Script Execution
Script Execution
The script execution feature allows batch execution of multiple commands, enabling automated drawing.
EXECSTR - Execute Script
Opens a script input dialog to execute user-entered command scripts.
Command name: EXECSTR
Usage
Command: EXECSTRAfter executing the command, a script input dialog pops up. Enter the script content in the dialog and click the "Execute" button to run the script.
Dialog Features
| Button | Description |
|---|---|
| Execute | Execute the entered script |
| Cancel | Cancel execution |
| Clear | Clear the editor content |
| Template | Load the default script template |
Script Syntax
Basic Format
A script consists of multiple lines, each of which can be:
- A command name
- Command parameters (coordinates, values, keywords)
- Comments (starting with
; or //, which are skipped)
Note: Empty lines and comment lines are automatically skipped during command parameter reading, and can be freely added to improve readability.
Selecting Objects
Commands that require object selection (such as MOVE, COPY, SCALE, etc.) require manually selecting objects first, then running the script. The script will operate on the pre-selected objects.
Example Script
; This is a simple script example
LINE
0,0
100,0
100,100
0,100
C
CIRCLE
50,50
30Comments
Two comment formats are supported:
; Semicolon comment
// Double slash commentComment lines are skipped and no operations are executed.
Variables
Defining Variables
Use SET statements to define variables:
SET VAR_NAME=value
SET WIDTH=100
SET HEIGHT=200
SET NAME=MyBlockUsing Variables
Use $() syntax to reference variables:
SET WIDTH=100
SET HEIGHT=50
LINE
0,0
$(WIDTH),0
LINE
$(WIDTH),0
$(WIDTH),$(HEIGHT)Built-in Variables
| Variable | Description |
|---|---|
$(PI) | Pi (3.14159...) |
$(LASTPOINT_X) | X coordinate of the last input point |
$(LASTPOINT_Y) | Y coordinate of the last input point |
$(CLAYER) | Current layer name |
$(CECOLOR) | Current color index |
$(OSMODE) | Object snap mode |
Expressions
Math Operations
Math operations can be performed within $():
SET BASE=100
LINE
0,0
$(BASE*2),$(BASE/2)
; Result: 200, 50Supported operators:
+Addition-Subtraction*Multiplication/Division()Parentheses
Math Functions
| Function | Description | Example |
|---|---|---|
SIN(angle) | Sine (degrees) | $(SIN(45)) |
COS(angle) | Cosine (degrees) | $(COS(60)) |
TAN(angle) | Tangent (degrees) | $(TAN(30)) |
SQRT(n) | Square root | $(SQRT(2)) |
ABS(n) | Absolute value | $(ABS(-5)) |
ROUND(n) | Round | $(ROUND(3.7)) |
FLOOR(n) | Floor | $(FLOOR(3.7)) |
CEIL(n) | Ceiling | $(CEIL(3.2)) |
Practical Script Examples
Draw a Rectangle
LINE
0,0
100,0
LINE
100,0
100,50
LINE
100,50
0,50
LINE
0,50
0,0Draw Three Parallel Lines
LINE
0,0
100,0
LINE
0,20
100,20
LINE
0,40
100,40Draw Concentric Circles
CIRCLE
100,100
20
CIRCLE
100,100
40
CIRCLE
100,100
60Draw Concentric Circles with a Loop
SET CX=200
SET CY=200
SET R=20
REPEAT 5
CIRCLE
$(CX),$(CY)
$(R)
SET R=$(R+20)
ENDREPEATDraw Grid Points with Loops
SET X=0
REPEAT 4
SET Y=0
REPEAT 4
CIRCLE
$(X),$(Y)
5
SET Y=$(Y+50)
ENDREPEAT
SET X=$(X+50)
ENDREPEATProgramming Interface
TypeScript Usage
import { ExecuteStrCommand } from 'vjcad';
// Create command instance
const cmd = new ExecuteStrCommand();
// Execute script string
await cmd.executeString(`
LINE
0,0
100,100
CIRCLE
50,50
30
`);Notes
- Empty line handling: Empty lines act as pressing Enter, used to end the current command
- Case sensitivity: Command names are case-insensitive, variable names are case-insensitive
- Coordinate format: Use
x,yformat, avoid extra spaces - Line-by-line execution: The script is parsed line by line and executed sequentially
Next Steps
- Code Execution - Write automation code using JavaScript
- Command Reference - View all available commands
- Drawing Commands - Detailed drawing command descriptions
- Command Basics - Learn command system basics
See Also
Three-Tier Automation Capability Comparison
| Tier | Command | Target Users | Capability Scope |
|---|---|---|---|
| Script Execution | EXECSTR | Users without JS knowledge | Command sequences, variables, loops |
| Code Execution | EXECJS | Users with JS knowledge | Async JS code, access to Engine API |
| Plugin System | PLUGINS | Professional developers | Full lifecycle, UI extensions, packaging & publishing |