Understanding Scripts

What is a script?

A script is a plain text file containing CC3 commands. It is just like typing the commands at the command prompt. They can be used to draw just about any thing you could draw yourself, with the advantage of automation. A script cannot drive dialog boxes. They are especially useful to programmers who don’t want to master CC3’s rather esoteric file format. The file must be saved with a .scr suffix.

Scripts can include ordinary CC3 commands (text equivalents of the ones in the standard menu) or special macro commands. The text equivalent of commands is listed after each command in the help file and in the help index in Alphabetical list of commands.

How do you use a script?

There are three ways of executing a script file. The first is the only one you need to know to start with.

  1. From the Tools menu, select Macros, Script File then select the script file you have created. Use this method to test scripts

  2. Create a macro something like this then add to the fcw32.macro file instead

 

MACRO SCR

SCRIPTM #myscript.scr

ENDM

 

(The # sign represents CC3’s directory)

Type SCR and press ENTER at the command prompt to activate the script

3. Launch CC3 with a file the same name as the script. For example if you used the command line fcw32.exe test.fcw, CC3 would start with the file test.fcw and run the script test.scr if it exists.

The drawing environment

The first thing to do is to create a template that your script can modify. It should have all the layers, fill styles, line styles and symbol defintions inserted in it that you need. Your script should be tested with this drawing current. Scripts can work on any drawing, but you may have to add fill styles, line styles, colors, etc. before proceeding (see PARTM below for an example of how to do this)

An example

The following script adds a path to a map:

COLOR 29

LAYER COAST/SEA

FSTYLE Solid

LSTYLE Solid

PATH 0,0

100,100

20,23

123,234

34,243

 

SAVE

This script is fairly self-explanatory. It adds a Color 29 path to the map on the COAST/SEA layer, then saves the drawing.

Each RETURN character acts as a delimiter. With commands that keep going until you cancel them (e.g. PATH, above) you will need to put an extra delimiter to finish the command. Semicolons and spaces also acts as a delimiter in most commands, except those which can take a line of text with spaces (e.g. TEXTM)

The easiest way to find out how a command works is to type it in at the command prompt and see what questions it asks.

Insertion points

Most commands ask for a point at some stage. These can be added using Cartesian coordintates e.g. 200,300 or a number of others detailed in "Coordinates" in the help file.

Dialog boxes

You can’t use script files to drive dialog boxes. In order to get round this, there are many commands that have a non-dialog box equivalent. These usually end with an M character. A complete list is available in the Help file. Look under Macro Commands, Alphabetical list of macro commands.

 

A few particularly useful commands are mentioned here.

PARTM

PARTM <part file name> <Scale> <Rotation> <Insertion Point…>

This inserts one drawing into another. It can simply be used to add entities to a drawing, but you can also use it to add layers and symbol definitions. For example, imagine you had a drawing called sympart.fcw that consisted of 10 different symbols, and a line on the LAYER TO INSERT layer (one you have already defined). The following script command would add that layer and the symbol definitions to the current drawing:

 

PARTM #sympart

1 0 0,0

 

UNDO

 

The undo removes the entities, but does not erase the new layer and symbol definitions.

INSSYM

INSSYM <Symbol name> <x scale> <y scale> <rotation angle> <Insertion point…>

This enables you to insert a symbol by name into a drawing, specifying the scale and rotation angle. It will only allow you to insert symbols that are already in the current drawing. Make sure that you have added a copy of any symbol you want to be able to insert using a script into the drawing you want your script to work on. Otherwise, you can use the method described under PARTM above to make sure that the symbol definitions are inserted.

You can also use this to add new fill styles and line styles to a drawing that exist in the part file, if another style of the same name doesn’t already exist. If you want to add symbol fill styles to a draw, you should also include a copy of the symbol in the part.

SYMBOLC

INSSYM <symbol catalog name><Symbol name> <x scale> <y scale> <rotation angle> <Insertion point…>

This works as INSSYM, but allows you to insert a symbol from a specific catalog. It’s a little slower than INSSYM, but allows you to insert symbols from anywhere.

SYMBOLOPT
 SYMBOLOPT <x scale> <y scale> <rotation angle>

This lets you set the symbol scale and rotation. If you use it in combination with the Get Extents macro commands, you can set a suitable symbol scale for any overland map.

TEXM

TEXM <Text> <Text position [under last text]>

This adds text to a drawing. (You can’t use the normal text command as it uses the Edit Text dialog box). E.g.

TEXM This land is unknown; perhaps it will be explored one day.

0,0

If you enter a blank text position, it will be placed under the last piece of text placed.

Text Properties

With scripts you have nearly complete control over the appearance of text. The only fonts you can be sure are available are those installed with Windows 95/NT (Times New Roman, Arial, Symbol and a couple of others). There are a number of text commands that by pass the dialog box:

TSPECF Set font by name

TSPECF <Font name>

If you request a non-existent font, the font remains unchanged.

TSPECH Set text height

TSPECH <Text height>

Text height is the maximum possible for the font (even capitals are usually smaller than the text height). If you do not specify units (e.g. ‘ for feet or " for inches) then the units of the drawing will be used.

TSPECA Set text angle

TSPECA <text angle>

In CC3, 0° is horizontal, angles are measured anti-clockwise.

TSPECP Set text spacing

TSPECP <text spacing>

TSPECT Set text stretch factor

TSPECT <text stretch factor>

TSPECJ Set text justification

TSPECJ <justification code>

Text justification codes:

 

Far Left

Left

Center

Right

Far Right

Above

16

17

18

19

20

Top

--

6

7

8

--

Mid

9

3

4

5

10

Bottom

--

0

1

2

--

Below

11

12

13

14

15

 

TSPECS Set text style

TSPECS <Text style flag>

Text style flags. These can be added to combine styles, e.g. 16+32 is Bold Italic text.

1 Vertical

16 Bold

32 Italic

66 Underline

128 Strikeout

The following example places left justified, bold, underlined height 10 text in the current font at 100,100

TSPECJ 0

TSPECH 10

TSPECS 80

TEXTM River Rollin

100,100

File management

LOADM Load drawing file by name

SCRIPTM Run script by name

TFILEM Insert text file by name with current text specs

WRITEM Create part file by name. Note that if you write to #CLIPBRD.FC$, you are writing to the clipboard.

SAVEASM Save drawing file as name

Controlling entity specifications

COLOR Sets the color for entities to be added. Use the color number.

LSTYLE Sets line style by name

FSTYLE Sets fill style by name

LWIDTH sets the line width

SSET sets the current shet

LAYER Sets the current layer by name

See also Text Specs above.

Controlling layers

LAYER Sets the current layer by name

HIDE hides a named layer

SHOW shows a named layer

FREEZE makes uneditable a named layer

THAW makes editable a named layer (if not hidden)

SHOWA shows all layers

FREEZEA freezes all layers

THAWA thaws all layers

SELBYD Select by: dialog

Selection Methods used in scripts

You don’t often need to perform editing or copying commands in scripts, but you can. Note that entities on hidden or frozen layers will not be affected.

SELBYA Select entities by: All

SELBYP selection prior entities

SELBYL select all entities on a layer

SELBYC select all entities of a particular color (beware – all entities have a color, but some don’t display it, e.g. symbol references)

SELBYD Restores normal selection method

Examples:

LINE 0,0 100,100

 

SELBYP

CHANGEL COAST/SEA

SELBYD

Draws a line then changes the layer of the line to the COAST/SEA layer

SELBYC

CHANGEC 2 4

SELBYD

Changes all color 2 entities to color 4 entities. This example could be used as a basis for changing the color scheme of a contour map.

Combining selections

You can’t use AND, OR and NOT. The only way you can imitate these is by freezing layers. In the color change example above, you could exclude entities on the COAST/SEA layer as follows:

SELBYC

FREEZE COAST/SEA

CHANGEC 2 4

SELBYD

Making Multipolies

In order to make a multipoly, you have to select an number of previously created entities to combine them into one. As you can’t use dialog boxes, you will have to use another selection method to combine the entities. The best way to do this is using a temporary layer and selecting by layer. In CC3, type SELBYL. Now select an editing command. CC3 asks you for a layer. You can type in the layer name. When you have, CC3 selects all entities on that layer and proceeds with the command.

This can lead to entities other than the ones you have added to the drawing being selected, but users should not be using the Temporary layer anyway. If you are kind, you can warn them, or insert a part defined on a layer called "DO NOT USE" or "FOR SCRIPTS ONLY" (see PART above).

You can restore the normal selection procedure using SELBYD (select by dialog.). The following example creates a donut shape on the COAST/SEA layer.

LAYER TEMPORARY

CIRP 0,0 100,100

CIRP 0,0 50,50

SELBYL

FSTYLE SOLID

LWIDTH 0

LSTYLE SOLID

LAYER COAST/SEA

MPOLY TEMPORARY

SELBYD

LAYER COAST/SEA

FREEZE TEMPORARY

The last two lines are to discourage people from using the TEMPORARY layer.

Speeding up scripts

When you are happy that your script generating software is working, you can use the following commands to increase the speed of your scripts.

ECOFF – suppresses command prompt echo. (In other words – none of CC3’s requests for info are displayed)

Use this at the beginning of a script. It can increase speed by 200%.

ECON – restores command prompt echo

RDOFF – suppresses some redraws (e.g. when showing or hiding layers_

RDON – restore command prompts echoes

You can start scripts with RDOFF and ECOFF and finish them with RDON ECON. Note that if a script fails for some reason, you may have to type ECON and press ENTER to restore the command prompt.

Adding Hotspots

ACTIONM <text line> <p1> <p2>

ACTIONM bypasses the dialog box when defining hotspots, where <text line> is the macro name or script text, <p1> is the first point defining the button box, and <p2> is the second point defining the button box.

You could for example add a map link to a drawing like so:

 

ACTIONM LOADM #map.fcw;

0,0

30,30

Note the semicolon after the action text.

Message Boxes and Comments

You can’t add comments to script files, but you can add informative dialog boxes. These can act as comments or warnings to users.

MSGBOX <title> <line of text…>

For example:

MSGBOX Warning

About to run

LINE drawing routine

 

LINE 0,0 100,100 100,1000;

Launching an application

This method allows other applications which create scripts to be launched and run from CC3. Add a macro fcw32.mac using Notepad.

MACRO mylaunch

RUNAPP <full path of your application>

MSGBOX Info

About to run script

 

SCRIPTM <path of the script file your app created>

ENDM

We recommend that your application is a dialog box application (not resizeable) and Always on top.