Jump to content

change the element color at specific layer


brianfengming

Recommended Posts

i intend to change the element color in specific layer.

i find the lisp as follows. the lisp will change all objects color.

is it possible to modify it to meet our requirement.

 

===QUO==


;Changes the colour of
;all objects in drawing
;icluding blocks and references
;;IT WILL CHANGE ALL REF ALSO MAKE BACKUP OF ALL REF BEFORE USING

(defun mip:layer-status-restore ()
    (foreach item *MIP_LAYER_LST*
      (if (not (vlax-erased-p (car item)))
        (vl-catch-all-apply
          '(lambda ()
             (vla-put-lock (car item) (cdr (assoc "lock" (cdr item))))
             (vla-put-freeze (car item) (cdr (assoc "freeze" (cdr item))))
             ) ;_ end of lambda
          ) ;_ end of vl-catch-all-apply
        ) ;_ end of if
      ) ;_ end of foreach
    (setq *MIP_LAYER_LST* nil)
    ) ;_ end of defun

  (defun mip:layer-status-save ()
    (setq *MIP_LAYER_LST* nil)
    (vlax-for item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
      (setq *MIP_LAYER_LST* (cons (list item
                                  (cons "freeze" (vla-get-freeze item))
                                  (cons "lock" (vla-get-lock item))
                                  ) ;_ end of cons
                            *MIP_LAYER_LST*
                            ) ;_ end of cons
            ) ;_ end of setq
      (vla-put-lock item :vlax-false)
      (if (= (vla-get-freeze item) :vlax-true)
      (vl-catch-all-apply '(lambda () (vla-put-freeze item :vlax-false))))
      ) ;_ end of vlax-for
    ) ;_ end of defun
(defun ChangeAllObjectsColor (Doc Color )
(vlax-for Blk (vla-get-Blocks Doc)
 (if (= (vla-get-IsXref Blk) :vlax-false)
  (vlax-for Obj Blk
    (if (vlax-property-available-p Obj 'Color)
      (vla-put-Color Obj Color)
     )
  )
 )
)
)
(defun C:CX ( / doc col)
  (vl-load-com)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (vla-startundomark doc)
  (mip:layer-status-save)
  (if (setq col (acad_colordlg 7 t))
  (ChangeAllObjectsColor doc  col);_ col � color number
    )
  (mip:layer-status-restore)
  (vla-endundomark doc)
  (princ)
  )
(princ "\nType CX in command line")

==UNQUO==



 

Edited by SLW210
Add Code Tags
Link to comment
Share on other sites

Ok so say change Lines, plines on layer  abc correct ?

 

Need to know which objects to change ?

 

Could be like type "Line"

or "*line" plines & Lines

or "line Arc Circle" 

and so on.

Link to comment
Share on other sites

Note: The routine you submitted updates just objects in block definitions, not inserts or other objects. If that is what you actually want, the solution is simple:

 

Change the following line in the "ChangeAllObjectsColor" function:

(if (vlax-property-available-p Obj 'Color)

To 

(if (and (vlax-property-available-p Obj 'Color)(= (vla-get-layer obj) "<Your Layer Name Here>"))
;; Replace "<Your Layer Name Here>" with the layer name you need.

 

Edited by pkenewell
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...