Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble excluding objects on certain layers

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
shawn.p.phillips
424 Views, 3 Replies

Trouble excluding objects on certain layers

In the lisp below (I found this yesteray on one of my exhaustive searches and not sure who JB is but credit to him for this fine LISP routine), it converts all the linework in blocks, attributes, dimensions, etc to color by layer.  As I discovered this morning there are a few exceptions to the rule, in this case only effecting linework inside blocks (not dimsensions or attributes).  I tried to insert a "(not (wcmatch" line where I thought it should be but it didn't work.  The linework still got changed.  Any suggestions?  The line I added is towards the end of the routine.

 

;; JB 6/6/2006
;; Set all objects to color bylayer including attributes and
;; dimensions. Works with objects in deep nested blocks.
;; Temporarily unlocks any locked layers.
(defun c:ColorByLayer (/ *error* doc layers blocks locklst ByLayerAtt ByLayerDim)
    (defun *error* (msg)
        (cond
            ((not msg))
            ((wcmatch (strcase msg) "*QUIT*,*CANCEL*"))
            (T (princ (strcat "\nError: " msg)))
        )
        (foreach x locklst (vla-put-lock x :vlax-true))
    (vla-regen doc acActiveViewport)
    (vla-EndUndoMark doc)
    (princ)
    ) ;end error
;; Set attributes to color acByLayer.
;; Argument: a block reference vla-object.
    (defun ByLayerAtt (blkref)
        (if (vlax-property-available-p blkref 'HasAttributes)
            (foreach att (vlax-invoke blkref 'GetAttributes)
                (vlax-put att 'Color acByLayer)
            )
        )
    ) ;end
;; Set dimension or leader elements to color acByLayer.
;; Argument: a dimension or leader vla-object.
;; Thanks to Tim Willey for this code.
    (defun ByLayerDim (dim)
        (if (wcmatch (vlax-get dim 'ObjectName) "*Dimension,AcDbLeader")
            (mapcar
               '(lambda (x)
                    (vl-catch-all-apply 'vlax-put (list dim x acByLayer))
                )
               '("Color" "DimensionLineColor" "ExtensionLineColor" "TextColor")
            )
        )
    ) ;end
;;; Primary Function ;;;
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
        layers (vla-get-layers doc)
        blocks (vla-get-blocks doc)
    )
    (vla-StartUndoMark doc)
;; temporarily unlock locked layers
    (vlax-for x layers
        (if (eq :vlax-true (vla-get-lock x))
            (progn
                (vla-put-lock x :vlax-false)
                (setq locklst (cons x locklst))
            )
        )
    )
    (vlax-for blk blocks
        (if (eq :vlax-false (vla-get-IsXref blk))
            (vlax-for item blk
                (ByLayerDim item)
                (ByLayerAtt item)
                (vlax-put item 'Color acByLayer)
                (not (wcmatch (vla-get-Layer item) "A-GLAZ,S-FRAM,A-SPCL"))
            )
        )
    )
    (*error* nil)
) ;end Primary Function
;shortcut
(defun c:CBL () (c:ColorByLayer))

3 REPLIES 3
Message 2 of 4
hmsilva
in reply to: shawn.p.phillips


 

@shawn.p.phillips wrote:

In the lisp below (I found this yesteray on one of my exhaustive searches and not sure who JB is but credit to him for this fine LISP routine)

 


JB = Joe Burke
http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-color-to-by-layer/m-p/1649338/...
Try
(if (eq :vlax-false (vla-get-IsXref blk))
  (vlax-for item blk
    (if (not (wcmatch (vla-get-Layer item) "A-GLAZ,S-FRAM,A-SPCL"))
      (progn
        (ByLayerDim item)
        (ByLayerAtt item)
        (vlax-put item 'Color acByLayer)
      )
    )
  )
)

 

Hope that helps

Henrique

EESignature

Message 3 of 4
shawn.p.phillips
in reply to: hmsilva

Yes Sir!  Thanks again!

Message 4 of 4
hmsilva
in reply to: shawn.p.phillips

You're welcome, Shawn
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost