Jump to content

Unit Input for Python Scripts


twk

Recommended Posts

Greetings all,

The vectorscript language had a neat feature where in your code you force values to have a certain dimension regardless of the Document Unit settins.

eg.

Procedure UnitThing;
VAR
somvalue : REAL;
Begin;
somevalue := 50mm;
MoveTo(0,0);
LineTo(somevalue, 0);
end;
Run(UnitThing);

A line would be drawn to 50mm regardless of the documents units. If the doc units were set to Feet and Inches it would draw a line of 1.9685" in length.

however in python I can't seem to get this to work. Am I correct to assume that this won't work in python?

Link to comment

Vectorworks stores dimensions in WorldCoord which at this point is equal to one mm. When you used 50cm in VS it would automatically convert it into 500. Regardless of the unit settings, that is the value, always.

When showing the coordinates to the user, the value is modified based on the unit settings, but the length is always the same.

Can't this function do the same ?

http://developer.vectorworks.net/index.php/VS:Str2Num

Link to comment

You can use vs.ValidNumStr("50mm").

Please take a look at dlibrary, where it is used in a much friendlier way.

The Units class helps you with converting stuff and doing calculations. I would advice you to convert to inches, do the math, and than convert back to what you need. Because you can start with length units and end up with area units or volume units.

Edited by Dieter @ DWorks
Link to comment
  • 3 weeks later...

Thanks for the replies. I never knew the VW stored dimensions in worldCoordinates as 'mm'

Just tested the Str2Num() and it didn't work.

However the vs.ValidNumStr() call did.

unitStr = '50mm'

#unitNum = vs.Str2Num(unitStr)
chk, unitNum = vs.ValidNumStr(unitStr)

vs.Message(str(unitNum))

vs.MoveTo(0,0)
vs.LineTo(unitNum, 0)

the unitNum value draws a 50mm string regardless of document units.

..Interesting..

thanks again, Dieter and Hippothamus;

Tui

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...