Greetings to all,
I found a good lisp in a forum, but I need to ask for your help to modify it, so that instead of being able to change the color to objects, I can change in color to the layer that I select from an xref.
(defun c:blcc () (pl:block-color) (princ)) (defun c:encc () (pl:block-ent-color) (princ)) ;;;get from Alaspher http://forum.dwg.ru/showthread.php?t=1036 ;;; http://forum.dwg.ru/showpost.php?p=166220&postcount=18 (vl-load-com) (defun pl:block-ent-color (/ adoc blocks color ent lays) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) lays (vla-get-layers adoc) color (acad_colordlg 256) ) (if color (progn (setvar "errno" 0) (vla-startundomark adoc) (while (and (not (vl-catch-all-error-p (setq ent (vl-catch-all-apply (function nentsel) '("\nSelect entity <Exit>:") ) ) ) ) (/= 52 (getvar "errno")) ) (if ent (progn (setq ent (vlax-ename->vla-object (car ent)) lay (vla-item lays (vla-get-layer ent)) ) (if (= (vla-get-lock lay) :vlax-true) (progn (setq layloc (cons lay layloc)) (vla-put-lock lay :vlax-false) ) ) (vl-catch-all-apply (function vla-put-color) (list ent color)) (vla-regen adoc acallviewports) ) (princ "\nNothing selection! Try again.") ) ) (foreach i layloc (vla-put-lock i :vlax-true)) (vla-endundomark adoc) ) ) (princ) ) (defun pl:block-color (/ adoc blocks color ins lays) (setq adoc (vla-get-activedocument (vlax-get-acad-object)) blocks (vla-get-blocks adoc) lays (vla-get-layers adoc) color (acad_colordlg 256) ) (if color (progn (setvar "errno" 0) (vla-startundomark adoc) (while (and (not (vl-catch-all-error-p (setq ins (vl-catch-all-apply (function entsel) '("\nSelect block <Exit>:") ) ) ) ) (/= 52 (getvar "errno")) ) (if ins (progn (setq ins (vlax-ename->vla-object (car ins))) (if (= (vla-get-objectname ins) "AcDbBlockReference") (if (vlax-property-available-p ins 'path) (princ "\nThis is external reference! Try pick other.") (progn (_pl:block-color blocks ins color lays) (vla-regen adoc acallviewports) ) ) (princ "\nThis isn't block! Try pick other.") ) ) (princ "\nNothing selection! Try again.") ) ) (vla-endundomark adoc) ) ) (princ) ) (defun _pl:block-color (blocks ins color lays / lay layfrz layloc) (vlax-for e (vla-item blocks (vla-get-name ins)) (setq lay (vla-item lays (vla-get-layer e))) (if (= (vla-get-freeze lay) :vlax-true) (progn (setq layfrz (cons lay layfrz)) (vla-put-freeze lay :vlax-false)) ) (if (= (vla-get-lock lay) :vlax-true) (progn (setq layloc (cons lay layloc)) (vla-put-lock lay :vlax-false)) ) (vl-catch-all-apply (function vla-put-color) (list e color)) (if (and (= (vla-get-objectname e) "AcDbBlockReference") (not (vlax-property-available-p e 'path)) ) (_pl:block-color blocks e color lays) ) (foreach i layfrz (vla-put-freeze i :vlax-true)) (foreach i layloc (vla-put-lock i :vlax-true)) ) ) (progn (princ "\BLCC - Changes color of the chosen blocks") (princ "\nENCC - Changes color of the chosen objects (may be element of the block)") (princ))
LinkedIn / AutoCAD Certified Professional
Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.
Solved! Go to Solution.
Solved by john.uhden. Go to Solution.
Solved by ВeekeeCZ. Go to Solution.
I am responding from the context of 2002, but I don't think you can change layer colors on a per-viewport basis. I think you would need some kind of reactor to change a layer's color depending on the active viewport. Then again, what's to prevail when you plot?
John F. Uhden
I appreciate you replying,
What I need is that you can change the "COLOR VP" of the layer that I select in each viewport of an external reference.
LinkedIn / AutoCAD Certified Professional
Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.
@Anonymous, @john.uhden,
The lisp works, but it changes the color in all viewport.
I would like lisp to only change the color, only in the active viewport it has.
Thanks for the help.
LinkedIn / AutoCAD Certified Professional
Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.
This simple routine changes VP Color of selected (nested) layers.
(defun c:xVPcolor ( / col lay ent) (if (and (or (/= 1 (getvar 'CVPORT)) (prompt "\nProgram works inside of VP only!")) (setq col (getint "VP Color number: ")) (setq lay "") ) (progn (while (setq ent (car (nentsel "\nSelect layer: "))) (print (setq lay (strcat (cdr (assoc 8 (entget ent))) ",")))) (if (/= "" lay) (command "_.VPLAYER" "_Color" col lay "" "")))) (princ) )
Thank you very much, it works perfect.
Would it be too much to ask that instead of asking for a color, it unfolds a panel where you can select the color?
LinkedIn / AutoCAD Certified Professional
Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.
That should not be a problem.
(defun c:xVPcolor ( / col lay ent) (if (and (or (/= 1 (getvar 'CVPORT)) (prompt "\nProgram works inside of VP only!")) (setq lay "" col (acad_colordlg 0)) ) (progn (while (setq ent (car (nentsel "\nSelect layer: "))) (print (setq lay (strcat (cdr (assoc 8 (entget ent))) ",")))) (if (/= "" lay) (command "_.VPLAYER" "_Color" col lay "" "")))) (princ) )
You may have encountered an error. When I try to change the color of a reference with a name that contains "@", it does not change the color.
Could you solve this please?
LinkedIn / AutoCAD Certified Professional
Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.
I wonder if reverse quoting the "@" might help as it indicates taking the following character literally.
(setq lay (vl-string-subst "`@" "@" lay))
Plus, if the string does not contain the "@" character then it returns the string unchanged.
John F. Uhden
thanks for the reply,
Could you help me, in which part of the whole code, I put it?
LinkedIn / AutoCAD Certified Professional
Si mi respuesta fue una solución para usted, por favor seleccione "Aceptar Solución", para que también sirva a otro usuarios.
Pardon my rearranging a little. It's just sort of a style I learned from Stephan Koster.
I won't .guarantee that it will fix your "@" problem, but it won't hurt.
(defun c:xVPcolor ( / col lay ent) (and (or (/= 1 (getvar 'CVPORT)) (prompt "\nProgram works inside of VP only!") ) (setq lay "" col (acad_colordlg 0)) (while (setq ent (car (nentsel "\nSelect layer: "))) (print (setq lay (strcat (cdr (assoc 8 (entget ent))) ","))) (/= "" lay) (setq lay (vl-string-subst "`@" "@" lay)) (command "_.VPLAYER" "_Color" col lay "" "") ) ) (princ) )
Sorrry if soe letters got screwed up. My desk light wenrt ouy.
John F. Uhden
Hello, I have a problem, I need to change the color and layer of the blocks. I would like to know if there is an automatic way, since I have about 800 blocks in each file. these one by one I have to trigger the command "refedit" to enter the block and change the layer and color. Another important point, the layer has to be 0 and the color must be ByLayer and the blocks are and different colors and layers ...
Thank you very much in advance!!!
@silvestresallesjunior4 wrote:
Hello, I have a problem, I need to change the color and layer of the blocks. I would like to know if there is an automatic way, since I have about 800 blocks in each file. these one by one I have to trigger the command "refedit" to enter the block and change the layer and color. Another important point, the layer has to be 0 and the color must be ByLayer and the blocks are and different colors and layers ...
Thank you very much in advance!!!
SETBYLAYER Changes the property overrides of selected objects to ByLayer.
or via code
(defun c:Backtolayerzero (/ a) (while (setq a (tblnext "BLOCK" (null a))) (vlax-for itm (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object) ) ) (cdr (assoc 2 a)) ) (if (vlax-write-enabled-p itm) (progn (vla-put-layer itm "0") (vla-put-color itm 256) ) ) ) ) )
command: Backtolayerzero
Hi this Xvpcolor lisp saves me so much time and I really appreciate your help creating it. I am running into a problem with blocks where the internal line work etc. are set to layer 0. Like a spot elevation tic symbol. The xvpcolor lisp does not work for these type of blocks. Do you know anyway around that? I've tried to set the layers to "by block" and "by layer" but that does not change anything. I need to manually change the vp layer of the block to get the colors to be the way I want which can be time consuming if there are a lot of different blocks I'm changing. Thanks in advanced!
Can't find what you're looking for? Ask the community or share your knowledge.