> ## Documentation Index
> Fetch the complete documentation index at: https://docs.luminicad.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scripting Guide

> Create complex models using LuminiCAD scripting commands

## Introduction to Scripting

LuminiCAD's scripting interface lets you create precise models using text commands. It's especially useful for:

* Creating patterns and arrays
* Building complex shapes from simple ones
* Making parametric designs
* Automating repetitive tasks

## Using Variables

Commands can be assigned to variables for later use:

<CodeGroup>
  ```text Variables theme={null}
  base = CREATE RECTANGLE ORIGIN 0 0 0 SIZE 100 50
  CREATE PRISM SECTION $base LENGTH 200

  edge1 = CREATE LINE FROM 0 0 0 TO 100 0 0
  arc1 = CREATE ARC CENTER 100 0 0 START 100 10 0 NORMAL 0 0 1 ANGLE 90
  ```

  ```text Using Variables theme={null}
  // Create and store a base circle
  circle1 = CREATE CIRCLE CENTER 0 0 0 RADIUS 25 NORMAL 0 0 1

  // Use the stored circle to create a prism
  CREATE PRISM SECTION $circle1 LENGTH 100

  // Create a cutting tool
  cutter = CREATE CIRCLE CENTER 20 0 0 RADIUS 5 NORMAL 1 0 0
  CREATE PRISM SECTION $cutter LENGTH 60
  ```
</CodeGroup>

<Note>
  Use the \$ prefix when referencing variables in subsequent commands
</Note>

## Basic Commands

### Creating Simple Shapes

<CodeGroup>
  ```text Box theme={null}
  CREATE BOX ORIGIN x y z SIZE dx dy HEIGHT dz

  # Example
  CREATE BOX ORIGIN 0 0 0 SIZE 100 50 HEIGHT 75
  ```

  ```text Circle theme={null}
  CREATE CIRCLE CENTER x y z RADIUS r NORMAL nx ny nz

  # Example
  CREATE CIRCLE CENTER 0 0 0 RADIUS 50 NORMAL 0 0 1
  ```

  ```text Arc theme={null}
  CREATE ARC CENTER x y z START x y z NORMAL x y z ANGLE a

  # Example
  CREATE ARC CENTER 0 0 0 START 100 0 0 NORMAL 0 0 1 ANGLE 90
  ```

  ```text Line theme={null}
  CREATE LINE FROM x1 y1 z1 TO x2 y2 z2

  # Example
  CREATE LINE FROM 0 0 0 TO 100 0 0
  ```

  ```text Rectangle theme={null}
  CREATE RECTANGLE ORIGIN x y z SIZE dx dy

  # Example
  CREATE RECTANGLE ORIGIN 0 0 0 SIZE 100 50
  ```

  ```text Polygon theme={null}
  CREATE POLYGON POINTS x1 y1 z1 x2 y2 z2 ... xn yn zn

  # Example
  CREATE POLYGON POINTS 0 0 0 100 0 0 100 100 0 0 100 0
  ```
</CodeGroup>

## Advanced Operations

### Extrusion and Sweeping

<CodeGroup>
  ```text Prism theme={null}
  CREATE PRISM SECTION [section-command] LENGTH length

  # Example
  CREATE PRISM SECTION [CREATE CIRCLE CENTER 0 0 0 RADIUS 25 NORMAL 0 0 1] LENGTH 100
  ```

  ```text Revolve theme={null}
  CREATE REVOLVE PROFILE [profile-command] 
  AXIS ORIGIN x y z DIRECTION dx dy dz ANGLE angle

  # Example
  CREATE REVOLVE PROFILE [CREATE LINE FROM 10 0 0 TO 20 20 0] 
  AXIS ORIGIN 0 0 0 DIRECTION 0 0 1 ANGLE 360
  ```

  ```text Sweep theme={null}
  CREATE SWEEP PROFILE [profile-command] PATH [path-command]

  # Example
  CREATE SWEEP PROFILE [CREATE CIRCLE CENTER 0 0 0 RADIUS 10 NORMAL 1 0 0] 
  PATH [CREATE LINE FROM 0 0 0 TO 100 0 0]
  ```
</CodeGroup>

### Boolean Operations

<CodeGroup>
  ```text Fuse theme={null}
  CREATE FUSE BOTTOM [bottom-command] TOP [top-command]

  # Example
  CREATE FUSE BOTTOM [CREATE BOX ORIGIN 0 0 0 SIZE 50 50 HEIGHT 20] 
  TOP [CREATE CYLINDER CENTER 25 25 20 RADIUS 15 HEIGHT 30]
  ```

  ```text Boolean theme={null}
  CREATE BOOLEAN [COMMON|CUT|FUSE] 
  FIRST [first-shape] 
  SECOND [second-shape]

  # Example
  CREATE BOOLEAN CUT 
  FIRST [CREATE BOX ORIGIN 0 0 0 SIZE 50 50 HEIGHT 20] 
  SECOND [CREATE CYLINDER CENTER 25 25 0 RADIUS 10 HEIGHT 30]
  ```
</CodeGroup>

## Creating Complex Shapes

### Wire Creation

```text theme={null}
CREATE WIRE EDGES [edge-command] AND [edge-command]

# Example - Creating a rectangular wire
CREATE WIRE EDGES 
[CREATE LINE FROM 0 0 0 TO 100 0 0] AND
[CREATE LINE FROM 100 0 0 TO 100 100 0] AND
[CREATE LINE FROM 100 100 0 TO 0 100 0] AND
[CREATE LINE FROM 0 100 0 TO 0 0 0]
```

### Organization with Folders

```text theme={null}
CREATE FOLDER NAME "My Components"
```

## Practical Examples

### Creating a Patterned Cylinder

```text theme={null}
// Create base cylinder
CREATE CIRCLE CENTER 0 0 0 RADIUS 25 NORMAL 0 0 1
CREATE PRISM SECTION [previous-circle] LENGTH 100

// Create a single hole
CREATE CIRCLE CENTER 20 0 0 RADIUS 5 NORMAL 1 0 0
CREATE PRISM SECTION [previous-circle] LENGTH 60

// Pattern the hole around the cylinder
CREATE REVOLVE PROFILE [previous-hole] 
AXIS ORIGIN 0 0 0 DIRECTION 0 0 1 ANGLE 360
```

### Building a Flanged Connection

```text theme={null}
// Create the base flange
CREATE CIRCLE CENTER 0 0 0 RADIUS 50 NORMAL 0 0 1
CREATE PRISM SECTION [previous-circle] LENGTH 10

// Add the pipe
CREATE CIRCLE CENTER 0 0 10 RADIUS 25 NORMAL 0 0 1
CREATE PRISM SECTION [previous-circle] LENGTH 100

// Add bolt holes
CREATE CIRCLE CENTER 40 0 0 RADIUS 6 NORMAL 0 0 1
CREATE PRISM SECTION [previous-circle] LENGTH 10
CREATE REVOLVE PROFILE [previous-hole] 
AXIS ORIGIN 0 0 0 DIRECTION 0 0 1 ANGLE 360
```

<Tip>
  When creating complex models, break down your design into simple shapes first, then combine them using boolean operations.
</Tip>

## Best Practices

1. **Organization**
   * Use folders to group related components
   * Follow a consistent naming convention
   * Break complex shapes into manageable parts

2. **Efficiency**
   * Create patterns using REVOLVE or SWEEP when possible
   * Use boolean operations to combine shapes
   * Reuse common components through folders

3. **Troubleshooting**
   * Check your coordinates and measurements
   * Verify normal directions for circles and profiles
   * Ensure boolean operations have valid shapes

<Note>
  Remember that all measurements are in millimeters (mm) and angles in degrees.
</Note>
