Isolate Layer by Color

Discussion in 'AutoCAD' started by GaryDF, Sep 27, 2004.

  1. GaryDF

    GaryDF Guest

    A coworker requested a routine to isolate layer (layers) by entering a color
    number?
    I know a crazy request. Has anyone ever done this?

    Gary
     
    GaryDF, Sep 27, 2004
    #1
  2. (defun C:LCON ()
    (setq iColor (getint "\nInput Color ? "))
    (setq sLayerName "")
    (setq TS (tblnext "LAYER" T))
    (while TS
    (if (= iColor (abs (cdr (assoc 62 TS))))
    (progn
    (if (= sLayerName "")
    (setq sLayerName (strcat sLayerName (cdr (assoc 2 TS))))
    (setq sLayerName (strcat sLayerName "," (cdr (assoc 2 TS))))
    )
    )
    )
    (setq TS (tblnext "LAYER"))
    )
    (if (/= sLayerName "")
    (command "._LAYER" "off" "*" "on" sLayerName "")
    )
    (princ)
    )
     
    Alan Henderson @ A'cad Solutions, Sep 27, 2004
    #2
  3. GaryDF

    GaryDF Guest

    I keep getting:

    Yes or No, please.
    ; error: Function cancelled
    Really want layer "0" (the CURRENT layer) off? <N>
    Enter an option
    [?/Make/Set/New/ON/OFF/Color/Ltype/LWeight/Plot/Freeze/Thaw/LOck/Unlock/stAte]:

    Gary
     
    GaryDF, Sep 27, 2004
    #3
  4. GaryDF

    T.Willey Guest

    Gary,

    Try this.

    Tim

    (defun c:LayOffColor (/ ctyp *layers)

    (command "_.undo" "_end")
    (command "_.undo" "_group")
    (initget 1)
    (setq ctyp (getint "\n Enter number of color: "))
    (setq *layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
    (vlax-for item *layers
    (if (= (GetX (GetX item 'TrueColor) 'ColorIndex) ctyp)
    (PutX item 'LayerOn 0)
    )
    )
    (command "_.undo" "_end")
    (princ)
    )

    (defun GetX (object prop)
    (if (vlax-property-available-p object prop)
    (vlax-get object prop)
    )
    )

    (defun PutX (object prop val)
    (if (vlax-property-available-p object prop T)
    (vlax-put object prop val)
    )
    )
     
    T.Willey, Sep 27, 2004
    #4
  5. GaryDF

    GaryDF Guest

    Thanks, works great.

    The person wanting the routine, wants to isolate all layers except those layers
    with
    the color entered.

    Which sounds craze to me...

    Gary
     
    GaryDF, Sep 27, 2004
    #5
  6. GaryDF

    T.Willey Guest

    Gary,

    I think all you would have to do is change this line from
    (if (= (GetX (GetX item 'TrueColor) 'ColorIndex) ctyp)
    to
    (if (/= (GetX (GetX item 'TrueColor) 'ColorIndex) ctyp)
    So that non-equal numbers will be turned off.

    Tim
     
    T.Willey, Sep 27, 2004
    #6
  7. GaryDF

    T.Willey Guest

    And you might want to add a (vl-load-com) inside the function. I have one that loads on start so I don't add it to functions.

    Tim
     
    T.Willey, Sep 27, 2004
    #7
  8. GaryDF

    T.Willey Guest

    Gary,

    Here is a new one, it will turn the layers on per that color and turn the other one's off. No check for if layers are frozen though.

    Tim

    (defun c:IsoLayColor (/ ctyp *layers)

    (vl-load-com)
    (command "_.undo" "_end")
    (command "_.undo" "_group")
    (initget 1)
    (setq ctyp (getint "\n Enter number of color: "))
    (setq *layers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
    (vlax-for item *layers
    (if (= (GetX (GetX item 'TrueColor) 'ColorIndex) ctyp)
    (PutX item 'LayerOn -1)
    (PutX item 'LayerOn 0)
    )
    )
    (command "_.undo" "_end")
    (princ)
    )
     
    T.Willey, Sep 27, 2004
    #8
  9. GaryDF

    GaryDF Guest

    Thanks again





    other one's off. No check for if layers are frozen though.
     
    GaryDF, Sep 27, 2004
    #9
  10. The reason for the Yes or No, please is probably due to Expert set to 0
     
    Alan Henderson @ A'cad Solutions, Sep 27, 2004
    #10
  11. GaryDF

    GaryDF Guest

    Thanks, I missed that...working now.

    Gaey
     
    GaryDF, Sep 28, 2004
    #11
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.