PDA

View Full Version : Isolate Layer



timfrost
2004-10-06, 10:15 PM
Does anyone have a good isolate layer command. I know there is one in express tools but most of the time express tools quits working. My only recourse to quit ACAD and then reload all of my drawings.

If anyone has one to share it would me most appreciated. Mine does not work with xref drawings.

Thanks,

Tim

sinc
2004-10-08, 01:11 PM
Sounds like something's wrong. Have you tried repairing your installation or reinstalling?

CAB2k
2004-10-08, 04:02 PM
If anyone has one to share it would me most appreciated. Mine does not work with xref drawings.

Thanks,

Tim
When you say 'Mine' do you have a lisp other that express tools?
If so, post it and someone may revise it to work with xrefs.

timfrost
2004-10-08, 04:09 PM
(terpri)(prompt "Loading REMAIN ON please stand by...")(terpri)
(DEFUN C:RO ()

(LAYON) (EXIST)
; (COMMAND "LAYER" "OFF" elay "Y" "ON" layset "")
(COMMAND "LAYER" "OFF" elay "y" "")
(COMMAND "LAYER" "ON" layset "")
; (COMMAND "LAYER" "OFF" elay "Y" "ON" layset "")

(prin1)
)

(DEFUN LAYON ()

(prompt "Pick Layers to remain on ")
(setq pick (ssget))

(setq entnum 0)
(setq layset nil)
(setq newset (ssadd))
(setq enttot (sslength pick))

(while (< entnum enttot)
(if (= entnum 0)
(progn
(setq dl (cdr (assoc 8 (entget (ssname pick entnum)))))
(terpri)(prompt "Layers to remain on are: ")(prin1 dl)
(prompt ", ")
(setq layset dl)
)
(progn
(setq dl (cdr (assoc 8 (entget (ssname pick entnum)))))
(prin1 dl)(prompt ", ")
(setq layset (strcat layset "," dl))
)
)
(setq entnum (1+ entnum))
)

)

(DEFUN EXIST ()

(setq t 1 elay nil)
(while (setq a (tblnext "LAYER" t))
(if (= t 1)
(progn
(setq layer (cdr (assoc 2 a)))
(terpri) (prompt "Layers to turn off are: ")(prin1 layer)
(prompt ", ")
(setq elay layer)
(setq t nil)
)
(progn
(setq layer (cdr (assoc 2 a)))
(prin1 layer)(prompt ", ")
(setq elay (strcat elay "," layer))
)
)
)
)


CAB2k
2004-10-09, 04:55 PM
Try this, layers will be OFF not Frozen.

;; User pick of layers to remain ON
;; Picked layers turn off as picked, when Enter is pressed
;; picked layers are turned on and all others are turned off
(defun c:layon (/ laylst ent lname)
;;=====================================
;; Turn Layer On/Off -
;;=====================================
(defun layon (lst / doc lname)
(vl-load-com) ; load ActiveX support
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(vlax-for for-item (vla-get-layers doc) ;(vla-GetExtensionDictionary)
(setq lname (vlax-get-property for-item 'name))
(if (member lname lst)
(vlax-put-property
(vla-item (vla-get-layers doc) lname)
'layeron
:vlax-true
) ; layer ON
(vlax-put-property
(vla-item (vla-get-layers doc) lname)
'layeron
:vlax-false
) ; layer OFF
) ; endif
) ; vlax-for
) ; defun

;;===================
;; Start of Routine
;;===================
(command ".undo" "begin")
(prompt "\nLayers picked will turn off during selection.")
(setq laylst '())
(while (setq ent (nentsel "\nPick layers to keep on. Enter when done"))
(setq laylst (cons (setq lname (cdr (assoc 8 (entget (car ent))))) laylst))
(command "._Layer" "_Off" lname "")
) ; while
(layon laylst) ; Turn layers Off
(command ".undo" "end")
(princ)
) ;defun
(prompt "\n*-* Layers On loaded, Enter LayOn to run. *-*")
(princ)

timfrost
2004-10-11, 02:58 PM
Thank you for the post. I will give it a spin. I was starting to wonder, if I was the only one who needed something like this. Mine worked ok but not on xref.

Thanks,

Tim

timfrost
2004-10-12, 04:38 PM
The routine works great. Thank you for the help.

I have been reviewing the code. The section "Start of Routine" is clear.

However, I do not understand what is happening in the section labeled Turn Layer ON/Off Obviously, just from the name I know it turns the layers on and off. According to the help it is using Active X. However, I could not even find some of the code words. Is there anyway you can explain what is happening in this section of code.

If you do not have the time or the inclination I understand. However, it never hurts to ask.

In any event thank you for the routine it works fine.

CAB2k
2004-10-12, 05:34 PM
Tim,
I am just a beginner at vlisp but here are a few more comments.
Come visit us at the swamp and learn more about visual lisp.


;;=====================================
;; Turn Layer On/Off -
;;=====================================
;; lst is a list of layer names
(defun layon (lst / doc lname)
(vl-load-com) ; load ActiveX support
;; set vlax pointers
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
;; step through each layer
(vlax-for for-item (vla-get-layers doc) ;(vla-GetExtensionDictionary)
;; get the name of the layer
(setq lname (vlax-get-property for-item 'name))
;; if the name is in the 'Keep On' list
(if (member lname lst)
;; turn layer on
(vlax-put-property
(vla-item (vla-get-layers doc) lname)
'layeron :vlax-true) ; layer ON
;; ELSE turn layer off
(vlax-put-property
(vla-item (vla-get-layers doc) lname)
'layeron :vlax-false) ; layer OFF
) ; endif
) ; vlax-for
) ; defun

RobertB
2004-10-12, 09:55 PM
However, I do not understand what is happening in the section labeled Turn Layer ON/Off Obviously, just from the name I know it turns the layers on and off. According to the help it is using Active X. However, I could not even find some of the code words. Is there anyway you can explain what is happening in this section of code.
The ActiveX functions, the ones that start with vla-, are documented in the ActiveX/VBA Reference. The reference is written fully with VBA in mind, but with some "translation" it is easy to read the docs.

Please read my articles in the last two AUGIWorld issues on Attributes. It shows you how to go from plain AutoLISP to VBA and then to Visual LISP's ActiveX interface. That may help you understand how to translate the docs.

CAB2k
2004-10-12, 10:18 PM
Robert,
I'm sure Tim will find the articles useful, I did. I did a lot of underlining
and am rereading them. Are the articles available on-line?

RobertB
2004-10-13, 03:25 AM
I'm sure Tim will find the articles useful, I did. I did a lot of underlining
and am rereading them. Are the articles available on-line?
The issues are available online as PDFs under the Publications link. I'm glad you found the articles useful!

timfrost
2004-10-14, 04:57 PM
Thanks, to all. As you have gather I am an old Autolisp programmer. I have not done much for quite a few years but am getting back into it again. When I did a lot, there were no active x in autolisp. Thanks, for helping me along.

timfrost
2004-10-14, 05:11 PM
Nice job on the article. I especially like the comparison between the two languages. Thanks.

Tim

bhansen.114377
2006-09-16, 12:14 AM
It seems we have to many layers in our drawing because when I try this it gives me this

User input is too long.Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock
/stAte]: y
Invalid option keyword.
; error: Function cancelled
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock
/stAte]: *Cancel*

Anyone know how to fix this???

Opie
2006-09-16, 01:03 AM
It seems we have to many layers in our drawing because when I try this it gives me this

User input is too long.Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock
/stAte]: y
Invalid option keyword.
; error: Function cancelled
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck/Unlock
/stAte]: *Cancel*

Anyone know how to fix this???
I don't understand your question. How are you getting this error?

The y is not a valid character to input in that prompt.

CAB2k
2006-09-16, 02:29 AM
Try the other lisp routine.
Tim's routine has a few problems.