Deleting Selection Set Across Multiple Layouts

Deleting Selection Set Across Multiple Layouts

MrJSmith
Advocate Advocate
9,615 Views
45 Replies
Message 1 of 46

Deleting Selection Set Across Multiple Layouts

MrJSmith
Advocate
Advocate

I have a selection set that contains entities across multiple layouts. I wish to delete them. I have tried the autocad command erase and autolisp's entdel, they only deleted the entities for the layout I was on.

 

The only solution I have come up with (besides cycling through all the layouts) is to set the selection set entities to a layer and force AutoCad to delete that layer.

 

My question is why does AutoCad behave in this way regarding deleting and layouts, and is there a better way than my current method? 

 

Thanks!

0 Likes
Accepted solutions (1)
9,616 Views
45 Replies
Replies (45)
Message 21 of 46

ronjonp
Advisor
Advisor

@Anonymous wrote:

Works perfectly and extremely fast. Many thanks!


Glad to help 🙂

0 Likes
Message 22 of 46

Anonymous
Not applicable

I would be really helpful for me if you had a chance to give me some pointers on how to approach adapting this program to work for a selection set instead the whole drawing. Thanks again, it's a great program, I've been using it a lot.

0 Likes
Message 23 of 46

ronjonp
Advisor
Advisor

Give this quick adaptation a try .. not heavily tested. 

(defun c:foo2 (/ _objecttocolor a s)
  ;; RJP » 2019-04-26
  ;; (vl-remove-if-not '(lambda (x) (wcmatch x "VLA-PUT*COLOR*")) (atoms-family 1))
  (defun _objecttocolor	(obj col)
    (cond
      ;; Can we modify the object?
      ((vlax-write-enabled-p obj)
       ;; Brute force color change 
       (foreach	p '(color		 dimensionlinecolor   extensionlinecolor
		    leaderlinecolor	 textcolor	      textfillcolor
		   )
	 (vl-catch-all-apply 'vlax-put (list obj p col))
       )
       (cond
	 ;; Change the color of attributes
	 ((= "AcDbBlockReference" (vlax-get obj 'objectname))
	  (= -1 (vlax-get obj 'hasattributes))
	  (foreach a (vlax-invoke obj 'getattributes) (_objecttocolor a col))
	 )
	 ;; Turn off text background fills
	 ((vlax-property-available-p obj 'backgroundfill) (vla-put-backgroundfill obj :vlax-false))
       )
      )
    )
  )
  (cond	((setq s (ssget ":L"))
	 (setq s (mapcar '(lambda (x) (cdr (assoc 5 (entget x))))
			 (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
		 )
	 )
	 (setq a (vla-get-activedocument (vlax-get-acad-object)))
	 (vlax-for b (vla-get-layers a) b (vla-put-lock b :vlax-false))
	 (vlax-for b (vla-get-blocks a)
	   (vlax-for c b (and (vl-position (vla-get-handle c) s) (_objecttocolor c 8)))
	 )
	)
  )
  (princ)
)
0 Likes
Message 24 of 46

Anonymous
Not applicable

You are very kind! Everything works fine, even attributes in attributed blocks, the only objects that don't seem to change are blocks, regular & attributed, in attributed blocks only attributes change. I tried adding blocks to the

 (foreach	p '(color	.......

list, it wouldn't work. 

0 Likes
Message 25 of 46

ronjonp
Advisor
Advisor

@Anonymous wrote:

You are very kind! Everything works fine, even attributes in attributed blocks, the only objects that don't seem to change are blocks, regular & attributed, in attributed blocks only attributes change. I tried adding blocks to the

 (foreach	p '(color	.......

list, it wouldn't work. 


Give this version a try:

(defun c:foo2 (/ _objecttocolor a i s)
  ;; RJP » 2019-04-29
  (defun _objecttocolor	(obj col / a)
    (setq a (vla-get-activedocument (vlax-get-acad-object)))
    (cond
      ;; Can we modify the object?
      ((vlax-write-enabled-p obj)
       ;; Brute force color change 
       (foreach	p '(color		 dimensionlinecolor   extensionlinecolor
		    leaderlinecolor	 textcolor	      textfillcolor
		   )
	 (vl-catch-all-apply 'vlax-put (list obj p col))
       )
       (cond
	 ;; Change the color of attributes
	 ((= "AcDbBlockReference" (vlax-get obj 'objectname))
	  (and (= -1 (vlax-get obj 'hasattributes))
	       (foreach a (vlax-invoke obj 'getattributes) (_objecttocolor a col))
	  )
	  ;; This might make a mess for you so test
	  (or (vl-catch-all-error-p (vl-catch-all-apply 'vla-converttoanonymousblock (list obj)))
	      (vlax-for a (vla-item (vla-get-blocks a) (vla-get-name obj)) (_objecttocolor a col))
	  )
	 )
	 ;; Turn off text background fills
	 ((vlax-property-available-p obj 'backgroundfill) (vla-put-backgroundfill obj :vlax-false))
       )
      )
    )
  )
  (cond	((and (setq i (acad_colordlg 8)) (setq s (ssget ":L")))
	 (setq a (vla-get-activedocument (vlax-get-acad-object)))
	 (vlax-for b (vla-get-layers a) b (vla-put-lock b :vlax-false))
	 (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   (_objecttocolor (vlax-ename->vla-object x) i)
	 )
	)
  )
  (princ)
)
Message 26 of 46

Anonymous
Not applicable

It's worked very well. I really appreciate it, these programs help me a lot.

0 Likes
Message 27 of 46

ronjonp
Advisor
Advisor

@Anonymous wrote:

It's worked very well. I really appreciate it, these programs help me a lot.


Glad to help 🙂

0 Likes
Message 28 of 46

Loc_Cao
Explorer
Explorer

could you please give me this lisp file Its shortcut command is something I can't do.

 Thank you

0 Likes
Message 29 of 46

margono_bersinar
Enthusiast
Enthusiast

can you explain how to use this code sir?  i copy code to command bar but nothing happens.

0 Likes
Message 30 of 46

cadffm
Consultant
Consultant

Hi,

 


@margono_bersinar  schrieb:

i copy code to command bar but nothing happens.


By this step, you define a Lispfunction, in this case: A lisp defined (new) command.

You can use this new command now, by type in: FOO2<enter>

 
 

 

 

Sebastian

0 Likes
Message 31 of 46

margono_bersinar
Enthusiast
Enthusiast

margono_bersinar_0-1727348906046.png

i am sorry sir,  but i still can't use. can you explain more sir?

0 Likes
Message 32 of 46

cadffm
Consultant
Consultant

ahh, this code.

This code WORKS by just pasteing in the commandline, no more steps required.

(this code will delete objects with a groupcode 1 with the value "test" -> for example: TEXT objects with the text value "test")

Do you still have Text-Objects with the whole text content is "test", after paste the code? Share your .dwg and we can check the problem.

 

Because of this, I guessed you used one of the code what are noch self-running - next time, if there are more code/tools, please quote what you are talking about, THX

 

 

 

Sebastian

0 Likes
Message 33 of 46

margono_bersinar
Enthusiast
Enthusiast

sorry i very new joint on this forum many years i just become silent reader. i don't know also how to quote post sir.

for my case already use command filter & select object on accross layout & want to delete all that one.

object is text & polilyne.

0 Likes
Message 34 of 46

margono_bersinar
Enthusiast
Enthusiast

margono_bersinar_0-1727350920036.png

i want to delete this stamp because some other staff not use block, because if i find & replace to "for construction"  polyline not fit.

0 Likes
Message 35 of 46

cadffm
Consultant
Consultant

Hi,

 

the red part is a MTEXT (and the content is not "test", the content is : \pxqc;FOR APPROVAL

cadffm_0-1727352734833.png

 

 

to delete Texts&Mtexts with this content, edit the code like this:
(if (setq s (ssget "_x" '((1 . "*FOR APPROVAL"))))
(foreach x (mapcar 'cadr (ssnamex s))(vla-delete (vlax-ename->vla-object x)))
)

 

If you want to delete the Polyline as well, checkout if the Layer for both are used for them ONLY.

If so (in the attached .dwg it is the case), delete objects by Layer:

(if (setq s (ssget "_x" '((8 . "REMARK STAMP"))))
(foreach x (mapcar 'cadr (ssnamex s))(vla-delete (vlax-ename->vla-object x)))
)

 

 

Sebastian

0 Likes
Message 36 of 46

margono_bersinar
Enthusiast
Enthusiast

Ohh, i see.

Thank you sir, i will try code tommorow.

0 Likes
Message 37 of 46

margono_bersinar
Enthusiast
Enthusiast

@cadffm wrote:

Hi,

 

the red part is a MTEXT (and the content is not "test", the content is : \pxqc;FOR APPROVAL

cadffm_0-1727352734833.png

 

 

to delete Texts&Mtexts with this content, edit the code like this:
(if (setq s (ssget "_x" '((1 . "*FOR APPROVAL"))))
(foreach x (mapcar 'cadr (ssnamex s))(vla-delete (vlax-ename->vla-object x)))
)

 

If you want to delete the Polyline as well, checkout if the Layer for both are used for them ONLY.

If so (in the attached .dwg it is the case), delete objects by Layer:

(if (setq s (ssget "_x" '((8 . "REMARK STAMP"))))
(foreach x (mapcar 'cadr (ssnamex s))(vla-delete (vlax-ename->vla-object x)))
)

 

 


 

the code work perfectly sir, thank you.

 

other think sir, when i try other object i see this number "8" represent type of object, if i want to select block, wipeout or etc. how i can get or check the list sir ?

(if (setq s (ssget "_x" '((8 . ""))))
(foreach x (mapcar 'cadr (ssnamex s))(vla-delete (vlax-ename->vla-object x)))
)

 

margono_bersinar_0-1727401180351.png

 

0 Likes
Message 38 of 46

cadffm
Consultant
Consultant

Hi Margono,

 

my opinion? Be careful, if you are not familiar with it, you can delete much more than expected.

 

 

DXF Reference [F1]

Common groups

 

And 

(entget(car(entsel)))

 

or more readable, change the second line of following code,

from (entlast) to (car(entsel))

 

after you load this code, usw the new command PrintDXF 

what means, print object dxf codes

 

 

https://help.autodesk.com/view/MAP/2025/ENU/?guid=GUID-EF8C5586-BA1F-4EA6-BAD1-6BA792B601F0

 

 

How to handle lisp, and much more (don't forget to honor LM in the future, donates welcome (

https://www.lee-mac.com/runlisp.html

 

 

 

 

 

 

Sebastian

0 Likes
Message 39 of 46

margono_bersinar
Enthusiast
Enthusiast
noted sir, if sometime i have time i will learn lisp from beginning. for now i will use lisp from this forum that already trusted. thank you
0 Likes
Message 40 of 46

cadffm
Consultant
Consultant

Learning some DXF codes is not the same, it's okay if you start now 🙂

DXF codes, and SSGET filters,

this makes (A)CAD life easier 😄

 

 

Code 8 does not present an object type,

you deletes

all (unnested) object!

in modelspacw!

and all layouts!

which refered a unlocked LAYER XXXXX

 

 

8 = Layer

0 = Objectype

 

combined

(ssget "_x" '((0 . "CIRLE")(8 . "MyLayer")))

All unnested* circles on unlocked layer MyLayer

 

Unnested: Not part of a block or xref.

Sebastian