Jump to content

Recommended Posts

Posted

Hello,

I looking for a routine that will change specific layer color to colors I want. For example, change all layers with color=10 to color=13, layer with color=50 to color=53 and so on. I need so that when we set xrefs in our company we can offset the architect’s layer colors.

Thanks!

Leos98

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • leos98

    11

  • Lee Mac

    9

  • mjb

    3

  • GE13579

    2

Top Posters In This Topic

Posted

QSELECT can be useful for this kind of thing, depending on the number of layers and drawings you need to change. The use PROPERTIES once the layer is selected.

Posted

Thanks,

But what I’m trying to do is create a routine to set up xrefs. So far I have one that takes the architec’s drawing and detaches all of the xrefs he has, sets all objects to BYLAYER, PURGES the drawing and other things. Now, I also want to include the color changing routine to it.

Posted

Ok sorry I can't be of more help, but all being well a Mod could move this into the AutoLISP/ VBA... section?

Posted

There is a command that changes, merges and suchlikes with layers... unfortunatly I can't remember that, and have no access to autocad today (forgot to borrow a license - doh!) so can't check it out.... if nothing else, I'll check it up tomorrow.

Posted

Here's an oldie by Bill Kramer. It changes the color of all entities (if not Bylayer), not just layers...

COLORF.LSP

Posted

Thanks,

I downloaded and it looks very complex. I do not even know how to incorporate it into my already created routine. Is there something simpler?

Posted

The command I was thinking of is called LAYTRANS - if you have a template with the correct layers, LAYTRANS lets you translate layers in your drawing to those of your chosen template. You can save these translatations to be used again.

Posted

This will just change layer colour - will only affect ents set to "bylayer"

 

(defun c:laycol (/ colLst lay col)
 (vl-load-com)

 (setq colLst '((10 . 13)  ;; <<---<< Edit this as necessary
                (50 . 53)
       ))
 
 (vlax-for l (vla-get-layers
       (vla-get-activedocument
         (vlax-get-acad-object)))
   (setq lay (cons l lay)))
 (foreach layer lay
   (if (setq col (assoc (vla-get-color layer) colLst))
     (vla-put-color layer (cdr col))))
 (princ))

Posted

Lee Mac

Thanks, it works great, is there a way that instead of doing (10 . 13) I can do (red . 13) I tried it but it didn't work.

Posted

I got it, Instead of red I just did (1 . 13), for a minute i was confused and thought 10 was red. But now, what we want to do is change all of the colors in a range. for example, all colors from 10 thru 19 be change to 15, all colors from 20 thru 29 be change to 25. Any thoughts

 

Thanks!

Posted

Hey,

Can I copy the LISP into the macro of a button?

Posted
Hey,

Can I copy the LISP into the macro of a button?

 

For the macro, just make a call to the LISP's syntax from the macro button.

Posted

Try this for ranges:

 

(defun c:laycol (/ colLst lay col)
 (vl-load-com)

 (setq colLst '(
                ((10 19) 15)  ;; <<---<< Edit this as necessary
                ((20 29) 25)
       ))
 
 (vlax-for l (vla-get-layers
       (vla-get-activedocument
         (vlax-get-acad-object)))
   (setq lay (cons l lay)))
 (foreach layer lay
   (foreach col colLst
     (if (<= (caar col) (vla-get-color layer) (cadar col))
   (vla-put-color layer (cadr col)))))
 (princ))

 

Ammend as necessary

Posted

Thanks,

 

I did that andit works, any ideas about the range of colors. I'm sorry for bothering so much but this is my first time working with lisp and I really want to get this working.

 

Thanks again,

 

Leos98

Posted

Wow men I thank you a lot, a little late on my reply

Posted
Wow men I thank you a lot, a little late on my reply

 

Haha - range of colours already sorted dude :P

Posted

Lee Mac

First of all I would like to thank you for all of your help. I just tried the new routine but I keep getting the following error:

 

; error: bad argument type: consp 1

 

I have tried to understand it but due to my lack of knowledge in AUTOLISP have not being able to figure out. Can you please help me with this and also try to explain what is happening so I can start learning?

 

Thanks!

 

Leos98

Posted
Lee Mac

First of all I would like to thank you for all of your help. I just tried the new routine but I keep getting the following error:

 

; error: bad argument type: consp 1

 

I have tried to understand it but due to my lack of knowledge in AUTOLISP have not being able to figure out. Can you please help me with this and also try to explain what is happening so I can start learning?

 

Thanks!

 

Leos98

 

Hmm... I can't seem to reproduce the error that you are receiving - have you modified the posted code? If so, could you post the modified code?

 

Cheers

Posted

What I have done is the following:

 

(defun c:laycol1 (/ colLst lay col)

(vl-load-com)

(setq colLst '(

((10 19) 15) ;;

((20 29) 25)

((30 39) 35)

((40 49) 45)

((50 59) 55)

((60 69) 65)

((70 79) 75)

((80 89) 85)

((90 99) 95)

((100 109) 105)

((110 119) 115)

((120 129) 125)

((130 139) 135)

((140 149) 145)

((150 159) 155)

((160 169) 165)

((170 179) 175)

((180 189) 185)

((190 199) 195)

((200 209) 205)

((210 219) 215)

((220 229) 225)

((230 239) 235)

((240 249) 245)

(1 . 15)

(2 . 55)

(3 . 95)

(4 . 135)

(5 . 175)

(6 . 215)

(7 . 9)

))

 

(vlax-for l (vla-get-layers

(vla-get-activedocument

(vlax-get-acad-object)))

(setq lay (cons l lay)))

(foreach layer lay

(foreach col colLst

(if (

(vla-put-color layer (cadr col)))))

(princ))

 

Thanks!

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