Change Layer Color for Printing

Change Layer Color for Printing

RocksterB
Advocate Advocate
4,453 Views
11 Replies
Message 1 of 12

Change Layer Color for Printing

RocksterB
Advocate
Advocate

I'm in need of a routine that will allow me to plot certain layers color RED and change it back to default again later. My plot .PC3 is already setup to plot anything with RED property color as red line work. I have other layers to add, but used these five layers as an example of the situation. I’ll need to manipulate the routine myself later.

 

For example, the layer's original colors are:

  • I-FURN-SEAT, CYAN
  • I-FURN-FREE, GREEN
  • I-FURN-STOR, 50
  • I-FURN-FILE, 70
  • I-FURN-WKSF, 90

 

Now, if the routine finds the controlling layer I-FURN-SEAT is anything color but RED, it changes these just layers I-FURN-SEAT, I-FURN-FREE & I-FURN-STOR to RED. Note I'm not changing all of the A-FURN-* layer colors, only the layers just mentioned. This is a temporary property change used to plot the drawings with RED line work.

 

The results would be:

  • I-FURN-SEAT, RED
  • I-FURN-FREE, RED
  • I-FURN-STOR, RED
  • I-FURN-FILE, 70
  • I-FURN-WKSF, 90

 

After plotting, I run the "same" routine and if it finds the controlling layer I-FURN-SEAT is RED, it changes them back to their original layer color.

  • I-FURN-SEAT, CYAN
  • I-FURN-FREE, GREEN
  • I-FURN-STOR, 50
  • I-FURN-FILE, 70
  • I-FURN-WKSF, 90

 

Hopefully, I explained what I'm looking for clearly. Is something like this possible?

0 Likes
Accepted solutions (1)
4,454 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

Well, it's easy to write such routine but soo obsolete.

 

VP color override does not work for you?

Also, you should consider using STB plot styles... it's so much easier.

0 Likes
Message 3 of 12

RocksterB
Advocate
Advocate

True, I hadn't considered using VP overrides. This would involve multiple clicking instead of the reduced mouse clicks using a lisp routine. I could use a Layer State Manager (LMAN)to toggle the layers from default color to RED and back again, but going from drawing to drawing a layer might pop or off that shouldn't be in that visibility state. The same visibility on/off issue can occur if I used the LAYER TRANSLATOR (LAYTRANS). Also, the routine should apply the layer itself not just a VPORT. I plot multiple LAYOUT tabs from a single DWG file.

 

I’m open to any other suggestions. Hmm...,now you've got me thinking out side the box. Could I use the ACTION RECORDER (ATCRECORD) for this?

0 Likes
Message 4 of 12

ВeekeeCZ
Consultant
Consultant

Ok... something simple then...

 

(defun c:PlotRedToggle (/ lay)
  
  (if (or (setq lay (tblsearch "LAYER" "I-FURN-SEAT"))
	  (prompt "\nNo layer 'I-FURN-SEAT' found."))
    
    (if (/= 1 (abs (cdr (assoc 62 lay))))
      (progn
	(command "_layer"
		 "_c" 1 "I-FURN-SEAT"
		 "_c" 1 "I-FURN-FREE"
		 "_c" 1 "I-FURN-STOR"
		 "_c" 70 "I-FURN-FILE"
		 "_c" 90 "I-FURN-WKSF"
		 "")
	(princ "\nLayers were turned to RED."))
      
      (progn
	(command "_layer"
		 "_c" "CYAN" "I-FURN-SEAT"
		 "_c" "GREEN" "I-FURN-FREE"
		 "_c" 50 "I-FURN-STOR"
		 "_c" 70 "I-FURN-FILE"
		 "_c" 90 "I-FURN-WKSF"
		 "")
	(princ "\nLayers were turned to their original colors.")
	)))
  (princ)
  )
0 Likes
Message 5 of 12

RocksterB
Advocate
Advocate

That did exactly what I needed. One mouse click, layers and entities change to RED. Click once more anytime later, the RED layers change back to the default colors. Based on how the routine was written, I was able to provide additional layers. Great, I'm happy! 

0 Likes
Message 6 of 12

hak_vz
Advisor
Advisor
Accepted solution

If you have a file .txt that has list of layer names and its colors written as

layer1,50
layer2,100
1,15
2,25

This code will change color of that layers to that color. Since I use entmod approach colors should be written as numbers 1 - 255

 

(defun c:lcff (/ *error* str_to_lst f file1 redak lst layer_color layer_name lay)
(defun *error* ()
    (setvar "cmdecho" 1)
    (close file1)
)
(defun str_to_lst (str / len lst pos )
    (setq len (1+ (strlen ",")))
    (while (setq pos (vl-string-search "," str))
        (setq lst (cons (substr str 1 pos) lst)
              str (substr str (+ pos len))
    )
    )
    (reverse (cons str lst))
)
    (setvar "cmdecho" 0)
    (setq f (getfiled "Open File" (getvar "dwgprefix") "txt" 2))
    (setq file1 (open f "r"))
    
    (while (setq redak (read-line file1)) 
        (setq lst (str_to_lst redak) layer_name (car lst) layer_color (atoi(cadr lst)))
        (if (tblsearch "layer" layer_name)
            (progn
                (setq lay (entget (tblobjname "layer" layer_name)))
                (setq lay (subst (cons 62 layer_color)(assoc 62 lay) lay))
                (setq lay (entmod lay))
            )
        )
    )
    (close file1)
    (setvar "cmdecho" 1)
    (princ)
) 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 12

RocksterB
Advocate
Advocate

HAK, I tried your routine and it did work. I would probably use this one if I were changing a large amount of layers. In this situation, I'm changing only 10-12 layers. I didn't see a method to toggle to RED to default layer color. I guess I'd need two .TXT files, one to change the layers to RED and another to change them back to default colors.

0 Likes
Message 8 of 12

hak_vz
Advisor
Advisor

I didn't see a method to toggle to RED to default layer color. I guess I'd need two .TXT files, one to change the layers to RED and another to change them back to default colors.

I've made  it the way that you have two txt files, one with original layer colors and other with changes. If needed, I can try to modify this so that you have one file with covers both situation. I'd add a function to write out all layers with current colors, that can be easily edited. Idea is to have thx file written as

"layer_name,original_color,changed color".  In that case you are not restricted to change colors to RED but can do it how ever you like it.  Also I have to check how this function works regarding changing color to current layer. If it doesen't work we have to create temporary curent layer, perform all changes and reset curent layer.  Presumption is  that all element in a layer are created using color bylayer. So helper function to do that would be handy. Also we presume that all layers use indexed colors. If true colors are needed then this has to be done to. In that case code becomes a bit complex. Original function was written as a simple and not completely optimized solution.

At the moment, combining @ВeekeeCZ  answers your request.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 12

RocksterB
Advocate
Advocate

Thanks HAK for your added comments. 

0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant

@RocksterB wrote:

.... to plot certain layers color RED and change it back to default again later. ....

Now, if the routine finds the controlling layer I-FURN-SEAT is anything color but RED, it changes these just layers I-FURN-SEAT, I-FURN-FREE & I-FURN-STOR to RED. .... This is a temporary property change used to plot the drawings with RED line work.

....

After plotting, I run the "same" routine and if it finds the controlling layer I-FURN-SEAT is RED, it changes them back to their original layer color. ....



I think this can be a lot simpler, and involve only one  running of the command to cover both halves of the above description and  include the Plotting.  Lightly tested:

(defun C:PFR (); = Plot Furniture Red
  (if (member '(62 . 1) (tblsearch "layer" "I-FURN-SEAT")); reference Layer is Red?
    (progn ; then -- Plot, then put standard [non-red] colors to certain Layers
      (initdia)
      (command-s "_.plot")
      (command "_.layer" "_color" 4 "I-FURN-SEAT" "_color" 3 "I-FURN-FREE" "_color" 50 "I-FURN-STOR" "")
    ); progn
    (progn ; else -- change certain Layers to Red, Plot, put Layer colors back
      (command "_.layer" "_color" 1 "I-FURN-SEAT,I-FURN-FREE,I-FURN-STOR" "")
      (initdia)
      (command-s "_.plot")
      (command "_.layerp"); revert Layer color change
    ); progn
  ); if
  (princ)
); defun

Note that you can apply the same Layer-command option to more than one Layer at a time, with comma separators [all 3 to Red in one shot].

Kent Cooper, AIA
0 Likes
Message 11 of 12

RocksterB
Advocate
Advocate
 

Kent, that's really, really nice. I love the temp "RED  on/RED off" action. I can't use it, but its nice! The reason I can't use it is because in my situation, I need to only PUBLISH various LAYOUT tabs within one drawing file. Not all the LAYOUT tabs, just a few. Not for the full bound set, just loose sheets for certain sub-disciplines. Now..., if you could build the routine with that in mind, that would be great!

0 Likes
Message 12 of 12

Sea-Haven
Mentor
Mentor

Back to a file yeah ten now, oh need 11, no 12, maybe 13. don't forget continuous line type all line work.

 

Its easy

layername,color1,color2

layer1,50,1
layer2,100,1
1,15,1
2,25,1

 

Just flip (nth 1 or 2

 

look at lee-mac parse csv.lsp

 

0 Likes