Jump to content

Useful scripts

Recommended Posts

  • Vectorworks, Inc Employee

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.






PROCEDURE renameDeviceEquipment;
    {Alignment constants}
    kRight                = 1;
    kBottom               = 2;
    kLeft                 = 3;
    kColumn               = 4;
    kResize               = 0;
    kShift                = 1;

    dialog :LONGINT;
    result  :INTEGER;

    this: STRING;
    that: STRING;

PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);
    GetItemText(dialog, 5, this);
    GetItemText(dialog, 7, that);

PROCEDURE renameEquipment(h:HANDLE);
    SetRField(h, 'EquipItem','name', that);

PROCEDURE renameDevices(h:HANDLE);
    SetRField(h, 'Device','name', that);
    SetRField(h, 'Device','tag', that);

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



  • Like 1
Link to comment
  • Vectorworks, Inc Employee

Another one. Copies the user1 param from device objects to equipment.


PROCEDURE SyncUserParam;
    FUNCTION GetFirstDeviceParamValue(h:HANDLE):BOOLEAN;


        PROCEDURE callback(h:HANDLE);
            SetRField(h, 'EquipItem', 'user1', paramvalue);

    IF (GetTypeN(h) = 86) & (GetName(GetParametricRecord(h)) = 'Device') THEN
        paramvalue := GetRField(h, 'Device', 'user1');
        devicename := GetRField(h, 'Device', 'name');
        ForEachObject(callback, (((R IN ['EquipItem']) & ('EquipItem'.'name'= devicename))))

    GetFirstDeviceParamValue := FALSE;


ForEachObjectInLayer(GetFirstDeviceParamValue, 0, 1, 1 );



  • Like 1
Link to comment
  • Vectorworks, Inc Employee

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.



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.

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