Using Scripts

Using Existing Scripts

You can find a list of the VectorWorks provided ready-to-use scripts, arranged according to industry, in the VectorWorks Toolkit Folder, which is easily accessed from the Resources palette.

To use an existing script

    1. Locate the script in the resource palette or in a scripts palette.

    2. Double click the script to execute it.

Using Scripts Palettes

When scripts are created either through the VectorScript Editor or automated script facilities, they can be placed in Scripts palettes. You can create multiple script palettes with unique names to sort your scripts. You may add your new scripts to that palette as well.

To use an existing script in a palette

    1. Select the script palette that contains the script from the Script Palettes item in the Window menu.

    The script palette opens.

    2. Double click the script name to run the script.

To create your own scripts palettes

    1. Open the Resources palette.

    2. Click New.

    The Select Resource dialog box appears.

    3. Click Script Palette.

    4. Click Create.

    The Assign Name dialog box appears.

    5. Name the palette.

    6. Click OK.

    The new palette is created and placed in the current drawing.

Automated Script Facilities

Using Custom Selection

With VectorWorks' built-in programming language, you can create a script that selects all objects that meet a specific set of criteria. For example, select all objects with solid black lines.

To create a Custom Selection script

    1. From the Organize menu, select Custom Selection.

    The Custom Selection dialog box appears.

    2. Enter the selection criteria.

    Decide what type of script you want to create--one that Selects, Deselects, or Selects Only objects that meet your criteria.

    3. Select the type of script option you want to create.

    If you select Execute Immediately, then the visibility will be changed when you click OK. If you select Create Script, a name dialog will appear after you click OK. Name the script and it will be added to the default script palette.

    4. Click Criteria.

    The Database Criteria dialog box appears.

    5. Select the desired criteria.

    Use the series of pulldown menus to select each option.

    6. Click OK.

    The Assign Name dialog box appears.

    7. Enter the name you want to give to this new script.

    8. Click OK.

    VectorWorks will place your new script in a Scripts palette. To use the script, double-click its name in the palette.

    Note: Custom Selection works on the entire drawing, not just the active layer, unless you specify a layer in the criteria dialog. Items in groups are not affected.

Using Custom Visibility

With the Custom Visibility script, you can create scripts that hide or show all objects meeting a specific set of criteria, for example, all the walls in your drawing.

To create a Custom Visibility script

    1. From the Organize menu, select Custom Visibility.

    The Custom Visibility dialog box appears.

    2. Select visibility criteria.

    Decide what type of script you want to create--one that will Show, Show Only, or Hide objects that meet your criteria.

    3. Select the type of script option you want to create.

    If you select Execute Immediately, then the visibility will be changed when you click OK. If you select Create Script, a name dialog will appear after you click OK. Name the script and it will be added to the default script palette.

    4. Click Criteria.

    The Database Criteria dialog box appears.

    5. Select the desired criteria.

    Use the series of pulldown menus to select each option.

    6. Click OK.

    The Assign Name dialog box appears.

    7. Enter the name you want to give to this new script

    8. Click OK.

    Your new script is placed in the Scripts palette. To use the script, double-click its name in the palette.

    Note: Custom Visibility works on the entire drawing, not just the active layer, unless you specify a layer in the criteria dialog. Items in groups are not affected.

Custom Tools/Attributes

The Custom Tools/Attributes script allows you to record a variety of settings as you have set them in your current drawing. It is an automated way of creating a script that selects a tool, class, layer, constraint, attribute, and various other items. For example, you can use this feature to simultaneously select the rectangle tool, a blue pen, a red fill, a layer, and a class. When you run the script, all of these selections will be made for you and you can immediately begin to draw.

Note: Before you begin creating specialized scripts, it's a good idea to create a Defaults script. That way, you can easily return to your original settings at any time.

To create a Custom Tools/Attributes script

    1. In your current Drawing Area, select your desired options.

    Set all your object attributes, including pen, fill, color, and pattern. Select your tool from the tools palettes. Set your layers and classes and any other features.

    2. From the Organize menu, select Custom Tool/Attribute.

    The Custom Tool/Attribute dialog box appears.

    3. Select the settings you want the script to set by clicking on the checkbox to include a setting.

    Of the items you set, click only those you wish to be set by the script. All other settings in the drawing will remain unchanged. If you want a tool, symbol, or constraint to be activated, select the appropriate box.

    4. Click OK.

    The Assign Name dialog box appears.

    5. Enter the name you want to give the script in

    6. Click OK.

    VectorWorks will place your new script in a Scripts palette. To use the script, double-click its name in the palette.

Using the VectorScript Editor

You can create simple or even complex scripts using the VectorScript Editor. The VectorScript Editor is designed to provide an authoring environment for creating and editing VectorScript scripts. The Editor's features are designed to provide a basic but complete set of tools for this task.

The Editor contains a main editing window, as well as buttons which invoke procedures and functions, automated scripting facilities, and text import functions. The Editor's text window supports an ASCII text editing capability, similar to most basic text editors. Text may be cut, copied, and pasted.

To create a new script

    1. Open the Resources palette.

    2. Click New.

    The Create Resource dialog box appears.

    3. Click VectorScript Script.

    4. Click Create.

    The Assign Name dialog box appears.

    If there are scripts palettes in the drawing, you will be prompted to select the palette to which the script is to be added.

    If not, you will first be prompted to name a new palette and then to name the script.

    5. Name or select the palette where you want to place the script.

    6. Click OK.

    The Assign Name dialog box appears.

    7. Name the Script.

    8. Click OK.

    The VectorScript Editor appears.

    9. Create the script

    10. Click OK.

    11. Double-click the script in the Scripts palette to run it.

To add procedures to the editor

    1. Click Procedures.

    The Procedures dialog box appears.

    2. Click a Procedure Type (Chapter) and a Procedure.

    3. Click OK.

    The procedure is entered into the editor.

    Note: You may also type in a procedure.

To add selection criteria to the editor

    1. Click Criteria.

    This invokes a Database Criteria dialog as described in "Using Custom Selection".

    2. Pull down the menu to select your criteria.

    3. Click OK.

    The criteria is entered into the editor.

    This is the same as creating a Custom Selection script as described earlier in this chapter. See "Using Custom Selection" .

To add custom tool and attribute information to the editor

    1. Click Tool/Attr.

    2. Check the appropriate boxes.

    Remember that the current settings in your drawing will be executed as described in "Custom Tools/Attributes" .

    3. Click OK.

    The criteria is entered into the editor.

    This is the same as creating a Custom Tool/Attribute script as described earlier in this chapter. See "Custom Tools/Attributes" .

To add imported text from other sources to the editor

    1. Click Get Text.

    The Select VectorScript File dialog box appears.

    2. Select the desired text file.

    3. Click Open.

    All text in the file is entered into the editor.

    Note: Double clicking the file will also add the text to the editor.

To view script errors that occur when running a script

    1. Click View Errors.

    The VectorScript error window appears and lists the errors in your script.

    2. Click Done.

To modify a script

    1. Open the Resources palette.

    2. Select the desired script from the file tree.

    3. Click Edit.

    The VectorScript Editor is invoked.

    4. Edit the script as necessary.

    5. Click OK.

    Your script is updated.

    You can also invoke the VectorScript Editor by holding down the Alt (Windows) or Option (Macintosh) key and double-clicking the script in the Scripts palette.

Hello World Exercise

As with any other scripting language, the best way to get started in VectorScript is to create and edit a basic script. In the world of programming, it is customary to begin with the Hello World script. The following steps are specific to that script.

A detailed description of the VectorScript language is available in the VectorScript language Guide on-line. A function and procedure reference is available through the on-line help in HTML format.

To create the Hello World script

    1. Create a new VectorScript script as described earlier.

    2. Name the script Hello World.

    3. Enter the following text in the Editor window.

    Procedure HelloWorld;

    BEGIN

    Message('Hello, world');

    END;

    Run(HelloWorld);

    4. Click OK.

    5. The Hello World Script is added to a new or existing palette as described earlier.

    If the desired palette is not currently displayed, use the Resources palette and select the desired scripts palette.

    6. Double click Hello World in the palette.

    If you have entered the program properly into the script editor, a message bar will be displayed.

    If you encountered an error, you will need to return to the script editor and check for possible typographical errors. To do this, you can use a shortcut back to the editor. On Macintosh systems, double click on the script name while holding down the Option key; on Windows systems, double click on the script name while holding down the Alt key. Once you have re-entered the script editor, check your script for errors using the View Errors button and try running it again.

    7. Re-enter the script editor and modify your script so that it appears as follows:

    Procedure HelloWorld;

    VAR

    myMessage:STRING;

    BEGIN

    myMessage:= 'Hello again, world';

    Message(myMessage);

    END;

    Run(HelloWorld);

    8. Click OK.

    9. Run the script.

    If you encounter an error, go back and check your script for any typos or other mistakes. One of the most common mistakes made by both novice and experienced VectorScript users is omitting one of the quotes around the message 'Hello again, world'. Another is forgetting semi-colons at the end of a line.

    If you have proceeded to this point without any errors, try removing one of the quotes and executing the script to see how VectorScript responds. Resolving errors and debugging your scripts is an integral part of learning and using VectorScript, so you should get used to seeing an occasional error message and learn to use it as a guide to resolving the problem.



tech@diehlgraphsoft.com
Copyright © 1998, Diehl Graphsoft Inc. All rights reserved.