rosebud5 Posted October 18, 2016 Share Posted October 18, 2016 Hello, forum gave me a great script that will change any lines that I have to a specific line weight. the Script is below. How would I change the script to make a dotted line rather than a solid line? Thanks, PROCEDURE LineWeightChange; { (c) twk based off of original code by Petri Sakkinen 2008 } CONST newWeight = 20; PROCEDURE ChangeIt (h : HANDLE); VAR oldLW : INTEGER; BEGIN oldLW := GetLW(h); IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 10) OR (oldLW = 20) THEN SetLW(h, newWeight); END; BEGIN FOREACHOBJECT(ChangeIt, ((SEL=TRUE))); END; RUN(LineWeightChange); Quote Link to comment
Pat Stanford Posted October 18, 2016 Share Posted October 18, 2016 What version of VW are you working it. It may make a difference. Quote Link to comment
rosebud5 Posted December 16, 2016 Author Share Posted December 16, 2016 HI Pat, Version 2017 Quote Link to comment
Pat Stanford Posted December 16, 2016 Share Posted December 16, 2016 SetLSN(FSActLayer,-Name2Index('Zig Zag')); VW2017 uses LineTypes to define dashes (and other fancy things) in lines. So for your script to change the dash (or dotted), you will need to have a Line Type (created or existing) in the Resource Manager. If you want to edit the line weight and assign a dotted line type in the same script just put the following line right after the SetLW(h,NewWeight); line. SetLSN(h,-Name2Index('Name of your LineType Goes Here'); You may also need to add a RedrawAll; after the ForEachObject line. Hope this helps. Quote Link to comment
rosebud5 Posted December 20, 2016 Author Share Posted December 20, 2016 Thanks!! that works great!, happy holidays to you Quote Link to comment
rosebud5 Posted April 22, 2018 Author Share Posted April 22, 2018 what would be a simple script for changing the line weight and color of a line at the same time, for example, change to .25 line weight and red from an existing .05 and black line. Thanks Hi Pat, just posted that, also I am using 2018 version. thanks for the help Quote Link to comment
Pat Stanford Posted April 22, 2018 Share Posted April 22, 2018 For a single object or for all selected objects? The commands are the same, but the wrapper needs to be different. Do you need it to check the existing and then change only objects that have a specific setting? Or just set for selected objects? If you like the script above, then the basic commands you need are: SetLW(Handle, LineWeightInMils); For the color, you would use SetPenFore(Handle, R,G,B); So you will need to get the RGB value you want. If you have it in a palette, you could use ColorIndexToRGB to get this. So just about like the above script, but with a little math to calculate mils and RGB. If you need more details, please ask again. Quote Link to comment
rosebud5 Posted April 22, 2018 Author Share Posted April 22, 2018 Hi Pat, thanks for the quick reply, I did the following PROCEDURE LineWeightChange; { (c) twk based off of original code by Petri Sakkinen 2008 } CONST newWeight = 5; PROCEDURE ChangeIt (h : HANDLE); VAR oldLW : INTEGER; BEGIN oldLW := GetLW(h); IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 7) OR (oldLW = 10) OR (oldLW = 14) OR (oldLW = 20) THEN SetLW(h, newWeight); SetPenFore(Handle, 221,0,0); END; BEGIN FOREACHOBJECT(ChangeIt, ((SEL=TRUE))); END; RUN(LineWeightChange); Getting an error, any thoughts just trying to change for selected object(s) Quote Link to comment
Pat Stanford Posted April 22, 2018 Share Posted April 22, 2018 First, if you are pasting code into the forum, try and use a code block. Click the <> button in the formatting bar of the post and then paste into that block. It will keep the formatting better. Try this: PROCEDURE LineWeightChange; { (c) twk based off of original code by Petri Sakkinen 2008 } CONST newWeight = 5; PROCEDURE ChangeIt (h : HANDLE); VAR oldLW : INTEGER; BEGIN oldLW := GetLW(h); IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 7) OR (oldLW = 10) OR (oldLW = 14) OR (oldLW = 20) THEN Begin SetLW(h, newWeight); SetPenFore(h, 221,0,0); End; END; BEGIN FOREACHOBJECT(ChangeIt, ((SEL=TRUE))); END; RUN(LineWeightChange); When I wrote Handle, I meant to use a handle to the object. A handle is an identifier for the program to use to find a specific object. In the case your (Petri's) script, the variable that is being used to hold the handle is h. Second, when you want to do more thing as the result of and IF/THEN or REPEAT or UNTIL conditional, you have to put all of the multiple statements between a Begin/End pair. HTH. Quote Link to comment
rosebud5 Posted April 22, 2018 Author Share Posted April 22, 2018 Hi Pat, thanks for walking me through this, totally lost when it comes to coding. I tried the script and line weight changes but color does not? Thanks, Quote Link to comment
rosebud5 Posted April 22, 2018 Author Share Posted April 22, 2018 I tried with a new document and different color and still the line weight changes but the color does not. Thanks, Quote Link to comment
Pat Stanford Posted April 22, 2018 Share Posted April 22, 2018 The way the script is written, it will only work on lines weight of EXACTLY 2, 5, 7, 10, 20 mils. If you normally work in something other than mils or other line weights, then that part of the script will need to be modified. I just copied and pasted the script from above into a VW Script and ran it on a rectangle 20 mil with a blue pen color and a Circle 10 mil with a red pen color. Both ended up being 5 mil with a dark grey/black pen color. Or did you want to fill color to change? Since we were talking about lines, I assumed it was just the pen color. Quote Link to comment
rosebud5 Posted April 23, 2018 Author Share Posted April 23, 2018 Hi Pat, I am guessing that it should not matter, but the script works going from another color back to black when I use it as you did above, but I cant go the other way. I am trying to go from black to red or some other color. if you run the script on a black rectangle/line, will it change to the specified color (red, 221,0,0) Quote Link to comment
Pat Stanford Posted April 23, 2018 Share Posted April 23, 2018 Your RGB values are not right. Each of R G B should be in the range of 0 to 65535. 121 is really small, so the very small trace of red is not noticeable. Try using 65535, 0, 0 in the SetPenFore and you should get a real red. The following script will give you the RGB values for the first selected objects PenFore. Select an object with the color you want and run the script the three values will show up in the dialog box as the X, Y, and Z fields. Using the existing 3Pt dialog box was a quick and dirty hack to get an easy display. Procedure Test; Var R1,G1,B1:Real; Begin GetPenFore(FSActLayer,R1,G1,B1); PtDialog3D('RGB Is', Concat(R1), Concat(G1),Concat(B1),R1,G1,B1); End; Run(Test); Quote Link to comment
rosebud5 Posted April 23, 2018 Author Share Posted April 23, 2018 you are the man! thank you!! Quote Link to comment
rosebud5 Posted May 15, 2018 Author Share Posted May 15, 2018 Hi Pat, script is working great! What about if I wanted to add a fill to the script with a specific color, for example rectangle with same red fill and black outline. < PROCEDURE LineWeightChange; { (c) twk based off of original code by Petri Sakkinen 2008 } CONST newWeight = 5; PROCEDURE ChangeIt (h : HANDLE); VAR oldLW : INTEGER; BEGIN oldLW := GetLW(h); IF (oldLW = 2) OR (oldLW = 5) OR (oldLW = 7) OR (oldLW = 10) OR (oldLW = 14) OR (oldLW = 20) THEN Begin SetLW(h, newWeight); SetPenFore(h, 65535,0,0); End; END; BEGIN FOREACHOBJECT(ChangeIt, ((SEL=TRUE))); END; RUN(LineWeightChange); Quote Link to comment
Recommended Posts
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.