Jump to content
Developer Wiki and Function Reference Links ×

Script for Lineweights


rosebud5

Recommended Posts

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,

Link to comment
  • 2 weeks later...

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);

Link to comment

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

Link to comment

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

Link to comment

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!

Link to comment

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);

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...