Results 1 to 9 of 9

Thread: Edit Layer Properties by Selection?

  1. #1
    Member
    Join Date
    2014-06
    Posts
    36
    0 Did you find this post helpful? Yes

    Default Edit Layer Properties by Selection?

    Hi,

    Is there a way to graphically select an object and then edit the properties of the lay to which it belongs?

    For example, I'd like to be able to start a command, have it prompt me to select a line, for example, and then allow me to change the corresponding layer color from red to blue.

    Thoughts?

  2. #2
    Programming Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    3,778
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    I wrote this a few years back when I was first learning VL (could use some work to simplify); please take from it what you like (modify to support True Color):

    Code:
    (vl-load-com)
    
    (defun c:CLC () (c:ChangeLayerColor))
    (defun c:ChangeLayerColor (/ *error*)
      (princ "\rCHANGELAYERCOLOR ")
    
      (defun *error* (msg)
        (if acDoc
          (progn
            (vla-endundomark acDoc)
            (if regen
              (vla-regen acDoc acAllViewports)
            )
          )
        ) 
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat " ** Error: " msg " ** ")))
        )                                                                   ; Fatal error, display it
        (princ)
      )
    
      ((lambda (acDoc / ss color oLayers oLayer layers regen)
         (vla-startundomark acDoc)
         (if (not (setq ss (ssget "_i")))
           (progn
             (prompt "\nSelect entity on layer to change color: ")
             (setq ss (ssget))
           )
         )
    
         (if (= 1 (sslength ss))
           (setq color
                  (cdr
                    (assoc 62
                           (tblsearch "layer"
                                      (cdr (assoc 8 (entget (ssname ss 0))))
                           )
                    )
                  )
           )
         )
    
         (if (and ss
                  (princ "\nSelect replacement layer color: ")
                  (setq color (acad_colordlg (if color color 1) nil))
             )
           (progn
             (setq oLayers (vla-get-layers acDoc))
             (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
               (if
                 (not
                   (vl-position (setq oLayer (vla-item oLayers (vla-get-layer x))) layers)
                 )
                  (setq layers (cons oLayer layers))
               )
             )
             (vla-delete ss)
             (foreach oLayer layers
               (if (or regen
                       (= :vlax-true (vla-get-lock oLayer))
                   )
                 (setq regen T)
               )
               (vla-put-color oLayer color)
             )
             (*error* nil)
           )
         )
       )
        (vla-get-activedocument (vlax-get-acad-object))
      )
    )
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD® 2014, and Civil 3D® 2014 Certified Professional | Autodesk® Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

  3. #3
    AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL
    Posts
    1,605
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    To change the corresponding layer color from red to blue of a selected object you can also use the Ribbon Layer List Combo Box. Pick the color box and select the color you want.
    Tom Beauford P.S.M. - Civil 2013 on Windows 7 Pro
    Design Analysis - Leon County Public Works/Engineering
    2280 Miccosukee Rd. Tallahassee, FL 32308-5310
    Ph# (850)606-1516

  4. #4
    Certified AUGI Addict jaberwok's Avatar
    Join Date
    2000-12
    Location
    0,0,0 The Origin
    Posts
    8,371
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    Quote Originally Posted by Tom Beauford View Post
    To change the corresponding layer color from red to blue of a selected object you can also use the Ribbon Layer List Combo Box. Pick the color box and select the color you want.
    Unless the ribbon uses some new magic, that will change the properties of the object, not of its layer (which seems a very odd requirement anyway).
    John B

    "You can't convince a believer of anything; for their belief is not based on evidence, it's based on a deep-seated need to believe." - Carl Sagan

  5. #5
    AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL
    Posts
    1,605
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    Quote Originally Posted by jaberwok View Post
    Unless the ribbon uses some new magic, that will change the properties of the object, not of its layer (which seems a very odd requirement anyway).
    It's worked that way since at least 2012 I believe, make sure you're using the Ribbon Layer List Combo Box not the Ribbon Combo Box - Object Color.
    Tom Beauford P.S.M. - Civil 2013 on Windows 7 Pro
    Design Analysis - Leon County Public Works/Engineering
    2280 Miccosukee Rd. Tallahassee, FL 32308-5310
    Ph# (850)606-1516

  6. #6
    Certifiable AUGI Addict cadtag's Avatar
    Join Date
    2000-12
    Location
    Cairo - no, not Illinois
    Posts
    3,595
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    Lock/unlock, on/off, freeze/thaw, & color all work. Transparency by layer, lineweight, plotstyle, and plot/noplot are only available from the layer manager.

    but really, what's there now is 90% of the layer manipulation I need in a typical session.
    Real pirates wear silk suits & ties, and write EULAs
    The only thing more dangerous to the liberty of a free people than big government, is big business.

    Toward a Sustainable Water Future: Visions for 2050 http://ascelibrary.org/doi/book/10.1061/9780784412077

  7. #7
    AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL
    Posts
    1,605
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    Quote Originally Posted by cadtag View Post
    Lock/unlock, on/off, freeze/thaw, & color all work. Transparency by layer, lineweight, plotstyle, and plot/noplot are only available from the layer manager.

    but really, what's there now is 90% of the layer manipulation I need in a typical session.
    Possible Wish list item: System variable to modify the Ribbon Layer List Combo Box to include options for Transparency by layer, Lineweight, Plotstyle, and Plot/noPlot items. They would need to be modifiable like the existing items. The box size doesn't need to change it already expands as needed on drop-down. Or maybe an option to select a layer to modify in Properties Palette?

    Our base template has so many layers selecting the one you want to modify takes time. I'd like to see an option to have a selected objects layer selected in the layer dialog instead of the current layer.
    Tom Beauford P.S.M. - Civil 2013 on Windows 7 Pro
    Design Analysis - Leon County Public Works/Engineering
    2280 Miccosukee Rd. Tallahassee, FL 32308-5310
    Ph# (850)606-1516

  8. #8
    Programming Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    3,778
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    Quote Originally Posted by cadtag View Post
    ... Transparency by layer, lineweight, plotstyle, and plot/noplot are only available from the layer manager.
    FWIW -

    These properties are accessible through the -LAYER Command, in addition to being exposed to API (as discussed here).

    Cheers
    "Potential has a shelf life." - Margaret Atwood
    AutoCAD® 2014, and Civil 3D® 2014 Certified Professional | Autodesk® Authorized Developer
    Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security

  9. #9
    Certifiable AUGI Addict cadtag's Avatar
    Join Date
    2000-12
    Location
    Cairo - no, not Illinois
    Posts
    3,595
    0 Did you find this post helpful? Yes

    Default Re: Edit Layer Properties by Selection?

    picky picky.... but not clicky
    Real pirates wear silk suits & ties, and write EULAs
    The only thing more dangerous to the liberty of a free people than big government, is big business.

    Toward a Sustainable Water Future: Visions for 2050 http://ascelibrary.org/doi/book/10.1061/9780784412077

Posting Permissions

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