Jump to content

Select blocks by name without selecting any groups associated with them


ecustis

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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...