Jump to content
ecustis

Select blocks by name without selecting any groups associated with them

Recommended Posts

ecustis

Hello all,

 

I need to select two blocks and delete them automatically, their names are: FA_DEVICE_INIT_BASE_STANDARD and FA_DEVICE_INIT_SMOKE_DUCT_HOUSING

 

I usually use the quick select tool to delete these because they're always grouped with the actual device block. For example, we would have a smoke detector block and then it would have a "base" block underneath of it grouped with it so when we did exports they would be on the counts. When using quick select, if I say select block by name "FA_DEVICE_INIT_BASE_STANDARD" it actually only selects that block and not the "FA_DEVICE_INIT_SMOKE" block that is grouped with it. Is there any way to replicate what quick select does with autolisp? Here is what I have so far, it currently selects the blocks but it also selects any associated groups and deletes them too:

 

(defun c:AutoBlkRepPrepare ()
(if (setq ss1 (ssget "_x" '((0 . "INSERT")(2 . "FA_DEVICE_INIT_BASE_STANDARD,FA_DEVICE_INIT_SMOKE_DUCT_HOUSING"))))
(progn
(command "_.erase" ss1)
)
(alert "No preparation necessary!")
)
(princ)
)

 

Any help with this is greatly appreciated! Thanks!

Share this post


Link to post
Share on other sites
BIGAL

You will need to check somehow if its a group, something I dont use very often. An idea may be get all the groups check for your blocks in group make a list of all objects, ungroup delete blocks then regroup remainder. Then run what you have to get rid of individuals. Really need a sample dwg.

 

Some one other than me may have some GROUP code that would be usefull.

Share this post


Link to post
Share on other sites
Roy_043

You can temporarily change the PICKSTYLE.

Share this post


Link to post
Share on other sites
BIGAL

Cool Roy_043 tried it out.

Share this post


Link to post
Share on other sites
ecustis
You can temporarily change the PICKSTYLE.

 

Thanks Roy, I added a pickstyle change to the code and it works now.

 

The only thing that happens is it says "; error: Function cancelled". It doesn't affect the process and all and everything still works, but it is just annoying that it won't print the text I want it to. Here is the updated code:

(defun c:AutoBlkRepPrepare ()
(command "pickstyle" "0")
(if (setq ss1 (ssget "_x" '((0 . "INSERT")(2 . "FA_DEVICE_INIT_BASE_STANDARD,FA_DEVICE_INIT_SMOKE_DUCT_HOUSING"))))
(progn
(command "_.erase" ss1)
)
(alert "No preparation necessary!")
)
(command "pickstyle" "1")
(princ "Preparation complete!")
(princ)
)

 

Anyone have any suggestions on how to get rid of that error? Thanks!

Share this post


Link to post
Share on other sites
ronjonp

Try this .. removed command calls.

(defun c:foo (/ ps s)			;<- Localize variables
 (setq ps (getvar 'pickstyle))
 (setvar 'pickstyle 0)
 (if (setq s (ssget "_x" '((0 . "INSERT"))))
   (mapcar 'entdel (mapcar 'cadr (ssnamex s)))
   (alert "No preparation necessary!")
 )
 (setvar 'pickstyle ps)
 (princ)
)

Edited by ronjonp

Share this post


Link to post
Share on other sites
ecustis
Try this .. removed command calls.

(defun c:autoblkrepprepare (/ ps s)    ;<- Localize variables
 (setq ps (getvar 'pickstyle))
 (setvar 'pickstyle 0)
 (if (setq
   s (ssget
       "_x"
       '((0 . "INSERT") (2 . "FA_DEVICE_INIT_BASE_STANDARD,FA_DEVICE_INIT_SMOKE_DUCT_HOUSING"))
     )
     )
   (mapcar 'entdel (mapcar 'cadr (ssnamex s)))
   (alert "No preparation necessary!")
 )
 (setvar 'pickstyle ps)
 (princ)
)

 

Ron, this is awesome, works like a charm! Now to look up and learn what all you did so I can make my code not so basic. Thank you very much!

Share this post


Link to post
Share on other sites
ronjonp
Ron, this is awesome, works like a charm! Now to look up and learn what all you did so I can make my code not so basic. Thank you very much!

 

Glad to help :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×