Vectorworks, Inc Employee Conrad Preen Posted November 19, 2021 Vectorworks, Inc Employee Share Posted November 19, 2021 Hi everyone! I've started this topic as a place to post any scripts that are handy for ConnectCAD. These will all be unlocked and free for you to edit and hack around to fix other problems. Conrad 1 Quote Link to comment
Vectorworks, Inc Employee Conrad Preen Posted November 19, 2021 Author Vectorworks, Inc Employee Share Posted November 19, 2021 Here's the first one. Rename device AND equipment. Helps you out when the client tells you that you must rename all your devices and you've already begun laying out physical equipment. Just create a document script and past the text below into the script editor. OK, so it looks like some help is needed. Here's how it works. Say you have a device and an equipment item named 'MyDevice' and you want to change them both to 'YourDevice'. Then run the script. Type 'MyDevice' into the Find box and 'YourDevice' into the Replace box. Click OK. When I did this it changed both the equipment and the device called 'MyDevice' into 'YourDevice'. If it can't find any device or Equipment with the Find name then you get the alert saying that it can't be found. Enjoy! C PROCEDURE renameDeviceEquipment; CONST {Alignment constants} kRight = 1; kBottom = 2; kLeft = 3; kColumn = 4; kResize = 0; kShift = 1; VAR dialog :LONGINT; result :INTEGER; this: STRING; that: STRING; PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT); BEGIN GetItemText(dialog, 5, this); GetItemText(dialog, 7, that); END; PROCEDURE renameEquipment(h:HANDLE); BEGIN SetRField(h, 'EquipItem','name', that); ResetObject(h); END; PROCEDURE renameDevices(h:HANDLE); BEGIN SetRField(h, 'Device','name', that); SetRField(h, 'Device','tag', that); ResetObject(h); END; BEGIN dialog := CreateLayout('Rename Device and Equipment', false, 'OK', 'Cancel' ); CreateStaticText( dialog, 4, 'Find', -1 ); CreateEditText(dialog, 5, 'this', 24); CreateStaticText( dialog, 6, 'Replace', -1 ); CreateEditText(dialog, 7, 'that', 24); SetFirstLayoutItem(dialog, 4); SetBelowItem( dialog, 4, 6, 0, 0 ); SetRightItem( dialog, 4, 5, 0, 0 ); SetRightItem( dialog, 6, 7, 0, 0 ); AlignItemEdge( dialog, 5, kLeft, 1, kShift ); AlignItemEdge( dialog, 7, kLeft, 1, kShift ); IF RunLayoutDialog(dialog, Dialog_Handler) = 1 THEN BEGIN result := Count((((PON='Device') | (PON='EquipItem')) & (('Device'.'name'= this) | ('EquipItem'.'name'= this)))); IF result= 0 THEN AlertCritical('no devices or equipment found', 'check that the Find value is correct'); ForEachObject( renameEquipment, (5 & NOTINREFDLVP & ((PON='EquipItem') & ('EquipItem'.'name'= this)))); ForEachObject( renameDevices, (5 & NOTINREFDLVP & ((PON='Device') & ('Device'.'name'= this)))); END; END; Run(renameDeviceEquipment); 1 Quote Link to comment
Vectorworks, Inc Employee Conrad Preen Posted November 19, 2021 Author Vectorworks, Inc Employee Share Posted November 19, 2021 Another one. Copies the user1 param from device objects to equipment. PROCEDURE SyncUserParam; FUNCTION GetFirstDeviceParamValue(h:HANDLE):BOOLEAN; VAR paramvalue:STRING; devicename:STRING; PROCEDURE callback(h:HANDLE); BEGIN SetRField(h, 'EquipItem', 'user1', paramvalue); END; BEGIN IF (GetTypeN(h) = 86) & (GetName(GetParametricRecord(h)) = 'Device') THEN BEGIN paramvalue := GetRField(h, 'Device', 'user1'); devicename := GetRField(h, 'Device', 'name'); ForEachObject(callback, (((R IN ['EquipItem']) & ('EquipItem'.'name'= devicename)))) END; GetFirstDeviceParamValue := FALSE; END; BEGIN ForEachObjectInLayer(GetFirstDeviceParamValue, 0, 1, 1 ); END; Run(SyncUserParam); 1 Quote Link to comment
Vectorworks, Inc Employee Conrad Preen Posted November 19, 2021 Author Vectorworks, Inc Employee Share Posted November 19, 2021 Wonder how these work? Have a look at developer.vectorworks.net in the Function Reference section there are lots of examples for each function. C 1 Quote Link to comment
Vectorworks, Inc Employee Conrad Preen Posted November 24, 2021 Author Vectorworks, Inc Employee Share Posted November 24, 2021 If you aren't sure how to use these scripts in your document, here's a link to the help 😉 https://app-help.vectorworks.net/2022/eng/VW2022_Guide/Scripts/Creating_and_editing_script_palettes_and_scripts.htm?rhhlterm=add script scripts scripting&rhsearch=add a script What I've posted so far is in the Vectorscript language which is a dialect of Pascal. Vectorworks can also use Python as a scripting language. Python has an enormous range of external libraries that let your scrips do all kinds of things like getting data from websites for example. Obviously that's complicated but even if you script a set of repeated actions you normally do by hand you'll be amazed at the time you save. Conrad Quote Link to comment
Pat Stanford Posted January 18, 2022 Share Posted January 18, 2022 And you can still save time after spending a lot of time automating a task you do often. Even if the task doesn't take very long. The following is from the XKCD.com comic. https://xkcd.com/1205/. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. https://xkcd.com/1205/ 1 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.