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

Erase Nested Block

6 REPLIES 6
Reply
Message 1 of 7
CR-AdskSubscription
239 Views, 6 Replies

Erase Nested Block

Example: There is a block called BOX with another block called CIRCLE nested within it. I would like to erase block CIRCLE without exploding block BOX (if possible). I am aware that if I explode BOX first, then the following code will erase CIRCLE. However, it will not erase it if it is nested.

(if (tblsearch "BLOCK" "CIRCLE")
(progn
(setq ss (ssget "x" '((0 . "INSERT") (2 . "CIRCLE"))))
(command "ERASE" ss "")
)
(alert "Block not found.")
)

Thanks in advance.
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: CR-AdskSubscription

If you remove it, it will be removed from ALL insertions of that block.....

(if (tblsearch "block" "box")
(progn
(setq blk (vla-item (vla-get-blocks (vla-get-activedocument
(vlax-get-acad-object))) "BOX"))
(vlax-for obj blk
(if (and (vlax-property-available-p obj 'name)
(eq (strcase (vla-get-name obj)) "CIRCLE")
)
(vla-delete obj)
)
)
(vla-regen (vla-get-activedocument (vlax-get-acad-object))
acAllViewports)
)
)


"bbarkman" wrote in message news:5748587@discussion.autodesk.com...
Example: There is a block called BOX with another block called CIRCLE nested
within it. I would like to erase block CIRCLE without exploding block BOX
(if possible). I am aware that if I explode BOX first, then the following
code will erase CIRCLE. However, it will not erase it if it is nested.

(if (tblsearch "BLOCK" "CIRCLE")
(progn
(setq ss (ssget "x" '((0 . "INSERT") (2 . "CIRCLE"))))
(command "ERASE" ss "")
)
(alert "Block not found.")
)

Thanks in advance.
Message 3 of 7

Looks good, except there is an error: no function definition - vlax-get-acad-object. What else do I need to do?

Thanks.
Message 4 of 7
Anonymous
in reply to: CR-AdskSubscription

Add (vl-load-com) at the beginning of the code.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5748559@discussion.autodesk.com...
Looks good, except there is an error: no function definition -
vlax-get-acad-object. What else do I need to do?

Thanks.
Message 5 of 7
Anonymous
in reply to: CR-AdskSubscription

Unless you are doing this on 50 drawings, A couple of other options that require no code:
1. Redefine block circle to contain no elements. It disappears but you can rebuild it
later, especially if you wblock it out before redefining it.
2. Bedit the block box and erase the circle. Save the block definition.
3. Use the new cleanup program from Autodesk Labs.




wrote in message news:5748587@discussion.autodesk.com...
Example: There is a block called BOX with another block called CIRCLE nested within it. I
would like to erase block CIRCLE without exploding block BOX (if possible). I am aware
that if I explode BOX first, then the following code will erase CIRCLE. However, it will
not erase it if it is nested.

(if (tblsearch "BLOCK" "CIRCLE")
(progn
(setq ss (ssget "x" '((0 . "INSERT") (2 . "CIRCLE"))))
(command "ERASE" ss "")
)
(alert "Block not found.")
)

Thanks in advance.
Message 6 of 7

The code you provided works good. Now, is it possible to search only for the nested block? My nested block name never changes, but the block in which it is nested does.
Message 7 of 7
Anonymous
in reply to: CR-AdskSubscription

Sure. Use the following function like so:
(remove_blk "MyBlockNameToRemove")

[code]
(defun remove_blk (bname)
(vl-load-com)
(vlax-for blk (vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(if (= (vla-get-isXref blk) :vlax-false) ;skip xrefs
(vlax-for obj blk
(if (and (vlax-property-available-p obj 'name)
(wcmatch (vla-get-objectname obj) "*Block*")
(eq (strcase (vla-get-name obj)) bname)
)
(vla-delete obj)
)
)
)
)
(vla-regen (vla-get-activedocument (vlax-get-acad-object))
acAllViewports
)
)
[/code]

"bbarkman" wrote in message news:5761419@discussion.autodesk.com...
The code you provided works good. Now, is it possible to search only for
the nested block? My nested block name never changes, but the block in
which it is nested does.

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

Post to forums  

Autodesk Design & Make Report

”Boost