- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, all.
I was wondering if someone could help me finish this routine.
Basically, it needs to figure out if the user has something selected - this part works.
- If there's nothing selected, do something ("doThis") - this part works, too.
- If there's something selected, we need to do something else ("doThat"), but use the selected element's layer just for this one task, then get back to the previous layer.
The routine gives an error when it reaches the 6th line, where it should be setting the new variable newLayer to the object's layer name - I haven't been able to have it figure out what the selected object's layer name is.
One more thing, to make it more robust, if there's more than one object selected, is there a way to have the routine just ignore all of the elements but, say, the last one on the selection list?
I'd appreciate any help, even finding a new approach to the way this should work altogether.
Here's the code I have so far:
(defun C:Work () (if (not (setq mySS (ssget "_I"))) ; create sset if there's anything selected (doThis) ; action if there's nothing selected (progn ; action if selection exists (setq oldLayer (getvar "CLAYER")) ; saves current layer (setq newLayer (cdr (assoc 8 (entget mySS)))) ; get selection's layer (setvar "CLAYER" newLayer) ; make that layer current (doThat) ; work on this new layer (setvar "CLAYER" oldLayer) ; restores previous layer ) ) (setq mySS nil) ; empties selection (is this good practice, or do we not need to do it?) (princ) )
BTW, I found these posts, but still haven't been able to solve it...
- AutoDesk Comm: get Layer name and Colour from selected object
- CADTutor: Pick Entity to get it's Layer Name?
Again, thanks in advance.
Edgar
Solved! Go to Solution.