TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: TJAM51 on March 17, 2006, 11:51:51 AM
-
Is there a lisp that will allow you to isolate multiple layers?
Thanks
-
There is one with express tools.
-
I am using 2002 LT with LT-Extender to run lisp. I do not have express tools.
-
Maybe something like
(defun c:LayIso (/ ss Ent Str LayName)
(setq Str "")
(if (setq ss (ssget))
(while (setq Ent (ssname ss 0))
(if (not (vl-string-search (setq LayName (cdr (assoc 8 (entget Ent)))) Str))
(if (= Str "")
(setq Str LayName)
(setq Str (strcase Str ", " LayName))
)
)
(ssdel Ent ss)
)
)
(if Str
(command "_.layer" "_set" LayName "_off" "*" "_no" "_on" Str "")
)
(princ)
)
-
The routine did not work....thanks for the effort.
-
What did it say?
-
Select objects:
; error: too many arguments
-
You can try this one
http://www.theswamp.org/index.php?topic=8832.msg113077#msg113077
-
Thanks guys...no luck here is the error reading
Pick layers to keep on. Enter when done
; error: no function definition: VLAX-GET-ACAD-OBJECT
-
Maybe the LTextender will only do Plain Lisp, I seem to remember that.
-
TJAM51,
You have got the Extender, and don't use the Express Tools V1-9 :lol:? Search in the www for a download...
L.
-
Yep, no ActiveX or (vl-anything)....
removed bogus code, next time I'll look more closely at what I'm doing.....
-
Still no work......possibly the LT Extender will not allow it to work...here is the error reading...
Command: LAYISO
Select objects on layer to Isolate:
Select objects: 1 found
Select objects: 1 found, 2 total
Select objects:
Invalid option keyword.
; error: Function cancelled
Enter an option
[?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:
-
Since I don't have LT or LT-Extender it's really hard to say. I know that it works here in Acad2002 & Acad2006.
Try turning off a layer maually at the command line and paste back everything that gets output.
To start the layer command without the Dialog, use :
Command: -layer
-
Actually, it will probably give that error if you try to turn off the current layer....
Oh, carp.....
I'm doing it backwards.....disregard my previous code.....
/me goes back to drawing board with a fressh cup of coffee......
-
Try this....if the current layer gets turned off then the first object's layer will become current.
(defun c:LayIso (/ ss idx ent lay lays)
(prompt "\nSelect objects on layer to Isolate: ")
(if (setq ss (ssget))
(progn
(setq echo (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq idx -1)
(while (setq ent (ssname ss (setq idx (1+ idx))))
(setq lay (cdr (assoc 8 (entget ent))))
(if (not (member lay lays))
(setq lays (cons lay lays))
)
)
(if lays
(progn
(command "undo" "be")
(command ".layer" "off" "*" "y" "")
(mapcar '(lambda (x)
(command ".layer" "on" x "")
)
lays)
(command ".layer" "s" (last lays) "")
(command "undo" "end")
)
)
(setvar "cmdecho" echo)
)
)
(princ)
)
-
It works...thanks bunches :-D
-
Not to happy with the code but here is one that will freeze all but selected layers
The selected layers are turned off temporally as you select them.
;; CAB 08.21.08 [ Limited Testing ] version 3
;; User pick of layers to remain Thawed, freeze all others
;; Picked layers turn off as picked, when Enter is pressed
;; picked layers are thawed & turned on and all others are frozen
;;
;; modified to allow current layer to be frozen, makes the first
;; thawed layer current
;;
;; If a layer in an xref is selected the layer the xref is on can
;; not be frozen
;;
;; Layer 0 in an xref will not be frozen
;;
;; added uiso to restore the previous layer states
;;
(defun c:liso (/ laylst thalst ent lname xrlays)
(vl-load-com)
;; get current layer settings
(defun getlayerdata (doc / lst)
(vlax-for layObj (vla-get-layers doc)
(setq lst (cons (list layObj
(vla-get-freeze layObj)
(vla-get-layeron layObj)
)
lst)))
lst
)
(defun xrefp (ent / elist blist)
(and
(setq elist (entget ent))
(setq blist (entget (tblobjname "BLOCK" (cdr (assoc 2 elist)))))
(= 4 (logand (cdr (assoc 70 blist)) 4))
)
)
(defun LayerOff (layname doc) ; added for version 3
(vla-put-LayerOn (vla-item (vla-get-layers doc) layname) :vlax-false)
)
(command ".undo" "begin")
(setq *laysts (getlayerdata (vla-get-activedocument (vlax-get-acad-object)))
*clayer (getvar "clayer")
)
(prompt "\nLayers picked will turn off during selection.")
(while (setq ent (nentsel "\nPick layers to keep thawed. Enter when done"))
(setq lname (cdr (assoc 8 (entget (car ent)))))
(if (vl-position lname xrlays)
(prompt "\nFlagged xref layer can not be frozen.")
(if (and (= lname "0") (cadddr ent) (xrefp (last (nth 3 ent))))
(prompt "\nLayer 0 in xref can not be frozen.")
(progn
(setq thalst (cons lname thalst))
(LayerOff lname (vla-get-activedocument (vlax-get-acad-object)))
(if (and (cadddr ent) (xrefp (car (nth 3 ent))))
(progn ; save the xref layer
(setq xrlays (cons (cdr (assoc 8 (entget (last (nth 3 ent))))) xrlays)
thalst (cons (car xrlays) thalst)
)
)
)
)
)
)
)
(if thalst
(progn
(setq laylst (list (cdr (assoc 2 (tblnext "layer" t))))
clayer (getvar "clayer")
)
(while (setq lay (cdr (assoc 2 (tblnext "layer"))))
(if (and lay
(not (member lay thalst))
(/= lay clayer)
)
(setq laylst (cons lay laylst))
)
)
(if (vl-position *clayer laylst)
(setvar "clayer" (car thalst))
)
(command "._Layer")
(mapcar '(lambda (x) (command "_f" x)) laylst)
(command "")
(command "._Layer")
(mapcar '(lambda (x) (command "_ON" x)) thalst)
(command "")
)
)
(command ".undo" "end")
(princ)
)
(prompt "\n*-* Layers Isolate loaded, Enter LayISO to run. *-*")
(princ)
;; restore previous layer settings
(defun c:uiso (/ doc)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
clayer (vla-get-activelayer doc)
)
(if *laysts
(progn
(vlax-for layObj (vla-get-layers doc)
(if (and (setq lyrdat (assoc layObj *laysts))
(not (equal clayer layObj))
)
(progn
(vla-put-freeze layObj (cadr lyrdat))
(vla-put-layeron layObj (caddr lyrdat))
(if (= *clayer (vla-get-name layObj))
(vla-put-activelayer doc layObj)
)
)
)
)
(setq lyrdat (assoc clayer *laysts))
(if (/= *clayer (vla-get-name (car lyrdat)))
(vla-put-freeze (car lyrdat) (cadr lyrdat))
)
(vla-put-layeron (car lyrdat) (caddr lyrdat))
(vla-regen doc acactiveviewport)
)
)
)
<edit: code updated>