Pat Stanford Posted September 19, 2014 Share Posted September 19, 2014 There is some information on objects that is easily accessible from Vectorscript that is not available in a worksheet. One example of this is the Height and Width of a rectangle. This script reads the Height and Width of a rectangle and stores that information into a record so it can be accessed from a worksheet. The information is not dynamic, so if a rectangle changes size the script needs to be run again. NOTE: VW has a strange definition of Height and Width. They are based on how the object was originally drawn, not on how it is currently rotated on screen. This script only reports the data as shown in the OIP. It could be extended to take rotation into account. That is left as an exercise for the student. This could be easily be expanded to handle other object types and/or other object data to store in other fields. Before running this script, create a Record Format in the file named RectRecord with two fields named RWidth and RHeight. The fields should be created a Numbers and formatted as Dimension. Create and select some Rectangles in the drawing and run the script. Procedure Rect_Dims_to_Record; {Attaches a record to any selected Rectangles that do not have the record attached} {and stores the rectangle height and width into that record.} {Must be rerun any time the dimensions of a rectangel change.} {Written to provde the hgiht and withs of a rectangle in a form} {accessible in a worksheet.} {Sept. 19, 2014} {? 2014, Coviana, Inc - Pat Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} {Use at your own risk. Look both ways before crossing.} {Due to the risk of water pollution, use this, and all, scripts} {at least 100 meters from natural waterways. } Const {Change the constants here to reflect the Record Format and Field Names you are using} RecName='RectRecord'; WidthField='RWidth'; HeightField='RHeight'; Var RectHandle: Handle; {Handle to the current object we are working with} FullHeight, FullWidth : String; {Need to use a single variable to hold the rec.field} Begin RectHandle :=FSActLayer; {Get the first selected object} While RectHandle <> Nil do {Repeat until all selected objects have been handled} Begin If GetType(RectHandle)= 3 then {Check if object is a rectangle} Begin {If it is a rectangle then...} SetRecord(RectHandle,RecName); {Make sure the record is attached} SetRField(RectHandle, RecName, WidthField, Num2StrF(HWidth(RectHandle))); {set width} SetRField(RectHandle, RecName, HeightField, Num2StrF(HHeight(RectHandle))); {Set Height} RectHandle:=NextSObj(RectHandle); {Move on to the next selected object} end Else {If the object was not a rectangle} Begin RectHandle:=NextSObj(RectHandle); {Move on the the next selected object} End; End; End; Run(Rect_Dims_to_Record); Use at your own risk. No rights reserved. Quote Link to comment
Pi_ Posted October 2, 2014 Share Posted October 2, 2014 in the dutch version width and height is accessible in the worksheet =BREEDTE (width) =HOOGTE (height) Quote Link to comment
Pat Stanford Posted October 2, 2014 Author Share Posted October 2, 2014 The BREEDTE and HOOGTE are available, but my guess is they will return the same as the Height and Width in the English version and give you the values for the bounding box, not the rectangle width and height as shown in the OIP. Can you check and see if this is the case? Just a rectangle, duplicate it and rotate it. See what values you get in the worksheet. I would love it if the Dutch version is returning the "correct" values. It will make getting it turned on the English version much easier. Quote Link to comment
MullinRJ Posted October 6, 2014 Share Posted October 6, 2014 Pat, Thanks for posting. This is a great example of how to use scripting, records and worksheets together. I'd love it if someday the worksheet could be made to run attached scripts. I added a few lines at the front to have the script create the required record format if it doesn't exist, so the user doesn't have to. I also shortened the If/Else statement. Hope you don't mind. Raymond Procedure Rect_Dims_to_Record; {Attaches a record to any selected Rectangles that do not have the record attached} {and stores the rectangle height and width into that record.} {Must be rerun any time the dimensions of a rectangel change.} {Written to provde the hgiht and withs of a rectangle in a form} {accessible in a worksheet.} {Sept. 19, 2014} {? 2014, Coviana, Inc - Pat Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} {Use at your own risk. Look both ways before crossing.} {Due to the risk of water pollution, use this, and all, scripts} {at least 100 meters from natural waterways. } { Oct. 06, 2014 - R. Mullin } { Added code to create the required record format if it does not exist. } { This removes the need for the user to create it before running this script. } { Shortened the WHILE/IF loop by removing ELSE clause and getting the } { "NEXT Selected OBJect" outside the IF statement. } Const {Change the constants here to reflect the Record Format and Field Names you are using} RecName = 'RectRecord'; WidthField = 'RWidth'; HeightField = 'RHeight'; Var RectHandle: Handle; {Handle to the current object we are working with} FullHeight, FullWidth : String; {Need to use a single variable to hold the rec.field} Begin { create record format if it does not exist. } if (GetObject(RecName) = nil) then begin NewField(RecName, WidthField, '0', 3, 0); NewField(RecName, HeightField, '0', 3, 0); end; { if } RectHandle := FSActLayer; {Get the first selected object} While (RectHandle <> Nil) do {Repeat until all selected objects have been handled} Begin If (GetType(RectHandle) = 3) then {Check if object is a rectangle} Begin {If it is a rectangle then...} SetRecord(RectHandle,RecName); {Make sure the record is attached} SetRField(RectHandle, RecName, WidthField, Num2StrF(HWidth(RectHandle))); {set width} SetRField(RectHandle, RecName, HeightField, Num2StrF(HHeight(RectHandle))); {set Height} End; { if } RectHandle:=NextSObj(RectHandle); {Move on the the next selected object} End; { While } End; Run(Rect_Dims_to_Record); Quote Link to comment
B.Kilmer Posted December 9, 2014 Share Posted December 9, 2014 Great site you guys have here, I'm only a few months into vectorworks and just starting with writing some code, this site has been invaluable. I hoping someone could help me adjust this script to record the height and width of rectangle shaped 3d symbols from a front or side view. I'm using this to draw stage rigging plots in Spotlight 2015 and need to record the dimensions of the roof beams. 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.