Drawing Sync Help

Formulas and Script

Language: JavaScript (w3schools) and VBScript (Microsoft).
Debugger: Visual Studio for Windows (Express, Desktop, Professional, Premium, or Ultimate)

VBS Tutorial: Scripting: Your First Steps
File System Object: Introduction to the File System Object Model


SAMPLE FORMULA

From the C:\Program Files\Code Truck\Drawing Sync\Agent\Drawing folder, copy formula.dsg, formula.olj, and template.dxf to the Documents folder.

Open the copied formula.dsg. In the Formula tab click Enabled. In the Drawing tab click View DXF.


SAMPLE FORMULA POLYLINE

Double-click a vertex point to see the formula. In the fourierSquareWavefunction function call you can change the period from 5 to any odd number.

SCRIPT EDITOR

JavaScript documents (OLJ files) and Basic documents (OLB files) store formulas and macros.


OFFLINE BASIC DOCUMENT

The JavaScript and Basic editor supports supports autocompletion (Intellisense).

To display all formulas click Full Module View in the document toolbar.

To work with most formulas you do not need to display the OLB document. For example, to create a column formula click Column in the Formula tab. The formula that you enter into the Script Edit dialog box is automatically saved to an OLB file when you save the OL file.

 

MATCHING FORMULA (OLB, OLJ) FILE NAMES

Formulas are not stored in DSG files. Instead, they are stored in Basic (OLB) or JavaScript (OLJ) files with a matching name.

For example, the OL file c:\data\sample.ol pairs with c:\data\sample.olb. OLB and OLJ files are automatically saved when a matching OL file is saved.

If you open an OL file and scripting is enabled (both Startup and Enabled are selected in the Formula tab) formulas will run automatically.

Startup is an application setting and Enabled is an OL document setting; Both must be selected for formulas to run automatically.

If an OLB file is loaded with an OL file, it is hidden by default. To display the formula, click Edit Formula (F11) in the Formula tab.

Peer scripts do not load from the Temporary Internet Files directory.

 

AUTOCOMPLETION (INTELLISENSE)

As you type, language context features activate to help you identify language and objects features. Additional context features are available by activating the right-click context menu.

 

FORMULAS AND MACROS

Formulas are functions that are called by the OL document to calculate a cell value. A formula is called with the row and column number of the cell, and returns the cell value.

You can add functions in the Functions dialog box. To display the Functions dialog box, click Functions in the Formula tab.


FUNCTIONS DIALOG BOX

Macros are functions that you call directly. After you create a function, you can assign that function to run as a macro in the Macros dialog box.

To display the Macros dialog box click Macros in the Formula tab. If the Macros button is not enabled, select Enabled in the Script pane.


MACROS DIALOG BOX

In the macros dialog box, specify an existing function in the Function drop-down list and click Add to create a macro. 

After the function is added, you can click the function name under Macros in the Formula tab. 

You can add a local macro or a global macro in the Macros dialog box. A global macros automatically loads the OLB  file that contains the macro.

All formulas are called with row and column parameters (nRow, nCol). If you call a function as a macro, the row and column values are set to (-1, -1). If can be much easier to test and debug formulas when calling them as a macros (for example: break only if nRow equals -1). The Sub button in the Formula ribbon calls the current function as a macro.

 

STARTUP AND EVENTS

The Main procedure and (Declarations) section run at startup.

To add a global variable click (Declarations) the right list box. Click Main to add a startup procedure.

Events are procedures (Sub) that are called by the application. Drawing Sync supports three events (Load, Timer, and Exit).


TIMER EVENT

To enable the timer event set App.TimerInterval to the number of milliseconds between events. A value of 1000 causes the Timer event to fire once a second. To disable the event, set App.TimerInterval to zero.

To stop Events without stopping formulas click Pause in the Formula tab. To stop both formulas and events click Stop. Sub calls the current function (for testing).

 

DEBUGGER

Script debuggers are supported.

To begin debugging, you can set a breakpoint in the Basic document or the Script Edit dialog box. You can also click Debugger in the Formula tab, and connect to the OLB document. Open Debugger does not launch a debugger if Just-In-Time debugging is disabled or not supported (Express editions do not support JIT debugging). Instead, you can launch the debugger and Attach to Process or Connect to Running Documents.


VISUAL STUDIO SCRIPT DEBUGGER

The Microsoft Script Debugger is supported, but Visual Studio is recommended.


SCRIPT DEBUGGER

If you need to clear a formula breakpoint that was set in the script editor, you can set and clear the breakpoint in the debugger. You can debug formulas, however a formula is called every time the cell displays.


Drawing Sync ©2025 Code Truck LLC. All rights reserved