PDA

View Full Version : Layer fade not working in a "LockAll" command



JaCAD
2011-07-08, 07:56 PM
Hey all,

I'm working on a simple function to lock, unlock, thaw, etc, all layers in the drawing.
I've got it working, but I have a question about the fade setting.
Normally, when you use the "LockLayer" command, or lock a layer through the layer dialog, the layer fades, and I like this effect. However, when I run the following command, the layers get locked, but don't fade. Does anyone know how to fix this so the layers still fade when I run this command?

Thanks!



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:LockAll ( / )

(DoToAllLayers 'Lock :vlax-true)
(princ)
);end defun

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun DoToAllLayers (Prop Val / Layers Lim Cnt LyrObj)

(setq Layers (vla-get-layers #AcDoc#)
Lim (vla-get-count Layers)
Cnt -1
)

(while (< (setq Cnt (1+ Cnt)) Lim)
(setq LyrObj (vla-item Layers Cnt))

(vlax-put-property LyrObj Prop Val)
);end while

);end defun

BlackBox
2011-07-08, 08:54 PM
Presuming you have the correct lock fade setting, you need to regenerate the viewports.

Separately, why not simply use:



(defun c:LOCKALL ()
(command "._-layer" "lock" "*" "")
(princ))

BlackBox
2011-07-08, 08:58 PM
Also, consider this example:



(defun DoToAllLayers (Doc Prop Val / )
(vlax-for lay (vla-get-layers Doc)
(if (vlax-property-available-p lay Prop)
(vl-catch-all-apply 'vlax-put (list lay Prop Val)))))


Instead of passing Visual LISP arguments to your sub-function, then extracting the layer count from the layers collection, simply iterate through the collection and make all applicable changes.

I've included the Document Object as an argument, as in this case with SDI = 0, you can send this sub-function the Document Object for any open document in the Document's Collection and yield the desired result. This could also be utilized within an ObjectDBX routine as well.

Just a thought.

Tharwat
2011-07-08, 09:14 PM
All within one shut . :)



(setq lays (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
(vlax-for x lays
(if (eq (vla-get-lock (setq l (vla-item lays (vla-get-name x))))
:vlax-false
)
(vla-put-lock l :vlax-true)
)
)

Tharwat

Lee Mac
2011-07-09, 12:21 AM
@ Tharwat,

The highlighted section is unnecessary, since you already have the Layer Object bound to symbol 'x':





(setq lays (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
(vlax-for x lays
(if (eq (vla-get-lock (setq l (vla-item lays (vla-get-name x))))
:vlax-false
)
(vla-put-lock l :vlax-true)
)
)


It could be better written as:


(setq lays (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
(vlax-for x lays
(if (eq (vla-get-lock x) :vlax-false)
(vla-put-lock l :vlax-true)
)
)

However, I would be inclined to follow the route suggested by Renderman, but note that a Regen may be required to show the fade:



(defun c:test ( / _ApplyCollectionProperty acdoc )

(defun _ApplyCollectionProperty ( collection property value )
(vlax-for item collection
(vl-catch-all-apply 'vlax-put-property (list item property value))
)
)

(setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
(_ApplyCollectionProperty (vla-get-layers acdoc) 'lock :vlax-true)
(vla-regen acdoc acallviewports)
(princ)
)

BlackBox
2011-07-09, 04:17 AM
Nice one, Lee! :wink:

*IF* the OP is going to make this into a production tool (not a learning exercise), I'd suggest that vla-startUndoMark, and vla-endUndoMark be added for completeness.

Cheers! :beer:

Tharwat
2011-07-09, 04:25 AM
@ Tharwat,

The highlighted section is unnecessary, since you already have the Layer Object bound to symbol 'x':

It could be better written as:


(setq lays (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
(vlax-for x lays
(if (eq (vla-get-lock x) :vlax-false)
(vla-put-lock l :vlax-true)
)
)

I tried that before but it did not work at all on Cad 2010 it's been giving me a message that the vla-object is nil ,
but it worked well on Cad 2009 in the office,


I wonder how !!

Thank you .

marko_ribar
2011-07-09, 01:41 PM
It's because of this "typo" mistake :



(setq lays (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
)
(vlax-for x lays
(if (eq (vla-get-lock x) :vlax-false)
(vla-put-lock x :vlax-true)
)
)


M.R.

Lee Mac
2011-07-09, 03:38 PM
Good catch Marko, I modified things a little too hastily, but hopefully Tharwat gets the idea ;)

Tharwat
2011-07-09, 04:30 PM
but hopefully Tharwat gets the idea ;)

Certainly I did. 8)

irneb
2011-07-09, 08:43 PM
Just to understand correctly: Why check before you set the lock? It won't make a difference if you set it to what it was?

Why not simply:
(defun c:LockAll (/)
(vlax-for lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-put-Lock lay :vlax-true)
)
(princ)
)It's when you need something like FreezeAll where you need to check for the current layer. But still you don't need to check if it's already frozen do you?

In such case you can either check for the vla-get-Name against (getvar "CLAYER") or simply wrap the vla-put-Freeze inside a vlax-catch-all-apply. Much like RenderMan did in post #3.

Though that one is also a bit overly cautious :shock:, @RenderMan: You already have the vlax-catch-all-apply, which should allow for you removing the vlax-property-available-p, shouldn't it? :wink: Otherwise only check availability once (before the vlax-for loop) - should be a lot more efficient.

BTW, the "nice" thing about JaCAD and RenderMan's DoAllLayers is: It can also be used directly on ObjectDBX documents (i.e. DWG files you don't have open in ACad).

irneb
2011-07-09, 09:50 PM
Although ... we still haven't answered the OP's question: "Why doesn't the fade work when locking the layers?" I've even tried a forced regenall, but still doesn't work. Only thing which works seems to be changing the CTab, but that's a bit excessive isn't it?

I'm thinking it's something to do with the current view needing an update, but refresh does nothing and trying to update the ActivePViewport (when in paperspace) causes an error of "It's on a locked layer"!

BTW, here's the code I've used:
(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)

(defun DoAllLayers (Doc Prop Val / )
(DoAllCollection (vla-get-Layers Doc) Prop Val)
)

(defun c:LockAll (/)
(DoAllLayers *vla-ActiveDocument* 'Lock :vlax-true)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:UnLockAll (/)
(DoAllLayers *vla-ActiveDocument* 'Lock :vlax-false)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)And then "strangely" on my Vanilla 2011, the UnLockAll has no effect whatsoever. I've debugged and stepped through into the vl-catch-all-apply - but that doesn't return an error. Yet all the layers are still locked. I'm thinking it's something to do with Layer 0/Defpoints ... those 2 cause issues whenever they're Off/Frozen/Locked.

marko_ribar
2011-07-10, 06:49 AM
Based on your code, irneb, I've found what works...

try it :



(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)

(defun DoAllLayers (Doc Prop Val / )
(DoAllCollection (vla-get-Layers Doc) Prop Val)
)

(defun c:LockAll (/)
(DoAllLayers *vla-ActiveDocument* 'Lock 1)
(setvar 'laylockfadectl 50)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:UnLockAll (/)
(DoAllLayers *vla-ActiveDocument* 'Lock 0)
(setvar 'laylockfadectl 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)


M.R.
You suspected on Layers 0 and Defpoints, but they weren't problem... It's strange behavior of (vla- functions) when doing chains like : (vl-catch-all-apply 'vlax-put (list item Prop Val))...Strange, but true (vlax-true = 1; vlax-false = 0) in such chain situations... (to see fading effect, just before vla-regen function, variable 'laylockfadectl must be set - for unlockall at 0 - for lockall at 50)

marko_ribar
2011-07-10, 08:33 AM
However, if there are no chaining of vla- functions through
(vl-catch-all-apply 'vla-put (list item Prop Val), but using straight vla-put-Lock,
:vlax-true and :vlax-false arguments works fine...

Also possible like you firstly wrote :



(defun c:LockAll (/)
(vl-load-com)
(vlax-for lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-put-Lock lay :vlax-true)
)
(setvar 'laylockfadectl 50)
(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports)
(princ)
)

(defun c:UnLockAll (/)
(vl-load-com)
(vlax-for lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-put-Lock lay :vlax-false)
)
(setvar 'laylockfadectl 0)
(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports)
(princ)
)


Here, vla-regen works well with previously setvar 'laylockfadectl...

M.R.

irneb
2011-07-10, 09:48 AM
Thanks, this now seems to work fine. Though I've adjusted it so it resets the LayLockFadeCtl back to what it was:
(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val Check / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(vlax-for item Col
(if (or (not Check) (apply Check (list item)))
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)
)

(defun DoAllLayers (Doc Prop Val Check / LayerCollection)
(DoAllCollection (setq LayerCollection (vla-get-Layers Doc)) Prop Val Check)
)

(defun c:LockAll (/ fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(DoAllLayers *vla-ActiveDocument* 'Lock 1 nil)
(setvar 'LayLockFadeCtl 50)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(setvar 'LayLockFadeCtl fctl)
(princ)
)

(defun c:UnLockAll (/ fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(DoAllLayers *vla-ActiveDocument* 'Lock 0 nil)
(setvar 'LayLockFadeCtl 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(setvar 'LayLockFadeCtl fctl)
(princ)
)

(defun c:FreezeAll (/ clay)
(setq clay (getvar 'CLayer))
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 '(lambda (lay) (not (eq (vla-get-Name lay) clay))))
(princ)
)

(defun c:ThawAll (/)
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 nil)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:OffAll (/)
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 nil)
(princ)
)

(defun c:OnAll (/)
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 nil)
(princ)
)Otherwise, if the user locks a layer the usual way (after an UnLockAll) - the fade won't happen.

Also I've added a Check function - just send nil if not needed. Example use is to check for CLayer equality in the FreezeAll command. Though it's probably not necessary.

irneb
2011-07-10, 10:46 AM
However, if there are no chaining of vla- functions through
(vl-catch-all-apply 'vla-put (list item Prop Val), but using straight vla-put-Lock,
:vlax-true and :vlax-false arguments works fine...Ahhh! I understand! It's not the vl-catch-all-apply, it's the vlax-put which tries to convert lisp values to ActiveX data types and then screws up with :vlax-false.

So when I do this the UnLockAll works fine with :vlax-false!
(vl-catch-all-apply 'vlax-put-property (list item Prop Val))

However, in my code I'd like to keep the vlax-put instead, so I'll have to stick with using the 0/1.

Anyhow, here's my current version:
(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val Check / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(if Check
(vlax-for item Col
(if (apply Check (list item))
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)
)

(defun DoAllLayers (Doc Prop Val Check / LayerCollection)
(layerstate-save "_DoAllLayers_Restore" 255 nil)
(DoAllCollection (setq LayerCollection (vla-get-Layers Doc)) Prop Val Check)
)

(defun c:RestoreAll (/ fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(if (layerstate-has "_DoAllLayers_Restore")
(progn
(layerstate-restore "_DoAllLayers_Restore")
(if (= fctl 50)
(setvar 'LayLockFadeCtl 51)
(setvar 'LayLockFadeCtl 50)
)
(setvar 'LayLockFadeCtl fctl)
(vla-Regen *vla-ActiveDocument* acAllViewports)
)
)
(princ)
)

(defun c:LockAll (/ fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(DoAllLayers *vla-ActiveDocument* 'Lock 1 nil)
(if (= fctl 50)
(setvar 'LayLockFadeCtl 51)
(setvar 'LayLockFadeCtl 50)
)
(setvar 'LayLockFadeCtl fctl)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:UnLockAll (/ fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(DoAllLayers *vla-ActiveDocument* 'Lock 0 nil)
(setvar 'LayLockFadeCtl 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(setvar 'LayLockFadeCtl fctl)
(princ)
)

(defun c:FreezeAll (/)
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 nil)
(princ)
)

(defun c:ThawAll (/)
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 nil)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:OffAll (/)
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 nil)
(princ)
)

(defun c:OnAll (/)
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 nil)
(princ)
)Allows for the case when the LayLockFadeCtl=50 already (otherwise there seems to be no update). Also using the preset value instead, otherwise it always displays at 50 - no matter what the user's set his to.

And then added a RestoreAll so he can restore back to the layers' previous settings. Perhaps not needed as there is the LayerP command.

irneb
2011-07-10, 10:54 AM
BTW, the :vlax-true value is actually -1. Though it doesn't matter much what you send, as long as it's not 0 (which is always "False").

marko_ribar
2011-07-10, 12:31 PM
I see that you added check option for layers in collection, thus vl-chatch-all-apply will trap errors for current layer in FreezeAll and also if there are any other interferences... So check is probably not necessary at all, as for LayerP you are wright - I removed layerstate options, removed checking and changed LockAll function (probably some lines with if statements are sufficient)...



(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)

(defun DoAllLayers (Doc Prop Val / LayerCollection)
(DoAllCollection (setq LayerCollection (vla-get-Layers Doc)) Prop Val)
)

(defun c:LockAll (/ fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(DoAllLayers *vla-ActiveDocument* 'Lock 1)
(setvar 'LayLockFadeCtl fctl)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:UnLockAll (/ fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(DoAllLayers *vla-ActiveDocument* 'Lock 0)
(setvar 'LayLockFadeCtl 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(setvar 'LayLockFadeCtl fctl)
(princ)
)

(defun c:FreezeAll (/)
(DoAllLayers *vla-ActiveDocument* 'Freeze 1)
(princ)
)

(defun c:ThawAll (/)
(DoAllLayers *vla-ActiveDocument* 'Freeze 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:OffAll (/)
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0)
(princ)
)

(defun c:OnAll (/)
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1)
(princ)
)

;;;Use "LayerP" command to restore previous layer state;;;


M.R.

irneb
2011-07-10, 02:15 PM
The problem I have is that with that version of LockAll, it still doesn't update the fade. You have to change LayLockFadeCtl to something other than it is at present. That's why I have that if 50 then -> 51, and then back to what it was; before the regen. That way you "force" whatever's happening in acad's background to update the fade, but you re-use the current setting for the fade value.

I'm not sure if it's a version specific thing, but this happens on my Vanilla 2011.

marko_ribar
2011-07-10, 02:33 PM
On my Acad 2011, 2012 (haven't tried on ACA 2012, ACA 2010, Acad 2008 X86 ), I don't have this problems... If laylockfadectl is set to some value, it keeps it when LockAll, fade effect is displayed, and when UnlockAll as it's written in code (value is set back to its original), thus its called UnlockAll fade effect is not displayed... I don't know what is problem with your version of CAD, but on my everything seems to function as expected...

I use Windows 7 Ultimate X64, Cad versions X64, normal graphic card NVIDIA GeForce 6600 GT...

sorry for this info, it may upset you, but that's the true...

M.R.

irneb
2011-07-10, 02:34 PM
Anyhow. Here's the reason I have that check in there:
(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val Check / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(if Check
(vlax-for item Col
(if (apply Check (list item))
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)
)

(defun DoAllLayers (Doc Prop Val Check / LayerCollection)
(DoAllCollection (setq LayerCollection (vla-get-Layers Doc)) Prop Val Check)
)

(defun LockAll (Check / fctl)
(setq fctl (getvar 'LayLockFadeCtl))
(DoAllLayers *vla-ActiveDocument* 'Lock 1 Check)
(if (= fctl 50)
(setvar 'LayLockFadeCtl 51)
(setvar 'LayLockFadeCtl 50)
)
(setvar 'LayLockFadeCtl fctl)
(vla-Regen *vla-ActiveDocument* acAllViewports)
)

(defun c:LockAll (/)
(LockAll nil)
(princ)
)

(defun c:LockWC (/ wc)
(if (setq wc (strcase (getstring t "\nEnter wildcard match for layers to lock: ")))
(LockAll '(lambda (lay) (wcmatch (strcase (vla-get-Name lay)) wc)))
(LockAll nil)
)
(princ)
)That way you can have a command such as the LockWC which only locks layers matching a certain condition. It just opens up the possibilities. It's much the same reason I did a separate DoAllCollections defun - allows you to run the same idea through stuff like the document's Blocks / Dictionaries / Layouts / etc.

I might have rather done a system of DoAll* and DoWC* to split the 2 ideas, but that's why I added the (if Check ... before the vlax-for. It's just one single if condition, instead of checking every time in the iteration. So there's not much use in splitting the 2 all/check into 2 defuns.

irneb
2011-07-10, 02:41 PM
sorry for this info, it may upset you, but that's the true...No! That doesn't upset me in the least. All it means is there's some difference (possibly a setting which I don't know).

BTW, I'm using Win7-64-Pro, Vanilla Acad 2011-64 (under Revit Arch Suite), i7-2600, 16GB RAM, Geforce GT430.

Where I've found the problem is when on a PaperSpace tab. Perhaps that's the issue!

marko_ribar
2011-07-10, 03:27 PM
No problem for me weather I am in model space or paper space, with using MSPACE viewport or without using viewport... Everything is functioning as written in my version of LockAll... As for check option, you are in wright, it opens new possibilities, I tried to make code more concise, but probably your logic is superior...

As for checking what may be differences between my and your CAD, I'll post my *.svf with *.lsp for comparing values... Only difference that I my have beyond that is that in my acaddoc.lsp I use (setvar 'cmdecho 0) and (vl-cmdf "osnap" "off") for that way *.lsp files are optimized for faster using (command ...) functions within executing *.lsp files, and there are no possibilities for errors in drawing entities with point lists as polylines...

M.R.
See attachments...

Lee Mac
2011-07-10, 03:35 PM
However, in my code I'd like to keep the vlax-put instead, so I'll have to stick with using the 0/1.

Since vlax-get/put and vlax-invoke use native AutoLISP data types, I tend to use actrue / acfalse (1/0) and use :vlax-true / :vlax-false (-1/0) when using vlax-get/put-property and vlax-invoke-method.

marko_ribar
2011-07-12, 05:24 AM
I am sorry, Irne, it seems you were wright about forcing 'laylockfadectl... I've checked that and added before real value 'laylockfadectl 0... Also your logic opens as you said more possibilities so I kept your check option and redefined command functions... Now, everything is perfect, just like you wanted...



(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val Check / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(if Check
(vlax-for item Col
(if (apply Check (list item))
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)
)

(defun DoAllLayers (Doc Prop Val Check / LayerCollection)
(DoAllCollection (setq LayerCollection (vla-get-Layers Doc)) Prop Val Check)
)

(defun c:Lock (/ fctl chk)
(vl-cmdf "_.undo" "m")
(setq fctl (getvar 'LayLockFadeCtl))
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to lock <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Lock 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Lock 1 nil)
)
(setvar 'LayLockFadeCtl 0)
(setvar 'LayLockFadeCtl fctl)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:UnLock (/ fctl chk)
(vl-cmdf "_.undo" "m")
(setq fctl (getvar 'LayLockFadeCtl))
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to unlock <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Lock 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Lock 0 nil)
)
(setvar 'LayLockFadeCtl 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(setvar 'LayLockFadeCtl fctl)
(princ)
)

(defun c:Freeze (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to freeze <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 nil)
)
(princ)
)

(defun c:Thaw (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to thaw <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 nil)
)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:Off (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to turn off <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 nil)
)
(princ)
)

(defun c:On (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to turn on <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 nil)
)
(princ)
)

(princ "\nUse \"undo\" command to restore previous layer state - last made change")
(princ "\nLayer functions are : Lock, Unlock, Freeze, Thaw, Off, On")
(textscr)
(princ)


M.R.
My apology, your CAD is functioning the same as with all versions, so you don't need to compare sysvars...

JaCAD
2011-07-12, 06:21 PM
This looks great, and seems to almost work, Thank you for the help with the VL- coding.
However, I've run into trouble if I do the following:

1-Run "LOCK", lock all layers. All layers are locked, all layers fade.
2-Run "UNLOCK", unlock all layers. All layers are unlocked, All layers appear Un-Faded.
2-Type "RE", regenerate. All layers now appear faded again, but are still unlocked. I can regenerate, pan, zoom, etc, and all layers keep the fade. If I click on the layer drop-down, and then click back into modelspace, and regen, the fade goes away.

Thoughts?
Thanks!



I am sorry, Irne, it seems you were wright about forcing 'laylockfadectl... I've checked that and added before real value 'laylockfadectl 0... Also your logic opens as you said more possibilities so I kept your check option and redefined command functions... Now, everything is perfect, just like you wanted...



(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val Check / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(if Check
(vlax-for item Col
(if (apply Check (list item))
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)
)

(defun DoAllLayers (Doc Prop Val Check / LayerCollection)
(DoAllCollection (setq LayerCollection (vla-get-Layers Doc)) Prop Val Check)
)

(defun c:Lock (/ fctl chk)
(vl-cmdf "_.undo" "m")
(setq fctl (getvar 'LayLockFadeCtl))
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to lock <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Lock 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Lock 1 nil)
)
(setvar 'LayLockFadeCtl 0)
(setvar 'LayLockFadeCtl fctl)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:UnLock (/ fctl chk)
(vl-cmdf "_.undo" "m")
(setq fctl (getvar 'LayLockFadeCtl))
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to unlock <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Lock 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Lock 0 nil)
)
(setvar 'LayLockFadeCtl 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(setvar 'LayLockFadeCtl fctl)
(princ)
)

(defun c:Freeze (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to freeze <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 nil)
)
(princ)
)

(defun c:Thaw (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to thaw <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 nil)
)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:Off (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to turn off <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 nil)
)
(princ)
)

(defun c:On (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to turn on <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 nil)
)
(princ)
)

(princ "\nUse \"undo\" command to restore previous layer state - last made change")
(princ "\nLayer functions are : Lock, Unlock, Freeze, Thaw, Off, On")
(textscr)
(princ)


M.R.
My apology, your CAD is functioning the same as with all versions, so you don't need to compare sysvars...

marko_ribar
2011-07-12, 08:51 PM
Try this... Problem with regen after unlock is now fixed :



(vl-load-com)

(or *vla-AcadObject* (setq *vla-AcadObject* (vlax-get-acad-object)))
(or *vla-ActiveDocument* (setq *vla-ActiveDocument* (vla-get-ActiveDocument *vla-AcadObject*)))

(defun DoAllCollection (Col Prop Val Check / item)
(if (and (vlax-property-available-p Col 'Count)
(> (vla-get-Count Col) 0)
(vlax-property-available-p (vla-Item Col 0) Prop)
)
(if Check
(vlax-for item Col
(if (apply Check (list item))
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
(vlax-for item Col
(vl-catch-all-apply 'vlax-put (list item Prop Val))
)
)
)
)

(defun DoAllLayers (Doc Prop Val Check / LayerCollection)
(DoAllCollection (setq LayerCollection (vla-get-Layers Doc)) Prop Val Check)
)

(defun c:Lock (/ fctl chk)
(vl-cmdf "_.undo" "m")
(setq fctl (getvar 'LayLockFadeCtl))
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to lock <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Lock 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Lock 1 nil)
)
(setvar 'LayLockFadeCtl 0)
(setvar 'LayLockFadeCtl fctl)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:UnLock (/ fctl chk)
(vl-cmdf "_.undo" "m")
(setq fctl (getvar 'LayLockFadeCtl))
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to unlock <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Lock 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Lock 0 nil)
)
(setvar 'LayLockFadeCtl 0)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(setvar 'LayLockFadeCtl fctl)
(vl-cmdf "layer" "")
(princ)
)

(defun c:Freeze (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to freeze <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Freeze 1 nil)
)
(princ)
)

(defun c:Thaw (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to thaw <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'Freeze 0 nil)
)
(vla-Regen *vla-ActiveDocument* acAllViewports)
(princ)
)

(defun c:Off (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to turn off <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'LayerOn 0 nil)
)
(princ)
)

(defun c:On (/ chk)
(vl-cmdf "_.undo" "m")
(setq chk (strcase (getstring t "\nInput wildcard layer name(s) you want to turn on <*-all>: ")))
(if (/= chk "*")
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 '(lambda (lay) (wcmatch (strcase (vla-get-name lay)) chk)))
(DoAllLayers *vla-ActiveDocument* 'LayerOn 1 nil)
)
(princ)
)

(princ "\nUse \"undo\" command to restore previous layer state - last made change")
(princ "\nLayer functions are : Lock, Unlock, Freeze, Thaw, Off, On")
(textscr)
(princ)


M.R.

marko_ribar
2011-07-12, 09:10 PM
Thanks for your revisions JaCAD, I missed your observations... Code is now updated after modifications I've made and now, if you see this message, that means that my intervention is over, so you can test it again...

Regards, M.R.

marko_ribar
2011-07-12, 10:42 PM
Only now regen problem is fixed with little intervention :
line


(vl-cmdf "layer" "")

is added into Unlock function

M.R.
P.S. Previous code with inputs of sysvar 'Laylockfadectl are removed and only old code is valid with this little intervention...

BlackBox
2011-07-13, 05:14 AM
Sorry, I can't see the entire code posted above (on my iPhone)... But why not try:



(vla-regen <ActiveDocumentObject> acAllViewports)

irneb
2011-07-13, 07:15 AM
Sorry, I can't see the entire code posted above (on my iPhone)... But why not try:



(vla-regen <ActiveDocumentObject> acAllViewports)
That's already done! Has no effect unless you change the LayLockFadeCtrl sysvar to something else than it was. The problem then is that the UnLock goes and sets this to 0 (i.e. NoFade), then regens, then sets it back to what it was. Unfortunately then another regen causes the fade to occur even though the Layers are all unlocked.

That's why Marko's added that call to the layer command. Somewhere in there it "updates" the display buffer to reflect that the layers are actually now unlocked.

@Marko: If we have to go with a command (and the layer command at that), then this whole discussion is moot. We could simply have issued the thing onto the layer command in the first place. E.g.:
(defun c:Lock (/ wc echo)
(setq echo (getvar 'cmdecho))
(if (or (not (setq wc (getstring "\nEnter wildcard match for locking layers <*>: ")))
(eq wc ""))
(setq wc "*")
)
(setvar 'cmdecho 0)
(command "._LAYER" "_LOck" wc "")
(setvar 'cmdecho echo)
(princ)
)

(defun c:UnLock (/ wc echo)
(setq echo (getvar 'cmdecho))
(if (or (not (setq wc (getstring "\nEnter wildcard match for unlocking layers <*>: ")))
(eq wc ""))
(setq wc "*")
)
(setvar 'cmdecho 0)
(command "._LAYER" "_Unlock" wc "")
(setvar 'cmdecho echo)
(princ)
)

BlackBox
2011-07-13, 01:30 PM
That's already done!

Cool beans. 8)


@Marko: If we have to go with a command (and the layer command at that), then this whole discussion is moot. We could simply have issued the thing onto the layer command in the first place...


If only someone had suggested that sooner (http://forums.augi.com/showthread.php?p=1135047&mode=linear#post1135047). http://www.theswamp.org/Smileys/other/2funny.gif

Edit: Admittedly, the WC input is a desireable enhacement to my earlier post, but still.

irneb
2011-07-13, 03:03 PM
Yep! That's what I'd also have done. I did see this ... was in 2 minds whether to post a "duplicate" answer http://forums.sky.fm/images/smilies/confused-smiley-013.gif ... but thought WTH? http://forums.sky.fm/images/smilies/lmao.gif Why not see if Renderman can "get" me for it! http://forums.sky.fm/images/smilies/action-smiley-053.gif

BlackBox
2011-07-13, 03:17 PM
Yep! That's what I'd also have done. I did see this ... was in 2 minds whether to post a "duplicate" answer http://forums.sky.fm/images/smilies/confused-smiley-013.gif ... but thought WTH? http://forums.sky.fm/images/smilies/lmao.gif Why not see if Renderman can "get" me for it! http://forums.sky.fm/images/smilies/action-smiley-053.gif

You know it's not like that, my friend.

However, if you're about to say something to the effect of (and I paraphrase) "I'm so sorry... I deleted what I wrote" I'll be kind of upset.

The last thing I want to do is to run someone else off! http://www.theswamp.org/Smileys/other/knuppel2.gif

irneb
2011-07-13, 03:59 PM
I never thought I'd see this :shock:! Renderman tippy-toeing around, trying NOT to bump into someone!
http://t0.gstatic.com/images?q=tbn:ANd9GcQdFq3zJUDW1AMhNywfF3IOdmFanYQRG5-G7vGoVsT2xKTqh2Ea_Q

Nah! I didn't take it like that. I know you meant it as a joke! I really think you were overly "wrist-slapped" on that other thread (if that's what you can actually call a pile-up on someone). You should definitely not change your forum personality because of it!

BlackBox
2011-07-13, 09:51 PM
I never thought I'd see this :shock:! Renderman tippy-toeing around, trying NOT to bump into someone!
http://t0.gstatic.com/images?q=tbn:ANd9GcQdFq3zJUDW1AMhNywfF3IOdmFanYQRG5-G7vGoVsT2xKTqh2Ea_Q

Nah! I didn't take it like that. I know you meant it as a joke! I really think you were overly "wrist-slapped" on that other thread (if that's what you can actually call a pile-up on someone). You should definitely not change your forum personality because of it!

I appreciate that Irneb; I said my piece "over there."

It's not like anyone stepped in as character witness in my defense, so it was kind of me against the room. Interesting that the venom spewed toward me was far, far more, shall we say "incendiary" to be polite, than anything that I said to spark their disapproval in the first place.

John was right... All I can do is put it behind me, and try not to make the same mistake twice.

Change my personality!? :roll:

Good, Bad, or Ugly... I am who I am.
(^^ Which is all three! ^^)