Page 1 of 4 1234 LastLast
Results 1 to 10 of 36

Thread: Layer fade not working in a "LockAll" command

  1. #1
    Active Member
    Join Date
    2008-02
    Location
    Toronto, On
    Posts
    59
    Login to Give a bone
    0

    Question Layer fade not working in a "LockAll" command

    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!

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (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

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    Presuming you have the correct lock fade setting, you need to regenerate the viewports.

    Separately, why not simply use:

    Code:
    (defun c:LOCKALL ()
      (command "._-layer" "lock" "*" "")
      (princ))
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    Also, consider this example:

    Code:
    (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.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    All within one shut .

    Code:
    (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

  5. #5
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    @ Tharwat,

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

    Quote Originally Posted by tharwat View Post
    Code:
    (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:

    Code:
    (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:

    Code:
    (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)
    )

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    Nice one, Lee!

    *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!
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    Quote Originally Posted by Lee Mac View Post
    @ Tharwat,

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

    It could be better written as:

    Code:
    (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 .

  8. #8
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    It's because of this "typo" mistake :

    Code:
    (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.

  9. #9
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    Good catch Marko, I modified things a little too hastily, but hopefully Tharwat gets the idea

  10. #10
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Layer fade not working in a "LockAll" command

    Quote Originally Posted by Lee Mac View Post
    but hopefully Tharwat gets the idea
    Certainly I did.

Page 1 of 4 1234 LastLast

Similar Threads

  1. 2016: AutoCAD "dim" command not working
    By ledgehead in forum AutoCAD General
    Replies: 8
    Last Post: 2015-04-29, 03:06 PM
  2. Replies: 8
    Last Post: 2012-08-18, 01:31 AM
  3. 2012: How to set up DWG export "by layer" just like autocad command?
    By eng.douglasbastos814858 in forum Revit Architecture - General
    Replies: 0
    Last Post: 2012-06-12, 12:55 PM
  4. PDF Layer Filters available by "Plot" command?
    By actsrevolt in forum AutoCAD Plotting
    Replies: 3
    Last Post: 2010-09-18, 09:50 AM
  5. (command ".explode") not working in 2011
    By revituser195 in forum AutoLISP
    Replies: 15
    Last Post: 2010-09-01, 04:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •