rosebud5 Posted February 3, 2016 Share Posted February 3, 2016 Hi, I am trying to create a script in order to change a selection (line, etc.) to a different line weight without having to go through the attributes palette dropdown. I know that you can create a dotted line type without any gaps in the resource browser as a line type but you do not have any control over line weight. I have a bunch of line weight scripts that I use all the time but they do not work on currently drawn items. Would like to create a custom tool/attribute that changes the currently selected line with just a click. Thanks, Quote Link to comment
Vectorworks, Inc Employee PVA - Admin Posted February 3, 2016 Vectorworks, Inc Employee Share Posted February 3, 2016 Looks like a sample was added by Pat Standford for a very similar task, though this one might be for replacing a specific line weight with a specified one: http://developer.vectorworks.net/index.php/VS:SetLW Quote Link to comment
rosebud5 Posted February 12, 2016 Author Share Posted February 12, 2016 Hi, thanks for the response. I am not very adept at coding and every time put in the code that you referenced it changes all the objects to the new line weight, not just the selected object. Any suggestions: this is what I have put in the script editor: PROCEDURE LineWeightChange; { © Petri Sakkinen 2008 } CONST { substitute these with the required values } oldWeight = 2; newWeight = 20; PROCEDURE ChangeIt (h : HANDLE); BEGIN SETLW(h, newWeight); END; BEGIN FOREACHOBJECT(ChangeIt, LW = oldWeight); END; RUN(LineWeightChange); Quote Link to comment
Hippocode Posted February 12, 2016 Share Posted February 12, 2016 Change your criteria to use selected objects only. Quote Link to comment
rosebud5 Posted February 12, 2016 Author Share Posted February 12, 2016 OK, thanks for the quick reply. so... do i just change the line that says "FOREACHOBJECT" to "FORSELECTED OBJECT"? sorry for the simple questions but i have not idea what i am doing with the coding. thanks Quote Link to comment
Hippocode Posted February 12, 2016 Share Posted February 12, 2016 Your current criteria is "LW = oldWeight". try adding AND SELECTED which will probably work. Honestly the easiest way is to create a custom selection into a script, which will create the criteria for you. Then copy it inside your script. Quote Link to comment
rosebud5 Posted February 12, 2016 Author Share Posted February 12, 2016 THAT DID NOT SEEM TO WORK, I MUST HAVE MY WORDING WRONG BECAUSE IT GAVE ME AN ARROW Quote Link to comment
rosebud5 Posted February 12, 2016 Author Share Posted February 12, 2016 I meant an error, not arrow, thanks Quote Link to comment
rosebud5 Posted February 12, 2016 Author Share Posted February 12, 2016 OK, do I tried this out and it still did not seem to work PROCEDURE LineWeightChange; { © Petri Sakkinen 2008 } CONST { substitute these with the required values } oldWeight = 2; newWeight = 20; PROCEDURE ChangeIt (h : HANDLE); BEGIN SETLW(h, newWeight); END; BEGIN FOREACHOBJECT(ChangeIt, LW = selectedobject); END; RUN(LineWeightChange); any suggestions, thanks Quote Link to comment
Hippocode Posted February 12, 2016 Share Posted February 12, 2016 As I mentioned earlier, use the custom selection menu command to create the criteria string if you can't make it work. Also, there are various topics to be found showing how this criteria is supposed to be setup. Quote Link to comment
twk Posted February 12, 2016 Share Posted February 12, 2016 PROCEDURE LineWeightChange; { (c) Petri Sakkinen 2008 } CONST { substitute these with the required values } oldWeight = 2; newWeight = 20; PROCEDURE ChangeIt (h : HANDLE); BEGIN SETLW(h, newWeight); END; BEGIN FOREACHOBJECT(ChangeIt, ((LW=oldWeight)&(SEL=TRUE))); END; RUN(LineWeightChange); the ForEachObject Call has two arguments - Callback function, A block of code to be run on the objects found via the criteria - Criteria, The criteria used to find objects you're wanting the callback function to be run on More Info : http://developer.vectorworks.net/index.php/VS:ForEachObject What Petri's code is doing is looking for all objects that have a line weight size specified by the oldWeight variable. ie oldWeight = 2; (LW=oldWeight) I added the SEL=True to the criteria to find only the objects that are selected. More Info on Criterias can be found here: http://developer.vectorworks.net/index.php/VS:Search_Criteria hth Tui Quote Link to comment
rosebud5 Posted February 16, 2016 Author Share Posted February 16, 2016 you are awesome!! thank you so much for laying that out. it totally worked and makes things a lot easier. So, if I want to have the the code change any line weight to the specified line weight, could I put multiple values into code like oldWeight = 2, 5, 10, 20; I tried that and it did not work so I think that i am just writing it wrong, Again, thank you for you help, greatly appreciated! Quote Link to comment
twk Posted February 16, 2016 Share Posted February 16, 2016 There are a number of ways to tackle this. Below is one way of the many ways. Have a look at the vectorscript language guide to get a hang of the syntax required to know. Vectorscript is based off of the Pascal language. I have jumped from VS to python, so my syntax may be incorrect. Double check if it works on an empty file, just in case crashes etc. occur. That is my disclaimer by the way. hehe I am by no means an expert, just an eager learner like yourself no doubt. 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
rosebud5 Posted February 16, 2016 Author Share Posted February 16, 2016 you are not only a Journeyman, you are a wizard as well, totally worked. thanks for all the help!! truly appreciated. 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.