Jump to content

color change in all layer from selected area


Recommended Posts

Posted

Hi

 

This lisp collected from other, but I need to little modify; while I apply command ColorX select color (index dialog box) displayed. After select ok, I need to ask select object at command line; which means I need to change the color selecting window.

Thanks

venki

 

defun C:ColorX( / 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 ColorX in command line")

color change in all layers.lsp

Posted

Something like this ... ? 8)

 

(defun c:TesT (/ color ss i obj)
 (vl-load-com)
 ;;; Tharwat 12. Dec. 2011 ;;;
 (cond ((not acdoc) (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))))
 (if (and (setq color (acad_colordlg 7 t)) (setq ss (ssget "_:L")))
   (progn (vla-startundomark acdoc)
          (repeat (setq i (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
            (vla-put-color obj color)
          )
          (vla-endundomark acdoc)
   )
   (princ)
 )
 (princ)
)

Posted
Something like this ... ? 8)

 

(defun c:TesT (/ color ss i obj)
 (vl-load-com)
 ;;; Tharwat 12. Dec. 2011 ;;;
 (cond ((not acdoc) (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))))
 (if (and (setq color (acad_colordlg 7 t)) (setq ss (ssget "_:L")))
   (progn (vla-startundomark acdoc)
          (repeat (setq i (sslength ss))
            (setq obj (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
            (vla-put-color obj color)
          )
          (vla-endundomark acdoc)
   )
   (princ)
 )
 (princ)
)

 

 

 

 

 

 

Sorry,can't change block objects.pls check ur code.

Posted

Anyway , check this out ... 8)

 

(defun c:TesT (/ color ss i sn obj lst name)
 (vl-load-com)
;;; Tharwat 13. Dec. 2011 ;;;
 (cond ((not acdoc) (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))))
 (if (and (setq color (acad_colordlg 7 t)) (setq ss (ssget "_:L")))
   (progn (vla-startundomark acdoc)
          (repeat (setq i (sslength ss))
            (setq obj (vlax-ename->vla-object (setq sn (ssname ss (setq i (1- i))))))
            (if (eq (cdr (assoc 0 (entget sn))) "INSERT")
              (vlax-for block (setq blk (vla-item (vla-get-blocks acdoc) (setq name (vla-get-EffectiveName obj))))
                (if (and (eq :vlax-false (vla-get-isLayout blk))
                         (eq :vlax-false (vla-get-isXref blk))
                         (if (not (member name lst))
                           (setq lst (cons name lst))
                         )
                    )
                  (vlax-for x blk
                    (if (not (eq "AcDbBlockReference" (vla-get-objectname x)))
                      (vla-put-color x color)
                    )
                  )
                )
              )
              (vla-put-color obj color)
            )
          )
          (vla-regen acdoc acAllViewports)
          (vla-endundomark acdoc)
   )
   (princ)
 )
 (princ)
)

Posted
Hi

This lisp collected from other, but I need to little modify; while I apply command ColorX select color (index dialog box) displayed. After select ok, I need to ask select object at command line; which means I need to change the color selecting window.

 

 

Are you wanting to change the color of the enity or the color of the layer of the entity selected?

Posted

(defun c:aa( / doc bl ss co )
   (PTE:subload-111213-g)
   
   (setq doc (vla-get-activedocument (vlax-get-acad-object))
         bl  (vla-get-blocks doc)
         ss  (PTE:ss->obj(ssget))
         co  (acad_colordlg 256 t)
   )
   
   (foreach ob ss
       (if (= (vla-get-objectname ob) "AcDbBlockReference")
           (PTE:changeC_ ob bl co)
           (vla-put-color ob co)
       )
   )(vla-regen doc acAllViewports)
   (princ)
)(vl-load-com)

(defun PTE:subload-111213-g nil
   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   ;;             Sub Function - 01            ;;
   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   (defun PTE:ss->obj ( ss / i re )
       (if ss
           (repeat (setq i (sslength ss))
               (setq re (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) re))
           )
       )
   )
   
   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   ;;             Sub Function - 02            ;;
   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   (defun PTE:changeC_ ( obj bl co )
       (vlax-for obj (vla-item bl (vla-get-name obj))
           (if (= (vla-get-objectname obj) "AcDbBlockReference")
               (PTE:changeC_ obj bl co)
               (vla-put-color obj co)
           )
       )
   )
)

Posted

Guys, I dont see the logic why the need for a lisp code if the OP only wants the entiy to be on specificied color , wherein the color properties will be not be "Bylayer" Same goes for Block entities: You dont really need a code for that. Besdes with the code you guys written will change all instances of the block and not just the selected block entity

 

Thats the reason why im asking the OP to clarify his request

 

I would think changing the color of the layer where the entity is currently assigned is more likely what the OP wants (or so i think :) )

 

perhaps something like this

 

(defun  c:test (/ LayerColl e ss lst)
 (vl-load-com)
 (setq  LayerColl
    (vla-get-Layers
      (vla-get-activedocument (vlax-get-acad-object))
      )
   )
 (if (and (setq color (acad_colordlg 7 t))
       (setq ss (ssget)))
   (repeat (sslength ss)
     (setq e (cdr (assoc 8 (entget (ssname ss 0)))))
     (if (not (member e lst))
       (progn
         (vla-put-color (vla-item LayerColl e) color)
         (setq lst (cons e lst))
         )
       )
     (ssdel (ssname ss 0) ss)
     )
   )
 )

 

Granting all the enities color properties are "Bylayer"

Posted

(defun c:aa( / doc bl ss co )
   (PTE:subload-111213-g)

   (setq doc (vla-get-activedocument (vlax-get-acad-object))
         bl  (vla-get-blocks doc)
         ss  (PTE:ss->obj(ssget))
         co  (acad_colordlg 256 t)
   )

   (foreach ob ss
       (if (= (vla-get-objectname ob) "AcDbBlockReference")
           (PTE:changeC_ ob bl co)
           (vla-put-color ob co)
       )
   )(vla-regen doc acAllViewports)
   (princ)
)(vl-load-com)

(defun PTE:subload-111213-g nil
   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   ;;             Sub Function - 01            ;;
   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   (defun PTE:ss->obj ( ss / i re )
       (if ss
           (repeat (setq i (sslength ss))
               (setq re (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) re))
           )
       )
   )

   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   ;;             Sub Function - 02            ;;
   ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
   (defun PTE:changeC_ ( obj bl co )
       (vlax-for obj (vla-item bl (vla-get-name obj))
           (if (= (vla-get-objectname obj) "AcDbBlockReference")
               (PTE:changeC_ obj bl co)
               (vla-put-color obj co)
           )
       )
   )
)

 

 

 

Hi good morning!!!!!!!

 

(defun c:aa( / doc bl ss co )

(PTE:subload-111213-g)

 

(setq doc (vla-get-activedocument (vlax-get-acad-object))

bl (vla-get-blocks doc)

ss (PTE:ss->obj(ssget))

co (acad_colordlg 256 t)

)

 

(foreach ob ss

(if (= (vla-get-objectname ob) "AcDbBlockReference")

(PTE:changeC_ ob bl co)

(vla-put-color ob co)

)

)(vla-regen doc acAllViewports)

(princ)

)(vl-load-com)

 

(defun PTE:subload-111213-g nil

;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;

;; Sub Function - 01 ;;

;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;

(defun PTE:ss->obj ( ss / i re )

(if ss

(repeat (setq i (sslength ss))

(setq re (cons (vlax-ename->vla-object (ssname ss (setq i (1- i)))) re))

)

)

)

 

;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;

;; Sub Function - 02 ;;

;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;

(defun PTE:changeC_ ( obj bl co )

(vlax-for obj (vla-item bl (vla-get-name obj))

(if (= (vla-get-objectname obj) "AcDbBlockReference")

(PTE:changeC_ obj bl co)

(vla-put-color obj co)

)

)

)

)

 

 

Thanks for code,great work.This one works perfect,after change my color (including blocks) again I need to change back by layer that time code not working in blocks (block color can't change).

 

Thanks once again for great works

 

venki

Posted (edited)
Hi good morning!!!!!!!

Thanks for code,great work.This one works perfect,after change my color (including blocks) again I need to change back by layer that time code not working in blocks (block color can't change).

 

I stand corrected :lol:

 

Curious, if thats the case why not just use _properties?

 

Another case of ---end justifies the means--- :surrender:

Edited by pBe

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...