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

Delete all objects in a layer but viewports

18 REPLIES 18
SOLVED
Reply
Message 1 of 19
msarqui
1480 Views, 18 Replies

Delete all objects in a layer but viewports

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!

18 REPLIES 18
Message 2 of 19
hmsilva
in reply to: msarqui


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

EESignature

Message 3 of 19
rkmcswain
in reply to: msarqui

msarqui wrote:
I use layer defpoints to draw viewports and other objects that I don't want to see when plot.

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.

R.K. McSwain     | CADpanacea | on twitter
Message 4 of 19
Kent1Cooper
in reply to: msarqui


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

Kent Cooper, AIA
Message 5 of 19
Lee_Mac
in reply to: hmsilva

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

 

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

Message 6 of 19
scot-65
in reply to: rkmcswain

... or assign a color that has grayscale of 0%.
You can either create a layer with this color as bylayer or simply CHPROP the object in it's current layer to this no-plot color (if using CTB pen tables).
???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 7 of 19
hmsilva
in reply to: Lee_Mac


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

EESignature

Message 8 of 19
dbroad
in reply to: hmsilva

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.

Architect, Registered NC, VA, SC, & GA.
Message 9 of 19
hmsilva
in reply to: dbroad


@dbroad3 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

 

 

EESignature

Message 10 of 19
dbroad
in reply to: hmsilva

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.

Architect, Registered NC, VA, SC, & GA.
Message 11 of 19
hmsilva
in reply to: dbroad


@dbroad3 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

EESignature

Message 12 of 19
msarqui
in reply to: msarqui

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

Message 13 of 19
Kent1Cooper
in reply to: dbroad


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

Kent Cooper, AIA
Message 14 of 19
hmsilva
in reply to: msarqui


@msarqui wrote:
..., 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.

You're welcome, Marcelo!

Glad I could help

 

Henrique

EESignature

Message 15 of 19
dbroad
in reply to: Kent1Cooper

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

Architect, Registered NC, VA, SC, & GA.
Message 16 of 19
hmsilva
in reply to: dbroad


@dbroad3 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

EESignature

Message 17 of 19
Kent1Cooper
in reply to: hmsilva


@hmsilva wrote:

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

Kent Cooper, AIA
Message 18 of 19
dbroad
in reply to: Kent1Cooper

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

 

Architect, Registered NC, VA, SC, & GA.
Message 19 of 19
hmsilva
in reply to: Kent1Cooper


@Kent1Cooper wrote:

Or use (entdel) -- see the end of Message 4.



You're correct, I didn't read the full post...

 


@dbroad3 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

EESignature

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

Post to forums  

Autodesk Design & Make Report

”Boost