Hi!
I use layer defpoints to draw viewports and other objects that I don't want to see when plot.
Is there a lisp to delete all objects in this layer (paper and model space), except the viewports?
Thanks!
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
msarqui wrote:I use layer defpoints to draw viewports and other objects that I don't want to see when plot.
Is there a lisp to delete all objects in this layer (paper and model space), except the viewports?
Untested...
(defun c:demo (/ adoc) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for blks (vla-get-blocks adoc) (if (= (vla-get-isxref blks) :vlax-false) (vlax-for blk blks (if (and (= (strcase (vla-get-layer blk)) "DEFPOINTS") (/= (vla-get-objectname blk) "AcDbViewport") ) (vla-delete blk) ) ) ) ) (vla-regen adoc acallviewports) (princ) )
HTH
Henrique
Side note: Have you considered creating your own no-plot layer?
Objects on layer Defpoints are visible but not select-able when layer 0 is frozen, and maybe other oddities.
@msarqui wrote:
....
I use layer defpoints to draw viewports and other objects that I don't want to see when plot.
Is there a lisp to delete all objects in this layer (paper and model space), except the viewports?
....
I agree that it's really better to make a non-plotting Layer for the purpose, rather than use a Layer intended for Dimensioning definition points merely because it happens to not plot. But given that you already have things set up that way, you can find everything on that Layer that's not a Viewport:
(ssget "_X" '((8 . "Defpoints") (0 . "~VIEWPORT")))
You could then use (command "_.erase" ... if they're all in the current space, but that doesn't seem likely, so instead you should step through the set and use (entdel) on each item. Write back if you don't know how to do that.
I use layer defpoints to draw viewports and other objects that I don't want to see when plot.
Is there a lisp to delete all objects in this layer (paper and model space), except the viewports?
Untested...
(defun c:demo (/ adoc) (vl-load-com) (setq adoc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for blks (vla-get-blocks adoc) (if (= (vla-get-isxref blks) :vlax-false) (vlax-for blk blks (if (and (= (strcase (vla-get-layer blk)) "DEFPOINTS") (/= (vla-get-objectname blk) "AcDbViewport") ) (vla-delete blk) ) ) ) ) (vla-regen adoc acallviewports) (princ) )
Good code Henrique -
That is how I would also be inclined to write it, as the Visual LISP method of iterating over every block definition component automatically takes care of objects in all drawing layouts & also within block definitions (hence accounting for nested blocks too). Iterating over the database is also likely to be faster than the Vanilla AutoLISP alternative if large quantities of objects are involved, as, with Vanilla AutoLISP you are effectively iterating over the same objects twice: once over the drawing database to retrieve a selection set with the call to ssget, and again to iterate over this selection set in order to delete the objects.
My only suggestion would be to test whether the object is write-enabled (vlax-write-enabled-p) before attempting to delete it, or as a 'sledge-hammer' approach, wrap the vla-delete call inside a vl-catch-all-apply expression to account for either if the DEFPOINTS layer is locked, or if the object is referenced in some way and cannot be deleted - but this is nit-picking for this scenario.
Lee
Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.
Lee_Mac wrote:Good code Henrique -
Thank you Lee! 🙂
Lee_Mac wrote:My only suggestion would be to test whether the object is write-enabled (vlax-write-enabled-p) before attempting to delete it, or as a 'sledge-hammer' approach, wrap the vla-delete call inside a vl-catch-all-apply expression to account for either if the DEFPOINTS layer is locked, or if the object is referenced in some way and cannot be deleted - but this is nit-picking for this scenario.
As usual, great suggestions!
Cheers
Henrique
Henrique,
Probably not that important but I would also skip point entities from deletion. Otherwise, all the dimension blocks will be without their point entities. Also, points on defpoints are an important feature of some verticals. I also use them in my own block design.
@Anonymous wrote:
Henrique,
Probably not that important but I would also skip point entities from deletion. Otherwise, all the dimension blocks will be without their point entities. Also, points on defpoints are an important feature of some verticals. I also use them in my own block design.
Hi Doug,
thanks for your comment, I also use the defpoints to my block points, and to temporarily put some objects that I need that they remain visible but not select-able, but as the OP as stated, "a lisp to delete all objects in this layer (paper and model space), except the viewports"...
Cheers
Henrique
This is a prime example of where we who are in the know, should either ignore such requests or to try to solve them in the least destructive way possible. It's akin to a parent who doesn't let their children play with daddy's Uzi just cause they ask nicely.
@Anonymous wrote:
This is a prime example of where we who are in the know, should either ignore such requests or to try to solve them in the least destructive way possible. It's akin to a parent who doesn't let their children play with daddy's Uzi just cause they ask nicely.
Agree...
Henrique
Hello everyone!
Thanks for all answers and suggestions.
We have used defpoints to viewports and other objects that we don't want to see in the plotting for more then 12 years, even before Autocad give to us the possibility to make a non-plot layer. So, this is a hard thing to change in the office standards.
That said, thanks to Henrique. Your code do exactly what I want and is pretty fast, even in the large drawings. I will test it in more drawings and I will let you know about future issues.
Cheers
Marcelo Silva
@Anonymous wrote:
... I would also skip point entities from deletion. Otherwise, all the dimension blocks will be without their point entities. Also, points on defpoints are an important feature of some verticals. I also use them in my own block design.
If the OP's situation doesn't involve such verticals, and if they do want to remove any independent Point entities there may be on that Layer, then my earlier suggestion works fine -- it does not "see" the definition points in Dimension entities, so they won't be removed. If you skip them entirely for the purpose of retaining them in Dimensions, things the OP wants removed may not be. If they want even nested objects on that Layer, other than Dimension definition points, removed, then mine won't get them, but I imagine the through-the-blocks approach could be made to distinguish nested Points within Dimensions from any other Points, and get rid of only the latter.
Good point Kent. Your method would not affect any of the AutoCAD internal use of defpoints as in below. But browsing blocks via ActiveX must be done very carefully since it is a layer automatically created by Autodesk and should be managed by Autodesk.
(defun c:cleandp()(command "_.erase" (ssget "x" '((8 . "defpoints") (0 . "~viewport")))"")(princ))
@Anonymous wrote:
Good point Kent. Your method would not affect any of the AutoCAD internal use of defpoints as in below. But browsing blocks via ActiveX must be done very carefully since it is a layer automatically created by Autodesk and should be managed by Autodesk.
(defun c:cleandp()(command "_.erase" (ssget "x" '((8 . "defpoints") (0 . "~viewport")))"")(princ))
To erase all objects in defpoints in all layouts, we'll have to step through all layouts and run the erase command in each layout...
Henrique
@hmsilva wrote:
@Anonymous wrote:
....
(defun c:cleandp()(command "_.erase" (ssget "x" '((8 . "defpoints") (0 . "~viewport")))"")(princ))
To erase all objects in defpoints in all layouts, we'll have to step through all layouts and run the erase command in each layout...
....
Or use (entdel) -- see the end of Message 4.
Thanks. Not concentrating today. This is a way to use activeX without going into block definitions other than layouts.
(defun c:cleandp () (ssget "x" '((8 . "defpoints") (0 . "~viewport"))) (vlax-for n (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object) ) ) (vla-delete n) ) (princ) )
@Kent1Cooper wrote:
Or use (entdel) -- see the end of Message 4.
You're correct, I didn't read the full post...
@Anonymous wrote:
Thanks. Not concentrating today. This is a way to use activeX without going into block definitions other than layouts.
(defun c:cleandp () (ssget "x" '((8 . "defpoints") (0 . "~viewport"))) (vlax-for n (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object) ) ) (vla-delete n) ) (princ) )
Nice approach!
Henrique
Can't find what you're looking for? Ask the community or share your knowledge.