Jump to content

List the value of an attribute in a serie of same blocks


Recommended Posts

Posted (edited)

Think their was an error with my getstring. everything seems to be working. cut out only showing the duplicates now shows unique values + count to cut down on spam.

Example

LAOB-2.0.lsp

Edited by mhupp
Posted

Please excuse the delay, il lisp now works and I am able to try lisp on different blocks too.

Unfortunately, what I had hypothesized happens, which frustrates the execution.

1) I select a series of blocks, not all of those in the drawing, but a part, for example only those with DALI 10.

2) I run the lisp and choose the ID attribute (for example)

3) ...but the lisp lists all the ID values of all the blocks in the drawing whether they have the BUS attribute compiled with DALI 10 and whether they have the DALI attribute compiled can DALI 11 or other.

I need the chosen attribute listing to be limited to the blocks that have the BUS attribute compiled with DALI 10 (for example) because they are the ones I specifically selected before running the lisp, because I want to check the IDs of only that group of blocks...this is my pickfirst concept.

Unfortunately I don't need to know the total listing of the ID values of all the blocks, because I have to check them in logical groups, so I select them before executing the lisp.

Sorry lisp still has this problem, I thought I managed to explain myself in previous posts.

However the new selection method is much nicer

Posted (edited)

How this lisp works.

  • You select an attribute you want to search/change in an existing block.
  • from that it pulls the block name
  • Selects all the blocks in the drawing with that name.
  • Pulls the value of that attribute from each block.
  • Lists all the values and how many times it was seen.

Select Block Attribute:
"DALI 10" Found 37 Time(s)
"DALI 11" Found 36 Time(s)

Value to Search: DAL 10

  • Then asks for input to narrow the search (if you want to see all blocks with DAL 10 input that)
  • After the input it will display how many blocks it found. (should be the same when it was listed)

37 Blocks Found

  • Zoom to the the first block in the Selection and ask if you want to change the DALI 10 Value . (you can zoom in and out without exiting the command)

Change [DALI 10]:Test

  • If you type anything in "DALI 10" will change to that input of the block your looking at and a message will be displayed.

Attribute updated to "Test"

  • Zooms to next block in the selection set and ask for input (if you don't want to change the value hit enter or right click)

Change [DALI 10]:

  • Once you have cycled thought all the blocks it will zoom back out and ask you to select another attribute. starting the process over again.

 

 

I can change the lisp to instead create a selection set of something selected before the lisp is run instead of all blocks in the drawing by that name.

 

 

Edited by mhupp
Posted

You select an attribute you want to search/change in an existing block. OK

from that it pulls the block name OK

Selects all the blocks in the drawing with that name. OK

Pulls the value of that attribute from each block. OK

Lists all the values and how many times it was seen. OK

Select Block Attribute: OK
"DALI 10" Found 37 Time(s) OK
"DALI 11" Found 36 Time(s) OK

Value to Search: DAL 10 OK

Then asks for input to narrow the search (if you want to see all blocks with DAL 10 input that) OK

After the input it will display how many blocks it found. (should be the same when it was listed) OK

37 Blocks Found OK

Zoom to the the first block in the Selection and ask if you want to change the DALI 10 Value I don't want to change the value DALI 10, i want to control the id attrubute bvalue of this group of block, I need to list and check the value of the ID attributes of the blocks that have the BUS attribute compiled with DALI 10.

 

Your lisp is beautiful, but unfortunately it is applied to all the blocks of the drawing, I need it to be applied only to a group of blocks, for example those that have the BUS attribute compiled with DALI 10

 

Posted

Hello, I write you another example of use,...o you know the lisp CountAttributeValues by Lee Mac?

It has the option to run on the group of selected blocks before being executed (pickfirst).

If you use it on the example file and in the way you prefer, select all the blocks with the BUS attribute compiled with DALI 10 and then run the lisp, a table is created that lists all the values of all the attributes.

Even though the lisp doesn't indicate the attribute label, it allows me to check the values of interest of only the selected group of blocks.

your lisp is much more practical for my use, but it has the drawback that it doesn't apply exclusively to the group of blocks selected before executing it.

Hoping to have explained my problem to you better, goodbye

Posted

Ok new lisp. might want to name is something like laob-change.

 

Does the following.

  • asks user to select a group of blocks that have attributes
  • asks the user to select an attribute to filter down the selected blocks by
  • displays how many blocks are left and what filter was used

37 Blocks Left after filtering by TAG: BUS VALUE: DALI 10

  • It then zooms to each block left in the selection and ask for what attribute to change.
  • if you don't want to change any values just hit enter and it will go to the next block.

Select Block Attribute to Change:

  • if you do select a value it will display the old value and ask for a new one

Old Value: L9P
New Value: L10P
Attribute Updated to "L10P"

 

(defun C:LAOB (/ Drawing ss ent vc sz s obj tag att minpt maxpt)
  (vl-load-com)
  (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object))))
  (prompt "\nSelect Blocks: ")
  (setq ss (ssget '((0 . "INSERT") (66 . 1))))
  (setvar 'cmdecho 0)
  (while (setq ent (car (nentsel "\nSelect Block Attribute to Filter by: ")))
    (setq vc (getvar 'viewctr))
    (setq sz (getvar 'viewsize))
    (setq s (ssadd))
    (if (= (cdr (assoc 0 (entget ent))) "ATTRIB")
      (progn
        (setq obj (vlax-ename->vla-object ent))
        (setq tag (vla-get-tagstring obj))
        (setq att (vla-get-textstring obj))
        (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
          (foreach x (vlax-safearray->list (vlax-variant-value (vla-getattributes (vlax-ename->vla-object ent))))
            (if (and (= (vla-get-tagstring x) tag) (eq (vla-get-textstring x) att))
              (ssadd ent s)
            )
          )
        )
        (prompt (strcat "\n" (itoa (sslength s)) " Blocks Left after filting by tag: " tag " with value: " att))
        (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
          (vla-GetBoundingBox (setq obj (vlax-ename->vla-object ent)) 'minpt 'maxpt)
          (vla-ZoomWindow (vlax-get-acad-object) minpt maxpt)
          (command "_.Zoom" "_O")
          (while (setq att (car (nentsel "\nSelect Block Attribute to Change: ")))
            (progn
              (setq obj (vlax-ename->vla-object att)
                    tag (vla-get-tagstring obj)
                    blk (vlax-ename->vla-object ent)
              )
              (foreach x (vlax-safearray->list (vlax-variant-value (vla-getattributes blk)))
                (if (= (vla-get-tagstring x) tag)
                  (progn
                    (prompt (strcat "\nOld Value: " (vla-get-textstring x)))
                    (if (/= (setq att (getstring T "New Value: ")) "")
                      (progn
                        (vla-put-textstring x att)
                        (prompt (strcat "\nAttribute Updated from \"" tag "\" to \"" att "\""))
                      )
                    )
                  )
                )
              )
            )
          )
        )
        (vl-cmdf "_.Zoom" "C" VC SZ)
      )
    )
  )
  (setvar 'cmdecho 1)
  (vla-endundomark Drawing)
  (princ)
)

 

This example changed the block with the tag ID 66 back to 54 inside a circle

Posted

Hi Mhupp and sorry for my late reply.
I've tried lisp and while you've perfected it to a level that I think will serve many users, sadly it's no longer for me.
Since it doesn't seem possible to work only on a group of pre-selected objects, and explaining again my requirement which is to list the value of an attribute in a definied selection of same blocks, I ask you this: first selecting an attribute (e.g. DALI 10 i.e. "BUS") and then the second attribute (i.e. ID), is it possible to restore the values again as they were listed in the first version of lisp, in the status bar, in the combination they are matched with?

This is the list I generated using the first version of lisp, copying all the blocks with dali 10 and then all the blocks with dali 11 in an empty file so i could control the sequences separately which is my need.
DALI 10 "20"
DALI 10 "21"
DALI 10 "22"
DALI 10 "23"
DALI 10 "24"
DALI 10 "25"
DALI 10 "26"
DALI 10 "27"
DALI 10 "28"
DALI 10 "29"
DALI 10 "30"
DALI 10 "31"
DALI 10 "32"
DALI 10 "33"
DALI 10 "34"
DALI 10 "35"
DALI 10 "36"
DALI 10 "36"
DALI 10 "37"
DALI 10 "38"
DALI 10 "39"
DALI 10 "40"
DALI 10 "41"
DALI 10 "42"
DALI 10 "43"
DALI 10 "44"
DALI 10 "45"
DALI 10 "46"
DALI 10 "47"
DALI 10 "48"
DALI 10 "49"
DALI 10 "50"
DALI 10 "51"
DALI 10 "52"
DALI 10 "53"
DALI 10 "54"
DALI 10 "55"
DALI 11 "21"
DALI 11 "22"
DALI 11 "23"
DALI 11 "24"
DALI 11 "25"
DALI 11 "26"
DALI 11 "27"
DALI 11 "28"
DALI 11 "29"
DALI 11 "30"
DALI 11 "31"
DALI 11 "32"
DALI 11 "33"
DALI 11 "34"
DALI 11 "35"
DALI 11 "36"
DALI 11 "36"
DALI 11 "37"
DALI 11 "38"
DALI 11 "39"
DALI 11 "40"
DALI 11 "41"
DALI 11 "42"
DALI 11 "43"
DALI 11 "44"
DALI 11 "45"
DALI 11 "46"
DALI 11 "47"
DALI 11 "48"
DALI 11 "49"
DALI 11 "50"
DALI 11 "51"
DALI 11 "52"
DALI 11 "53"
DALI 11 "54"
DALI 11 "55"

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...