Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select dynamic blocks with a certain distance value

12 REPLIES 12
Reply
Message 1 of 13
MikeKovacik4928
1272 Views, 12 Replies

Select dynamic blocks with a certain distance value

I would like to select all dynamic blocks with the same name and the same "distance" value

ie I have hundreds of dynamic blocks called "ledger" with various distance values ranging from 900 to 2500.

I want to select the ones with distance value 2500, so I can

1. see where they are

2. once I have seen where they are, change their value or else do some other operation on them all at once

 

Is this possible. It is not possible with Qselect, is there some other way? Lisp maybe?

 

Michael Kovacik

AutoCAD 2018

Joburg, South Africa

12 REPLIES 12
Message 2 of 13
devitg
in reply to: MikeKovacik4928

@MikeKovacik4928 

 

please state. 

 same "distance" value

from where , to where. 

 

If possible , upload a sample.dwg , please. 

Message 3 of 13
pendean
in reply to: MikeKovacik4928

Message 4 of 13
dmfrazier
in reply to: MikeKovacik4928

Message 5 of 13
MikeKovacik4928
in reply to: dmfrazier

Thanks

Nice routine for selecting all instances of a particular dynamic block.

like a Qselect for dynamic blocks.

Doesn't do what I need, however, selecting only instances with a certain distance value.

I ended up manually putting each different distance value on its own layer,

and then isolating each layer separately when I wanted to count. It took me a couple of hours.

Eattext works okay to do the counting of the different values contained in a large group, but I wanted to visually select all the instances of a certain value so I could work on them.

The eattext never seems to get to the excel file or the autocad table, always the error "deleteme" appearing in the excel cell and the autocad table not even appearing. However I screen shot the results and use the screen shot.

 

 

 

 

Message 6 of 13
dlanorh
in reply to: MikeKovacik4928

Try this. It creates a global variable *ss* that contains a selection set of entities that match the requirements. The selection set is also highlighted.

 

 

(defun rh:get_dbpv (b p / v)
  (vl-some '(lambda (x) (and (= (strcase (vlax-get x 'propertyname)) (strcase p)) (setq v (vlax-get x 'value)))) (vlax-invoke b 'getdynamicblockproperties))
  v
);end_defun

(vl-load-com)

(defun c:dbbp ( / *error* fuzz ss cnt obj bn lst)
  (defun *error* ( msg )
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  (setq fuzz 1.0e-7
        ss (ssget "_X" '((0 . "INSERT")))
  );end_setq

  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq cnt (1- cnt)))))
            (cond ( (= :vlax-true (vlax-get-property obj 'isdynamicblock))
                    (setq bn (vlax-get obj (if (vlax-property-available-p obj 'effectivename) 'effectivename 'name)))
                    (if (= (strcase bn) "LEDGER") (setq lst (cons obj lst)))
                  )
            );end_cond
          );end_repeat
          (setq *ss* (ssadd))
          (foreach blk lst
            (cond ( (equal (rh:get_dbpv blk "distance1") 2500 fuzz) (ssadd (vlax-vla-object->ename blk) *ss*) (redraw (vlax-vla-object->ename blk) 3)))
          );end_foreach
        )
        (t (alert "Nothing Found"))
  );end_cond

  (princ)
);end_defun

 

 

 

I am not one of the robots you're looking for

Message 7 of 13
MikeKovacik4928
in reply to: dlanorh

Thanks

What do I type in to run it

AQ 087 DynBlk-Select Distance_004.jpg

Mike

Message 8 of 13
dlanorh
in reply to: MikeKovacik4928

type dbbp on the command line and press enter.

I am not one of the robots you're looking for

Message 9 of 13
MikeKovacik4928
in reply to: dlanorh

doesn't seem to work

AQ 087 DynBlk-Select Distance_007.jpg

Message 10 of 13
dlanorh
in reply to: MikeKovacik4928

This loads and runs without any problems on my system (AutoCAD 2012).

 

I have attached the lisp. Ensure it is saved to a trusted path in your support file or add the path where it is saved to the "trustedpaths" sytem variable. If it loads properly you should see "Type dbbp to run" on the line above the command line. If you don't see this it isn't loading properly.

 

The lisp requires no input, it should just highlight the blocks on the screen. If run in a empty drawing an alert should appear saying "Nothing Found"

 

 

I am not one of the robots you're looking for

Message 11 of 13
dlanorh
in reply to: MikeKovacik4928

I have just noticed why the code was not running. It has been copied and pasted via a text editor (probably NotePad) . This has missed the lf/cr's out so all the code is on one line, and everything after the first in line comment is considered a comment and not code. 😎

I am not one of the robots you're looking for

Message 12 of 13
MikeKovacik4928
in reply to: dlanorh

It has been copied and pasted via a text editor (probably NotePad)

Yes that is exactly what I did.

I now took the .lsp you posted and tried that one instead.

Still nothing happened.

AQ 087 DynBlk-Select Distance_008.jpg

not sure what's going on or how the lisp is supposed to work.

Thanks for your help anyway.

 

Mike

Message 13 of 13
dlanorh
in reply to: MikeKovacik4928

The lisp should highlight every block in the drawing that meets the criteria you supplied, and makes a global variable *ss* which contains a selection set of all the block entities that meet the criteria.

I am not one of the robots you're looking for

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report