Jump to content

Quick and Easy LISP to change layer colors NEEDED. Thanks


tmelancon

Recommended Posts

I am quite busy, of course, like everyone, I have loads of work needing to get done so I thought I would make this quick post. Hopefully someone with the available time can help out! I basically need a simple routine to change colors from our old standards to our new standards.

 

I am sure it is most likely the simplest routine but if someone could post one and save me a little bit of time I would appreciate it.

 

An example would be layer: TEXT, which with our old standards for 30+ years has been the 'GREEN', we have now changed that and are using color '104' which is more of a turtle green, anyways thats what the boss wants so that's what the boss gets.

 

Currently when we open a drawing that was drawn, say, 10 years ago, it has all of our old layers and their respective old colors.

 

I just need a lisp that would run every time we open a drawing for editing or revisions that would automatically search for the layers and change their properties (colors)..

Link to comment
Share on other sites

I wouldn't see anything wrong with batch processing to expedite the whole ordeal. but we have so many drawings and sometimes do no revisit for months or years. Is there any way we can write something to just run at start up when opening an existing drawing to change the color for layer "TEXT" to "104". The "TEXT" layer is the layer that I really need to address because it dominates in our office standard templates.

Link to comment
Share on other sites

Try this:

(defun c:clc ( / col ent lst )
   (setq lst
      '([highlight]
           ("TEXT"          104)
           ("YourLayerHere" 123)[/highlight]
       )
   )
   (foreach lay lst
       (if (setq ent (tblobjname "layer" (car lay)))
           (progn
               (setq ent (entget ent)
                     col (assoc 62 ent)
               )
               (entmod (subst (cons 62 (if (minusp (cdr col)) (- (cadr lay)) (cadr lay))) col ent))
           )
       )
   )
   (princ)
)

Populate the highlighted list with layer name & colours, matching the format shown.

Edited by Lee Mac
Link to comment
Share on other sites

I know that Lee has already helped you out with this,

but there are also a couple OOTB solutions for this, one being using the LAYTRANS command.

It is a great and I think underutilized command, perfect for situations like this.

Or you could use a .dws (drawing standards file) to do the same thing.

 

Glad Lee got you squared away, he usually does! :beer:

Link to comment
Share on other sites

Hey Gad can you elaborate on the LAYTRANS feature? I am checking it out now, any other details or steps to take to get it done that way?

Link to comment
Share on other sites

Sorry ReMark I should have been more specific. I want to add it to my startup.lsp to execute automatically. I do not want to execute by typing a command in the command line. Thanks

Link to comment
Share on other sites

Lee how can I modify to add this piece to my startup routine? Remove DEFUN? Please assist. Thanks

 

Hi tmelancon,

 

Follow these steps carefully:

 

  • Start a new blank drawing in AutoCAD

 

  • At the command-line, type
    (findfile "acaddoc.lsp")


 

  • If the above returns a filepath, navigate to the file in Windows Explorer and open the file.

 

  • If the above returns nil, open notepad and save a file to your AutoCAD Support Path with filename acaddoc.lsp
    (ensure 'Save as Type' is set to 'All Files').

 

  • Copy the code I have provided to your acaddoc.lsp file (new or existing).

 

  • On a new line after the code, type
    (c:clc)


 

  • Save the acaddoc.lsp file.

Done!

Link to comment
Share on other sites

Thanks for the response Lee, I just needed the little piece of code at the end. I knew I was missing something. Props!

Link to comment
Share on other sites

Hey Gad can you elaborate on the LAYTRANS feature? I am checking it out now, any other details or steps to take to get it done that way?

As it just so happens Shaan has posted a pretty comprehensive description of this feature today ...

http://www.cadtutor.net/forum/showthread.php?80447-AutoCAD-Layer-Translator-Saves-Time-Converting-Files-to-CAD-Standard-Layers.

 

If you load the lisp into your Startup Suite, per ReMark's suggestion it autoloads.

 

Standards Checker using your .dws file does the job too.

And clearly whatever Lee suggests will do it too, in spades!

Link to comment
Share on other sites

Thanks Dadgad, the only thing I was missing was the line at the end where it actually executes the command following the code. Simple fix I was overlooking. Thanks all for everything. God bless!

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