attempting to select objects that aren't in current space

attempting to select objects that aren't in current space

Anonymous
Not applicable
1,104 Views
8 Replies
Message 1 of 9

attempting to select objects that aren't in current space

Anonymous
Not applicable

So my code is to send xref layers to back (in an order).

(defun C:GEN-BU-DO-MEP (/ laylist sr)

(setq laylist '("XREF-IMG-FRT"  
		"XREF-VP"
		"XREF-MEP"
		"XREF-GRD")
)		
	
(foreach lay laylist
	(if (and (tblsearch "LAYER" lay)(setq sr (ssget "X" (list (cons 8 lay))))) 		;if sr returns true / if there is something on it
		(command "_draworder" sr "" "_B")						;problem here is it goes to select objects that are not in current space
	)
)
		
)


My issue is (i think) that the 'if' function finds something on one of the layers, but then when it goes on to draworder the selection, an error occurs because whatever it has found is not in the current space. 

How do I get around this?? Error handler??

0 Likes
Accepted solutions (2)
1,105 Views
8 Replies
Replies (8)
Message 2 of 9

john.uhden
Mentor
Mentor
Accepted solution

I don't know your overall intent, but your SR can return things in both spaces, but you may not be able to apply a command to them if they are in the opposite of your current space.  I would recommend your inspecting the 410 code of each entity's data to determine what layout it is in, then switch to the desired layout and apply your command to a reduced selection set.

John F. Uhden

0 Likes
Message 3 of 9

Anonymous
Not applicable

Oh, legend. I changed it to:

(foreach lay laylist
	(if (and (tblsearch "LAYER" lay)(setq sr (ssget "X" (list (cons 8 lay)(cons 410 (getvar "ctab")))))) 
	)
)

Thank you for your guidance!! 

 

0 Likes
Message 4 of 9

Anonymous
Not applicable

UPDATE:

Above line works for ModelSpace but PaperSpace presented some complications. So have a separate line for Paper:

(foreach lay laylist
	(if (and (tblsearch "LAYER" lay)(setq sr (ssget "X" (list (cons 8 lay)(cons 410 (if (eq 1 (getvar 'CVPORT))(getvar 'CTAB) "Model"))))))
		(command "_draworder" sr "" "_B")
	)
)

 

0 Likes
Message 5 of 9

john.uhden
Mentor
Mentor
Accepted solution

You may have to switch to each layout tab before invoking any command for objects in each tab...

(foreach layout laylist
  (setvar "ctab" layout)
  (setq ss (ssget "x" <filter>))
  (command "_.whatever" ss ...)
)

BTW, (layoutlist) will return a list of all layout names excepting "Model" so maybe you want to use:

(foreach layout (layoutlist) ...

John F. Uhden

0 Likes
Message 6 of 9

Anonymous
Not applicable

It's ok John, the code has actually been simplified from a larger code, where i already have it going through each tab. Thank you for the heads up though!

0 Likes
Message 7 of 9

john.uhden
Mentor
Mentor
It is so enjoyable to be helping someone who has already learned a lot but
is still eager to improve. Plus, many thanks to you for the thanks.
Someday maybe we can all be as learned as @Anonymous.

John F. Uhden

0 Likes
Message 8 of 9

Anonymous
Not applicable

I have learned a lot! Still feel like I'm a looooong way off - I'm just looking forward to the day when I can be as helpful as the pros like yourself! Not entirely sure who @Anonymous is though..?

0 Likes
Message 9 of 9

john.uhden
Mentor
Mentor
Well, you should.

John F. Uhden

0 Likes