View Full Version : assign layer lineweight based on layer color
kjbusacker
2007-02-28, 09:11 PM
Any suggestions no how to write a lisp routine to add lineweight values to layers based on their layer color? Thanks in advance!
- Kevin
david_peterson
2007-02-28, 09:22 PM
Isn't that what they make .ctb files for?
~sorry I had to do it ;) ~
kjbusacker
2007-02-28, 09:39 PM
Isn't that what they make .ctb files for?
~sorry I had to do it ;) ~
Yeah, let's not go there. :roll:
david_peterson
2007-02-28, 10:03 PM
If you need a quick fix for a few drawings, you could use the filter command to select all object of color "x" and then change the properties.
Any suggestions no how to write a lisp routine to add lineweight values to layers based on their layer color? Thanks in advance!
- Kevin
Hi Kevin,
Maybe this will get you started:
(defun c:assignlineweights ( / layers_col col)
(vl-load-com)
(or *acaddoc* (setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))))
(setq layers_col (vla-get-layers *acaddoc*))
(vlax-for item layers_col
(setq col (vlax-get-property item 'color))
(cond ((= col 1)(vlax-put-property item 'LineWeight acLnWt005))
((= col 2)(vlax-put-property item 'LineWeight acLnWt018))
((= col 3)(vlax-put-property item 'LineWeight acLnWt060));copy down and change to suit
)
)
(princ)
)
The lineweights are listed in the developers documentation under ActiveX and VBA Reference/Properties/Lineweight Property.
HTH
kjbusacker
2007-02-28, 10:28 PM
If you need a quick fix for a few drawings, you could use the filter command to select all object of color "x" and then change the properties.
Nope, have about 300 dwgs (100 layers in each) to process. Besides, I think that filter you mentioned should only give you entities assigned to color "x". All of our entities are color=256 (color by-layer).
kjbusacker
2007-02-28, 10:34 PM
Thanks Tim! I am not an experienced vl-lisper and was hoping to find more basic lisp functions like tblnext, but I will read-up on the vl functions you specified and give it the 'ol college try.
Thanks Tim! I am not an experienced vl-lisper and was hoping to find more basic lisp functions like tblnext, but I will read-up on the vl functions you specified and give it the 'ol college try.
No experience required:
Each color you need to assign a lineweight will have a line like this:
((= col 2)(vlax-put-property item 'LineWeight acLnWt018))
In this example line, any layer with color yellow (2) will be assigned a lineweight of 0.18mm. To add more, just copy the line down, change the color number, and look up and change the lineweight; add as many as you need.
Let me know if you need help loading and running it once you get it set up the way you want.
Edit: ps, you can also post your code and we'll have a look at it, if needed.
kjbusacker
2007-02-28, 11:04 PM
That works great Tim, and makes perfect sense! Thanks again.
I ran into this a while back. We had our company standard layers which were following the AIA-NCS (for the most part) using colors and a .ctb file. We needed to set up for some government work which required NCS 3.1 layer names, and with lineweights, and use thier .ctb file which ignored the colors. The good thing was I had written a lisp routine to make the layers in the first place. I simply did a "find and replace" and added the lineweight function to the routine based on the colors to match our desired plotted width.
The original routine looked like:
(DEFUN C:LYRS (/ CME)
(SETQ CME (GETVAR "CMDECHO"))
(SETQ LYR (GETVAR "CLAYER"))
(SETVAR "CMDECHO" 0)
(COMMAND "LAYER" "MAKE" "A-ANNO-DIMS" "COLOR" "40" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-FUTR" "COLOR" "202" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-STRS-EXST" "COLOR" "20" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-STRS" "COLOR" "4" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-TEXT" "COLOR" "4" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-TEXT-DEMO" "COLOR" "3" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-TITL" "COLOR" "4" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-MTCH" "COLOR" "5" "" "")
(COMMAND "LAYER" "MAKE" "A-AREA" "COLOR" "5" "" "")
(COMMAND "LAYER" "MAKE" "A-AREA-PATT" "COLOR" "10" "" "")
(COMMAND "LAYER" "MAKE" "A-AREA-IDEN" "COLOR" "4" "" "")
(COMMAND "LAYER" "MAKE" "A-CLNG-DEMO" "COLOR" "122" "" "LT" "HIDDEN2" "" "")
(PRINC)
)
The new one looked like this:
(COMMAND "LAYER" "MAKE" "A-ANNO-DIMS" "COLOR" "40" "" "LW" "0.18" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-FUTR" "COLOR" "202" "" "LW" "0.35" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-STRS-EXST" "COLOR" "20" "" "LW" "0.18" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-STRS" "COLOR" "4" "" "LW" "0.35" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-TEXT" "COLOR" "4" "" "LW" "0.35" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-TEXT-DEMO" "COLOR" "3" "" "LW" "0.35" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-TITL" "COLOR" "4" "" "LW" "0.35" "" "")
(COMMAND "LAYER" "MAKE" "A-ANNO-MTCH" "COLOR" "5" "" "LW" "0.5" "" "")
(COMMAND "LAYER" "MAKE" "A-AREA" "COLOR" "5" "" "LW" "0.5" "" "")
(COMMAND "LAYER" "MAKE" "A-AREA-PATT" "COLOR" "10" "" "LW" "0.18" "" "")
(COMMAND "LAYER" "MAKE" "A-AREA-IDEN" "COLOR" "4" "" "LW" "0.35" "" "")
(COMMAND "LAYER" "MAKE" "A-CLNG-DEMO" "COLOR" "122" "" "LW" "0.35" "" "LT" "HIDDEN2" "" "")
(PRINC)
)
This is just a sample, but it helped that I had the routine already written.
Find and replace works great in situation like this.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.