Jump to content

Change color of selected Xref layer


Aftertouch

Recommended Posts

Hello all,

 

I was looking for a code that allows me to select a object of a xref, and asks me to change the layers color.

 

now i found the code below...

 

(defun c:ChangeLayerColor (/ Sel EntList DataList cnt Num ClrNum EntData)

(if (setq Sel (nentsel "\n Select object to change layers color: "))
(progn
 (if (> (length Sel) 2)
  (setq EntList (cons (car Sel) (last Sel)))
  (setq EntList (cons (car Sel) EntList))
 )
 (setq DataList
  (mapcar
   '(lambda (x / EntData)
    (setq EntData (entget x))
    (cons (cdr (assoc 0 EntData)) (cdr (assoc 8 EntData)))
   )
   EntList
  )
 )
 (setq cnt 0)
 (textscr)
 (prompt "\n Select number of layer to change color: ")
 (foreach lst DataList
  (prompt (strcat "\n " (itoa cnt) " - " (cdr lst) " - Object [ " (car lst) " ]"))
  (setq cnt (1+ cnt))
 )
 (while
  (and
   (not (setq Num (getint (strcat "\n Select number between 0 - " (itoa (1- cnt)) ": "))))
   (not (< 0 Num (1- cnt)))
  )
 )
 (graphscr)
 (if (and Num (setq ClrNum (acad_colordlg 253)))
  (progn
   (setq EntData (entget (tblobjname "Layer" (cdr (nth Num DataList)))))
   (entmod
    (subst
     (cons 62 ClrNum)
     (assoc 62 EntData)
     EntData
    )
   )
   (command "_.Regen")
  )
 )
)
)
(princ)
)

 

But this gets all objects of the selected... So if i select a block it gets the 'XREF' layer, the block layer, the hatch in the blocks layer etc.. and i need to give in a number for wich i want to change.

 

Can this code be stripped down so it instant changes the color of the layer of the selected object. So when i select a block of an xref, it changes the layer the block is on for example. :unsure:

Also... this code only allows Index Colors... how can true colors be added?

 

Thanks in advance. :-)

Link to comment
Share on other sites

I can't help you with a lisp, but the system variable VISRETAIN might be of interest to you.

 

Hey Dadgad,

Visretain has absolutely nothing to do with my 'problem'. :-)

Link to comment
Share on other sites

Hey Dadgad,

Visretain has absolutely nothing to do with my 'problem'. :-)

 

Perhaps I am mistaken. :huh:

I was under the impression that by changing the VISRETAIN setting to 0, that you could essentially override the layer color defined in the original external drawing's layer table, and that your new layer color would be saved within your new drawing's layer table.

My apologies, should that not be the case. :|

Edited by Dadgad
Link to comment
Share on other sites

  • 7 months later...
Hello all,

 

Can this code be stripped down so it instant changes the color of the layer of the selected object. So when i select a block of an xref, it changes the layer the block is on for example. :unsure:

Also... this code only allows Index Colors... how can true colors be added?

 

 

Hi... sorry to necro your thread. but i just joined the forum.

 

I found these and they suit my needs.

I can't remember if i modified them or not.

I have several others and a couple of my own but these should do what you want.

 

I cant help you with true color as usage of true colors for what i do is generally not permitted.

 

select multiple with color input


(defun c:CHCOL (/ ncol ent lst)
(while (setq ent (car (nentsel "\nSelect enity on layer: ")))
(princ (setq ent (cdr (assoc 8 (entget ent)))))
(setq lst (cons ent lst)))
(setq ncol (getint "\nEnter index color number: "))
(and lst
(mapcar '(lambda (x)
(setq ent (entget (tblobjname "layer" x)))
(entmod (subst (cons 62 ncol) (assoc 62 ent) ent)))
lst))
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) 1))
(vl-load-com)

 

select one then color with menu


(defun C:CHCOLPICK (/ lay col)
 (setq
   lay (cdr (assoc 8 (entget (car (nentsel "\nObject on Layer to assign color to: ")))))
   col (acad_colordlg (cdr (assoc 62 (tblsearch "layer" lay))) nil)
 )
 (command "_.layer" "_color" col lay "")
 (princ)
)

 

cheers,

mugsy

Link to comment
Share on other sites

Perhaps I am mistaken. :huh:

I was under the impression that by changing the VISRETAIN setting to 0, that you could essentially override the layer color defined in the original external drawing's layer table, and that your new layer color would be saved within your new drawing's layer table.

My apologies, should that not be the case. :|

 

VISRETAIN is pretty much just like the reset button on your calculator but for the xref layers.

sets all layer overrides back to what is stored in the xref.

 

Cheers,

mugsy

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