Change specific Line weight to another depending on Layer.

Change specific Line weight to another depending on Layer.

Anonymous
Not applicable
2,323 Views
7 Replies
Message 1 of 8

Change specific Line weight to another depending on Layer.

Anonymous
Not applicable

Hello Lisp Gods.

 

I got a whole lot drawings where I need to change Line weights depending on their current Layer and Weight.

 

For Example:

----------------------------------------------------------------------------------------------------------------

Change a Line weight on Layer 1 with a current weight of 0,5 to the Weight "From Layer" (Or ByLayer).

 

Same with the Line weight on a Line in the Layer 2 with a weight of 0,5 to "From Layer" (Or ByLayer).

 

A Line on Layer 3 with a Line Weight of 0,15 or 0,00 to Weight "From Layer" (Or ByLayer).

----------------------------------------------------------------------------------------------------------------

 

If its possible a Script where i can feed in -Layer- and -Current Weight- and -New Weight-.

 

If this is too much to ask a script that change globally every Line with a Weight of 0,00 to 0,15 would be a great start!

 

 

Disclaimer:

Coulndt find a Solution in this Forum and on Google.

 

Thnaks very much kind strangers.

 

0 Likes
Accepted solutions (1)
2,324 Views
7 Replies
Replies (7)
Message 2 of 8

SeeMSixty7
Advisor
Advisor

If you just want to set all your entities lineweight to by layer just use the change command.

CHANGE

ALL

PROPERTIES

Lweight

BYLayer

 

(command "Change" "all" "p" "lw" "byl" "")

 

If you want to set all your layers to a particular lineweight based on color you could use the following to get you started. The lists below is basically a lists of color numbers to a lineweight, add or adjust as you want them and it will go through all layers and if it is a color in the list it will set the lineweight accordingly.

(defun c:ColorToLW()
	(setvar "LWUNITS" 1)
	(setq defaultlw 0.1778)
	(setq pipingcgtlayerfix
		(list
			(list 1 0.6874)
			(list 2 0.3556)
			(list 3 0.6096)
			(list 4 0.6096)
			(list 15 0.0635)
			(list 253 0.01)
			
	))
	(setq layerdata (tblnext "LAYER" T))
	(while layerdata
		
	 (setq layname (dxf 2 layerdata)
			 laycol  (dxf 62 layerdata)
			 laylin  (dxf 6 layerdata)
			 newlaylw(assoc laycol pipingcgtlayerfix)
	 )
	 (if newlaylw
		(progn
			(setq laylw (cadr newlaylw))
			(command "layer" "lw" (rtos laylw 2 4) layname "")
		)
		(progn
			(command "layer" "lw" "d" layname "")
		)
	 )
	 (setq layerdata (tblnext "LAYER"))
	)
)

good luck

0 Likes
Message 3 of 8

Anonymous
Not applicable

Seems like a good start - but not really what i was looking for.

 

on Layer 1 there are around 15 Line Weights but only 4 of them ( 0.70, 0.80, 1.40 and 0.50) should change to Bylayer.

0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... on Layer 1 with a current weight of 0,5 ...

... in the Layer 2 with a weight of 0,5 ...

... on Layer 3 with a Line Weight of 0,15 or 0,00 to Weight "From Layer" (Or ByLayer).

....



Something like this, perhaps [untested]?

(defun C:FLW (/ pair) ; = Fix LineWeights
  (foreach pair '(("1" 50) ("2" 50) ("3" 150) ("3" 0))
    (command "_.chprop"
      (ssget "_X" (list (cons 8 (car pair)) (cons 370 (cadr pair))))
      "" "_lweight" "ByLayer" ""
    ); command
  ); foreach
  (princ)
); defun

Check the numerical values associated with the lineweights you want in the code-370 entry in entity data [e.g. above, it's 50 there for what shows as 0.5 in Properties].

 

That will fix only things in the current space.  If you need to hit all spaces, (subst)/(entmod) methods could probably be used instead of a CHPROP command.  Again, untested, but I hope this would do it:

(defun C:FLW (/ pair ss n edata) ; = Fix LineWeights
  (foreach pair '(("1" 50) ("2" 50) ("3" 150) ("3" 0))
    (if (setq ss (ssget "_X" (list (cons 8 (car pair)) (cons 370 (cadr pair)))))
      (repeat (setq n (sslength ss))
        (setq edata (entget (ssname ss (setq n (1- n)))))
        (entmod (subst '(370 . -1) (assoc 370 edata) edata))
      ); repeat
    ); if
  ); foreach
  (princ)
); defun

[The question also arises:  By "script" do you mean a Script in AutoCAD's meaning of the word, that is, a .SCR file invoked by the SCRIPT command?  Or do you mean it in the more generic coded-steps way that a lot of people use?  If the former, is that because you use LT and can't use an AutoLisp routine?]

Kent Cooper, AIA
0 Likes
Message 5 of 8

Anonymous
Not applicable

First of all thanks for the effort

Yes , a routine would be great just like u did there, sorry im pretty new to LISP.

 

Your first routine changes all Weights to Bylayer but only Visually (?) and not in the properties itself.

(in the window that opens when u type " Lst " )

 

Second one doesnt do anything.

 

sofar im pretty clueless tho.

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

Your first routine changes all Weights to Bylayer but only Visually (?) and not in the properties itself.

(in the window that opens when u type " Lst " )

 

Second one doesnt do anything.

....


 

After correcting the 150 to 15 in the Layer-"3" pairings, I set up the circumstances and tested both commands, and they both work for me [in Model Space -- I didn't go into multiple spaces].

 

If you mean "LIST" command results not showing the change, when something's lineweight is ByLayer, that is not reported  there -- it simply omits that information, just as it omits color and/or linetype if there's no override on those.  You should see the difference if you LIST something before [with lineweight reported] and after [not].  Or, look at them in the Properties palette afterwards, where it does  show lineweight even when it's ByLayer.

Kent Cooper, AIA
0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

... and another correction of sorts:  The first one should also have a check on whether it found anything of the specified lineweight on the specified Layer, before it tries to change it:

(defun C:FLW (/ pair ss) ; = Fix LineWeights
  (foreach pair '(("1" 50) ("2" 50) ("3" 15) ("3" 0))
    (if (setq ss (ssget "_X" (list (cons 8 (car pair)) (cons 370 (cadr pair)))))
      (command "_.chprop" ss "" "_lweight" "ByLayer" ""); then
    ); if
  ); foreach
  (princ)
); defun
Kent Cooper, AIA
0 Likes
Message 8 of 8

Anonymous
Not applicable

Works perfectly fine now ! Thanks you!

 

In Addition to this is it possible to set all blocks in a drawing via Routine on "ByLayer"?

 

 

in Addition to the addition - Set every Lineweight higher than 50 entities on 50 and every weight lower than 50 on 15 ?

 

Again, Thanks for the help sofar!! 😄

0 Likes