Deleting Selection Set Across Multiple Layouts

Deleting Selection Set Across Multiple Layouts

MrJSmith
Advocate Advocate
9,589 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,590 Views
45 Replies
Replies (45)
Message 2 of 46

cadffm
Consultant
Consultant
Try it again with entdel, it works.
Note: Entdel erase a item and using entdel for this item again, it will restore!
So run your function only ONE time and check the result.

Sebastian

0 Likes
Message 3 of 46

MrJSmith
Advocate
Advocate

It didn't work. Only deleted it on the layout I was on. I used the following steps.

 

1. Pasted "WE WANT TO GO" text on two different layouts.

2. Used (setq ss (ssget "_X" '((1 . "WE WANT TO GO")))) to add to selection set ss.

3. Used (deleteAll ss) with the following function:

(defun deleteAll (ss / elist ct) 
	(setq ct 0)
	(repeat (sslength ss)
		(setq elist (ssname ss ct))
		(entdel elist)
		(setq ct (1+ ct))
	)
)
0 Likes
Message 4 of 46

ronjonp
Advisor
Advisor
Accepted solution

This should work:

(vl-load-com)
(if (setq s (ssget "_x" '((1 . "test"))))
  (foreach x (mapcar 'cadr (ssnamex s))(vla-delete (vlax-ename->vla-object x)))
)
Message 5 of 46

MrJSmith
Advocate
Advocate

That worked perfectly. Thanks! Do you know why vla command works vs the autolisp/native AutoCAD?

0 Likes
Message 6 of 46

ronjonp
Advisor
Advisor

I'm not exactly sure why .. but discovered it many moons ago when I was trying to be clever with something like this:

(mapcar 'entdel (mapcar 'cadr (ssnamex s)))

 

0 Likes
Message 7 of 46

cadffm
Consultant
Consultant

Ouch, I apologize for my incorrect information.
vla-delete (for all layouts) is needed instead of entdel (last layout and model area)

Why only last layout and model? I couldn't find this point documented in official papers.
Then one can only assume and assume that this was an unfavorable decision or a mistake
designing Acad2000, which has not changed until today.

Previously (R12-R14) there was only model area and a paper area (layout). You could toggle between both with the
variable 'tilemode' and you know if Model tab is current or not. Tilemode toggle today (2000-) between model and
the last-layout(good!feature), entdel also affects only the two.
(a mistake today, if you ask me, but no one does that - and I'm sure Autodesk would declare it as a feature today)

I am sorry


Sebastian

0 Likes
Message 8 of 46

Anonymous
Not applicable

Would you please let me know what would be the code for exploding selection set (e. g. hatches) across multiple layouts, I tried adapting your code but it didn't work. Also, maybe changing colour and draworder, again across multiple layouts. Thank you.

0 Likes
Message 9 of 46

MrJSmith
Advocate
Advocate

VLA's command to explode is very limited in its functionality. You can't explode hatches, multi-line text, etc. You can see what it can explode here. Also, the hatch object can be seen here which does not have the method explode available.

 

The easiest way to do what you are suggesting is to go to the layout that has the selected objects and do your explode there before moving to the next layout tab. This will be pretty slow as switching layout tabs can take awhile (at least from my experience). The other option would be to write your own "explode" function that would make copy of the objects using their base parts and deleting the original.  

Message 10 of 46

Anonymous
Not applicable

Thank you for clarifying that for me. Your code works very nicely for erasing objects, I thought it could work for exploding as well.

0 Likes
Message 11 of 46

MrJSmith
Advocate
Advocate

Me and you both; I have run into the same problems before. Vla-explode is simply too limited. It becomes really annoying when trying to implement reactors which can not use commands. You are forced to find work arounds for exploding, which I was sadly unable to do for my Mtext to text through explode. After several failed attempts I gave up on my reactor. Smiley Sad

 

Glad the delete is working for you though! 

0 Likes
Message 12 of 46

Anonymous
Not applicable

Thank you. I am trying to explode hatches, dimensions, MText, polylines, then delete unexploded hatches and change colour of everything. I am going to loop through model space and all layouts as you suggested.  ACWTZWEGERS posted some code that loops through all layouts:

 

(defun c:test  ( / B_CTAB B_ITEM)
(setq B_CTAB ( getvar "CTAB" ))
(foreach B_ITEM ( layoutlist)
(setvar "CTAB" B_ITEM )
(.....)
)
(setvar "CTAB" B_CTAB)
(princ)
)

 

Would you know a way to include model space as well or I'll need to write separate code for model space? Would you have another suggestion?

0 Likes
Message 13 of 46

ronjonp
Advisor
Advisor

@Anonymous wrote:

....

Would you know a way to include model space as well or I'll need to write separate code for model space? Would you have another suggestion?


Try this quick mod .. why are you exploding everything?

(defun c:test (/ b_ctab b_item)
  (setq b_ctab (getvar "CTAB"))
  (foreach b_item (cons "Model" (layoutlist)) (setvar "CTAB" b_item) (. . . . .))
  (setvar "CTAB" b_ctab)
  (princ)
 

 

0 Likes
Message 14 of 46

Anonymous
Not applicable

Thanks a lot, that worked fine.

I need to explode everything in the old drawing so I can can create a faded "background" by changing the colour. 

0 Likes
Message 15 of 46

ronjonp
Advisor
Advisor

@Anonymous wrote:

Thanks a lot, that worked fine.

I need to explode everything in the old drawing so I can can create a faded "background" by changing the colour. 


Would something like this work?

(defun c:foo (/ a)
  (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 (vl-catch-all-apply 'vla-put-color (list c 8))))
  (princ)
)
0 Likes
Message 16 of 46

Anonymous
Not applicable

It works very well, except for ATTRIBUTES in attributed blocks and LEADERS as far as I've tested your code, they don't change colour, everything else does, and very fast.

Is there a way to insert "burst" command or something similar in your code so attributed blocks change colour as well??

Leaders I'm using have "dim line color" red, and that won't change, either.

This comes very close to what I'm looking for, thank you very much!

0 Likes
Message 17 of 46

ronjonp
Advisor
Advisor

See if this gets you closer:

(defun c:foo (/ _objecttocolor a)
  (defun _objecttocolor	(obj col)
    (cond ((vlax-write-enabled-p obj)
	   (foreach p '(color dimensionlinecolor extensionlinecolor textcolor)
	     (vl-catch-all-apply 'vlax-put (list obj p col))
	   )
	   (and	(= "AcDbBlockReference" (vlax-get obj 'objectname))
		(= -1 (vlax-get obj 'hasattributes))
		(foreach a (vlax-invoke obj 'getattributes) (_objecttocolor a col))
	   )
	  )
    )
  )
  (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 (_objecttocolor c 8)))
  (princ)
)
0 Likes
Message 18 of 46

Anonymous
Not applicable
Yes, it works fine, leaders & attributes are faded now. The only objects left are coloured background fills for dimension text and mtext, I hadn't tested those ones before. I tried a few things myself, either background fill removed or faded would work, but I'm not familiar enough with visual lisp. Also, is there a quick way to make a version of this program that works for a selection set only, not for the whole drawing? I have done something that works via exploding everything, but this one is way faster and cleaner. Thank you, I really appreciate your help.
0 Likes
Message 19 of 46

ronjonp
Advisor
Advisor

@Anonymous wrote:
Yes, it works fine, leaders & attributes are faded now. The only objects left are coloured background fills for dimension text and mtext, I hadn't tested those ones before. I tried a few things myself, either background fill removed or faded would work, but I'm not familiar enough with visual lisp. Also, is there a quick way to make a version of this program that works for a selection set only, not for the whole drawing? I have done something that works via exploding everything, but this one is way faster and cleaner. Thank you, I really appreciate your help.

 

I don't have time to make code for a selection set a the moment but give this version a try to turn off text masks.

 

(defun c:foo (/ _objecttocolor a)
  ;; RJP » 2019-04-17
  ;; (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))
       )
      )
    )
  )
  (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 (_objecttocolor c 8)))
  (princ)
)

 

Message 20 of 46

Anonymous
Not applicable

Works perfectly and extremely fast. Many thanks!

0 Likes