Awesome Super Layer turn on command with slight issue, need help

Awesome Super Layer turn on command with slight issue, need help

brock212001
Explorer Explorer
1,324 Views
13 Replies
Message 1 of 14

Awesome Super Layer turn on command with slight issue, need help

brock212001
Explorer
Explorer

I have the following command which temporarily turns on all layers in a drawing including xrefs, allows you to select one to keep on and then it turns the rest back off and even reports the name of the layer for you.  One slight problem.  It seems after selecting the item it remains highlighted after the command is run . . . Could someone shed a light on why the selected object remains highlighted.  Not even a regenall helps until the drawing is closed and reopened.

 

;-----------------------------------------------------------------------------
;**************************** Super Layer Command ff ***********************
;*****************************************************************************
;-----------------------------------------------------------------------------
(defun c:ff (/ ActDoc LayCol LayList Sel tempLayName OnLayList)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq LayCol (vla-get-Layers ActDoc))
(vlax-for Lay LayCol
(setq LayList (cons (list Lay (vla-get-Freeze Lay) (vla-get-LayerOn Lay))
LayList))
(if (not (equal (vla-get-ActiveLayer Actdoc) Lay))
(vla-put-Freeze Lay :vlax-false)
)
(vla-put-LayerOn Lay :vlax-true)
)

(setq acadobject (vlax-get-acad-object))
(setq activedocument (vla-get-activedocument acadobject))
(vla-regen activedocument acActiveViewport )

(setvar "errno" 0)
(while (not (equal (getvar "errno") 52))
(if (setq Sel (nentsel "\n Select object on layer to leave On
Layer will stay on & Thawed: "))

(progn
(redraw (car Sel) 3)
(setq tempLayName (cdr (assoc 8 (entget (car Sel)))))
(if (not (vl-position tempLayName OnLayList))
(setq OnLayList (cons tempLayName OnLayList))
)
;-------------------------
(prompt (strcat "\n Following layer will stay on. Gigidy Gigidy!: " (vl-princ-to-string
OnLayList)))
;-------------------------
(foreach item (last Sel)
(if
(and
(equal (type item) 'ENAME)
(setq tempLayName (cdr (assoc 8 (entget item))))
(not (vl-position tempLayName OnLayList))
)
(setq OnLayList (cons tempLayName OnLayList))
)
)
)
)
)
(foreach Lst LayList
(if (not (vl-position (vla-get-Name (car Lst)) OnLayList))
(progn
(if (not (equal (vla-get-ActiveLayer Actdoc) (car Lst)))
(vla-put-Freeze (car Lst) (cadr Lst))
)
(vla-put-LayerOn (car Lst) (caddr Lst))
)
)
)
(princ)
)

;-----------------------------------------------------------------------------
;**************************** Remove Dim override RS *************************
;*****************************************************************************
;-----------------------------------------------------------------------------
;must have dimstyle set current

(defun c:rs ()
(setvar "cmdecho" 0)
(command "Dim" "Restore" (getvar "DIMSTYLE") "Exit")
(PRINC "CURRENT DIMSTYLE OVERIDES REMOVED, PREVIOUS TEXT OVERIDES POSSIBLY REMOVED")
(setvar "cmdecho" 1)
(princ)
)

0 Likes
Accepted solutions (1)
1,325 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant
Add the REGEN before last (princ)

(command "_.REGEN")
Message 3 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

....  One slight problem.  It seems after selecting the item it remains highlighted after the command is run . . . Could someone shed a light on why the selected object remains highlighted.  Not even a regenall helps until the drawing is closed and reopened.

....


Welcome to these Forums!

 

I don't understand why Regenerating doesn't fix that, as we would all expect [and if it really doesn't, I don't think @ВeekeeCZ suggestion will help].  But in any case, this:

 

  (redraw (car Sel) 3)

 

is what's highlighting it.  At any point after the need for highlighting is past, you can un-highlight it:

 

  (redraw (car Sel) 4)

 

though if Regenerating doesn't, maybe that won't either, and there's some other problem.

Kent Cooper, AIA
Message 4 of 14

brock212001
Explorer
Explorer

Regen didn't seem to work.  Thanks for your help though!

0 Likes
Message 5 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... command which temporarily turns on all layers in a drawing including xrefs, allows you to select one to keep on and then it turns the rest back off ....


Clarify something for me:  Does that mean that it turns off all other Layers than those of the selected object(s), or that it turns back off only the rest of the Layers that it just turned on?  Are you left with only the Layer(s) of the selected object(s) visible, or also all other Layers that were visible when you started the command?

 

If it turns off [or freezes] only the other Layers that were off [or frozen] when it started, I have a routine that does that, if you want to try a different one that [for me] does not have that highlighting problem.  It's called LayerThawOnSelect.lsp, with its LTOS command, available here.  But it does only Layers of top-level objects, not nested ones.  It could probably be made to do nested ones, but it would lose what I think is a nice feature: all objects on the Layer(s) it brings up to temporary visibility are highlighted, so you can distinguish which Layers to select from, and for every object you pick, everything on that Layer immediately gets un-highlighted, to avoid unnecessarily picking more than one thing on the same Layer.

Kent Cooper, AIA
Message 6 of 14

brock212001
Explorer
Explorer

I use it for drawings with xrefs from third parties.  If there is a layer froze and I don't know what that layers name is it turns all layers on so I can select the one I want, reports the name of that layer so I know, then returns the layer state back to what it was with the layer you selected additionally on.  Now it's on and you never touched the layer manager and you know the name.  Hard to explain but it makes life wonderful.  The beauty is it works through blocks and xrefs and reports.  The "(redraw (car Sel) 4)" seemed to have worked . . . here is where I put it.  Thanks everyone for your help.  Hope this is useful to everyone:

 

;-----------------------------------------------------------------------------
;**************************** Super Layer Command ff ***********************
;*****************************************************************************
;-----------------------------------------------------------------------------
(defun c:ff (/ ActDoc LayCol LayList Sel tempLayName OnLayList)

(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq LayCol (vla-get-Layers ActDoc))
(vlax-for Lay LayCol
(setq LayList (cons (list Lay (vla-get-Freeze Lay) (vla-get-LayerOn Lay))
LayList))
(if (not (equal (vla-get-ActiveLayer Actdoc) Lay))
(vla-put-Freeze Lay :vlax-false)
)
(vla-put-LayerOn Lay :vlax-true)
)

(setq acadobject (vlax-get-acad-object))
(setq activedocument (vla-get-activedocument acadobject))
(vla-regen activedocument acActiveViewport )

(setvar "errno" 0)
(while (not (equal (getvar "errno") 52))
(if (setq Sel (nentsel "\n Select object on layer to leave On
Layer will stay on & Thawed: "))

(progn
(redraw (car Sel) 3)
(setq tempLayName (cdr (assoc 8 (entget (car Sel)))))
(if (not (vl-position tempLayName OnLayList))
(setq OnLayList (cons tempLayName OnLayList))
)
(redraw (car Sel) 4)
;-------------------------
(prompt (strcat "\n Following layer will stay on. Gigidy Gigidy!: " (vl-princ-to-string
OnLayList)))
;-------------------------
(foreach item (last Sel)
(if
(and
(equal (type item) 'ENAME)
(setq tempLayName (cdr (assoc 8 (entget item))))
(not (vl-position tempLayName OnLayList))
)
(setq OnLayList (cons tempLayName OnLayList))
)
)
)
)
)
(foreach Lst LayList
(if (not (vl-position (vla-get-Name (car Lst)) OnLayList))
(progn
(if (not (equal (vla-get-ActiveLayer Actdoc) (car Lst)))
(vla-put-Freeze (car Lst) (cadr Lst))
)
(vla-put-LayerOn (car Lst) (caddr Lst))
)
)
)
(princ)
)

0 Likes
Message 7 of 14

3dwannab
Advocate
Advocate

Hi Kent. Thanks for the program.

 

I've removed the line 

 

 

(sssetfirst nil (ssget "_X" (list (cons 8 lnames))))

To

	(if (not (wcmatch lnames (strcat "" lnames "")))
		(foreach highlight (mapcar 'cadr (ssnamex (ssget "_X" (list (cons 8 lnames)))))
			(redraw highlight 3)
			)
		)

 

This seems to work but when I zoom far out and in again the highlights sort of lost. But it works.

 

 

The latest program on your link still had grips even after picking to turn on/thaw so this is okay for me apart from the zooming redraw issue which is probably a ACAD issue.

 

Just curious what do I have to change in order for escape to return the initial state. Can't get that bit. LEARNING!! 😉

0 Likes
Message 8 of 14

Kent1Cooper
Consultant
Consultant

@3dwannab wrote:

 

	(if (not (wcmatch lnames (strcat "" lnames "")))
....

 

This seems to work but when I zoom far out and in again the highlights sort of lost. But it works.

....

Just curious what do I have to change in order for escape to return the initial state. Can't get that bit. LEARNING!! 😉


Does the highlighting under the original code not work for you?  In case a version difference might matter, I tried it in 2016 here, and it still does for me.  [Nor do I lose highlighting in Zooming in and out -- I have no idea what could be going on there.]  Does doing it in a different way have some advantage?  That could be a lot of stepping through to highlight every object on every Layer separately, compared to all at once with (sssetfirst).

 

Also, is something missing there [lost in the copy/paste process, or something]?  This:

 

(wcmatch lnames (strcat "" lnames ""))

 

can't help but always be True, since (strcat "" lnames "") is exactly the same as lnames.

 

The LAYERP command in the *error* handler should restore the initial state, but in newer versions, you should change this part:

 

    (command
       "_.layerp"
       "_.undo" "_end"
    ); command

 

to this [since AutoCAD doesn't like the (command) function within *error* in the last few versions]:

    (command-s "_.layerp")
    (command-s "_.undo" "_end")

Kent Cooper, AIA
Message 9 of 14

john.uhden
Mentor
Mentor

One would think that (redraw e 4) would work, but in 2002 (redraw e 3) doesn't work on a nested entity.  Of course (nentsel) is the same as (entsel) on a non-nested entity, so a (redraw e 3) would/should work on that.

And, yes, a regen should work regardless.

 

BTW, what's the correct adjective to use for "non-nested?"

John F. Uhden

0 Likes
Message 10 of 14

Kent1Cooper
Consultant
Consultant

@john.uhden wrote:

.... 

BTW, what's the correct adjective to use for "non-nested?"


I usually use "top-level."

Kent Cooper, AIA
0 Likes
Message 11 of 14

3dwannab
Advocate
Advocate

Yeah, I had this program a while but like many others I just rediscovered it. 

 

The code block appears right on my end. Using Chrome and I checked on firefox too and it's okay.

 

 

Here's the same: (It was my way of checking if lnames existed otherwise if not then it throws an error). Still learning and most likely a better way of doing so.

 

(if (not (wcmatch lnames (strcat "" lnames "")))
(foreach highlight (mapcar 'cadr (ssnamex (ssget "_X" (list (cons 8 lnames)))))
(redraw highlight 3)
)
)

 

I was also trying to make the code work if there's more than more layer to be thawed/unhidden. But I'm finding that difficult. I'm trying this to learn that's all.

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

@3dwannab wrote:

.... 

(if (not (wcmatch lnames (strcat "" lnames "")))
(foreach ....
....

 

I was also trying to make the code work if there's more than more layer to be thawed/unhidden. But I'm finding that difficult. I'm trying this to learn that's all.


You still have a (wcmatch) test there that will only and always return T, so since the (not) wrapper will only and always turn that into nil, it will never go on to the (foreach) part.

 

LTOS work with selection of things on more than one Layer.

Kent Cooper, AIA
0 Likes
Message 13 of 14

john.uhden
Mentor
Mentor

When dealing with an architect, "top-level" might very well mean penthouse.  😕

John F. Uhden

0 Likes
Message 14 of 14

3dwannab
Advocate
Advocate

I'll never get any work done learning LISPing. I've got it to work like I wanted. I suppose the codes very transparent but I'm learning.

 

Below is my EDIT. Thanks for the program to learn 'STUFF' Kent1Cooper.

 

;; ADDED - Alert if no layers to be thawed/unhidden
;; ADDED - Output to Command line of layer changed
;; CHG - (redraw highlight 3) as opposed to ssgetfirst method

 

;;  LayerThawOnSelect.lsp [command name: LTOS]
;;  To Thaw and turn On the Layer(s) of user-Selected object(s).
;;  Temporarily thaws and turns on ALL Layers, and highlights all objects on those
;;    that were frozen or off, for selection of object(s) on Layer(s) user wants to thaw
;;    and turn on.  Upon selection of each object, un-highlights all objects on that
;;    Layer to avoid selecting something on a Layer already selected.
;;  Kent Cooper, 1 April 2013 [no foolin'!]


;; 3dwannabe EDIT 2017.03.18 - For learning purposes
;; ADDED	- Alert if no layers to be thawed/unhidden
;; ADDED	- Output to Command line of layer changed
;; CHG		- (redraw highlight 3) as opposed to ssgetfirst method

; = Layer Thaw/On by Selection of object(s) on frozen/off Layer(s)
(defun C:LTOS (/ *error* cmde lnames ldata ent lname)

	(defun *error* (errmsg)

		(if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
			(princ (strcat "\nError: " errmsg))
			)

		(command-s
			"_.layerp"
			"_.undo" "_end"
			)

		(setvar 'cmdecho cmde)
		(princ)
		)

	(setq
		cmde (getvar 'cmdecho)
		lnames ""
		)

	(while (setq ldata (tblnext "layer" (not ldata)))
		(if
			(or
				(= (logand (cdr (assoc 70 ldata)) 1) 1)
				(minusp (cdr (assoc 62 ldata)))
				)

			(setq lnames (strcat lnames (cdr (assoc 2 ldata)) ","))

			)
		)

	(if (/= lnames "")

		(progn

			(setvar 'cmdecho 0)

			(command
				"_.undo" "_begin"
				"_.layer" "_thaw" "*" "_on" "*" "" "_.regen"
				)

			(foreach highlight (mapcar 'cadr (ssnamex (ssget "_X" (list (cons 8 lnames)))))
				(redraw highlight 3)
				)

			(setq lnames "")

			(while

				(setq ent
					(car
						(entsel "\nSelect object to thaw/turn on its Layer [Enter/space/pick nothing to end]: ")
						)
					)

				(setq lname (cdr (assoc 8 (entget ent))))

				(if (not (wcmatch lnames (strcat "*" lname "*")))

					(progn
						(setq lnames (strcat lnames lname ","))
						(foreach ent (mapcar 'cadr (ssnamex (ssget "_X" (list (cons 8 lname)))))
							(redraw ent 4)
							)

						(princ (strcat "\nLayer \"" lname "\" has been thawed/turned on."))

						)
					)
				)

			(command

				"_.layerp"
				"_.layer" "_thaw" lnames "_on" lnames ""
				"_.regen"
				"_.undo" "_end"
				)

			(setvar 'cmdecho cmde)
			(princ "\nThe 'LTOS' Program has ended successfully.")(princ)

			)

		)

	(if (= lnames "")
		(progn

			(setvar 'cmdecho 0)

			(alert "There's no Layers to be Thawed/Unhidden")

			(setvar 'cmdecho cmde)
			(princ)

			)
		)

	(princ)

	)
(prompt "\nType 'LTOS' for Layer Thaw/On by object Selection.")(princ)

 

0 Likes