# Logic Blocks: Complete Beginner's Guide

### Introduction

Logic Blocks are one of the most powerful automation features in Dietrich's timber construction software. They allow you to create reusable, parametric components that combine multiple elements into a single unit.

This guide will take you from basic concepts through practical applications, following a structured learning path designed for beginners.

***

### What are Logic Blocks?

#### Definition

A **Logic Block** is a combination of components, machining processes, drawing elements, dimensions, and labels that work together as a single unit. Think of it as a "smart component" that can adapt to different situations based on parameters you define.

#### What Logic Blocks Combine

Logic Blocks can include:

* **3D Volumes and Objects** - Beams, plates, library components
* **Machine Processes** - Drillings, notches, cuts, custom tool paths
* **Drawing Elements** - Lines, shapes, dimensions
* **Text and Labels** - Annotations, part information
* **Smart Tags** - Pre-defined processing operations

#### Key Characteristics

Logic Blocks are:

* **Re-calculable** - Update automatically when conditions change
* **Editable** - Modify parameters after insertion using function 7-9-4
* **Movable and Rotatable** - Reposition as needed
* **Deletable** - Remove as a complete unit
* **Disbandable** - Break apart if needed (though this removes the smart functionality)

***

### Why Use Logic Blocks?

#### Primary Benefits

1. **Save Time** - Automate repetitive tasks that would take hours manually
2. **Ensure Consistency** - Same parameters = same results every time
3. **Reduce Errors** - Calculations are handled automatically
4. **Increase Flexibility** - Easily adapt designs with variable inputs
5. **Improve Productivity** - Focus on design decisions, not repetitive modeling

#### Real-World Applications

* **Window and door assemblies** with automatic framing
* **Connector systems** (screws, bolts, metal plates) with automatic distribution
* **Bracing elements** positioned and processed automatically
* **Drilling patterns** with calculated spacing
* **Custom joinery** with parametric dimensions

#### Time Savings Example

Manual process for adding 50 evenly-spaced drillings to a plate:

* Measure total length
* Calculate spacing
* Mark each position
* Insert each drilling individually
* **Time: 15-20 minutes**

With a Logic Block:

* Click start and end point
* Set diameter and maximum spacing
* **Time: 30 seconds**

***

### Logic Block Components and Files

#### File Structure

Every Logic Block consists of multiple file types working together:

**Primary File Types**

| File Type        | Extension            | Purpose                                     |
| ---------------- | -------------------- | ------------------------------------------- |
| Logic Block File | `.ksz`               | Main logic block definition                 |
| Object Library   | `.gbi`               | 3D components referenced by the logic block |
| Smart Tag File   | `.psl`               | Pre-defined process operations              |
| Drawing Sections | `.btz`               | 2D drawing elements                         |
| Picture Files    | `.jpg`, `.png`, etc. | Help images and icons                       |

#### File Organization

Logic Blocks are stored in a hierarchical folder structure:

```
%DHPKOL% (System Logic Blocks Directory)
├── Windows/
│   ├── Rectangular/
│   │   ├── window_single_sash.ksz
│   │   ├── window_objects.gbi
│   │   └── help_image.jpg
│   └── Slanting/
├── Construction/
├── Custom/ (User Logic Blocks)
└── ...
```

**Important**: When copying logic blocks, use the Mouse-Right functions to copy all linked data files together.

***

### Logic Block Types

Logic Blocks are classified by **type**, which determines where and how they can be used.

#### Available Types

**1. In Plan View**

* **Modules**: Floor plan, Floor decks, Floor design, Roof calculation, Roof design
* **Use**: Insert elements visible in top-down view
* **Examples**: Foundation layout, framing plans

**2. In Wall**

* **Modules**: Floor plan, Wall design
* **Use**: Insert elements into wall elevation
* **Examples**: Bracing, backing blocks, electrical boxes

**3. Insert in Wall Design**

* **Modules**: Wall design only
* **Use**: More specialized wall-based operations
* **Examples**: Complex connections, custom details

**4. For Windows/Doors**

* **Modules**: Window and door input dialogs
* **Use**: Automatically execute when placing openings
* **Examples**: Frame extensions, sill details, slots in bottom plates

**5. Insert in Roof Surface**

* **Modules**: Roof calculation, Roof design
* **Use**: Elements that attach to roof planes
* **Examples**: Dormer details, roof penetrations

**6. Insert in Truss**

* **Modules**: Truss design, Floor plan, Roof calculation/design
* **Use**: Truss-specific elements
* **Examples**: Web bracing, heel details

**7. Insert in Truss Design**

* **Modules**: Truss design
* **Use**: Detailed truss modifications
* **Examples**: Custom connections, reinforcement

**8. At Points, Objects**

* **Modules**: D-CAM, Wall design, Floor design, Roof design, Truss design
* **Use**: Maximum flexibility - insert anywhere by selecting points or objects
* **Examples**: Drilling patterns, connector hardware, custom processes

***

### Understanding Coordinate Systems

Coordinate systems are fundamental to how Logic Blocks work. Understanding them is crucial for creating and using logic blocks effectively.

#### Two Key Coordinate Systems

**1. Basic Coordinate System (Basic CS)**

* **Determined by**: Logic block type and program module
* **Purpose**: Defines the initial reference frame
* **Example**: In wall design, the Basic CS is aligned with the wall face

**2. Insertion Coordinate System (Insertion CS)**

* **Defined in**: The Basic CS (not the Global CS!)
* **How it's defined**:
  * Using a positioning point and height origin, OR
  * Using three points (coordinates can come from calculations, variables, or user prompts)
* **Purpose**: All further definitions inside the logic block refer to this coordinate system

#### Key Principle

**All coordinates, positions, and orientations within a logic block are relative to the Insertion CS, not the global building coordinate system.**

This is what makes logic blocks portable and reusable - they work the same way regardless of where in the building they're inserted.

#### Coordinate System Visualization

```
Global Building CS
    └── Basic CS (determined by logic block type)
        └── Insertion CS (defined within logic block)
            └── All logic block elements positioned here
```

***

### Variables in Logic Blocks

Variables are what make logic blocks parametric and flexible. They store values that control dimensions, quantities, positions, and behavior.

***

### Calculations in Logic Blocks

Calculations are where the "logic" in Logic Blocks really comes to life. They perform mathematical operations, string manipulations, and conditional logic.

#### Debugging Calculations

When a logic block doesn't work as expected:

1. Check the **Control File** at `%DHPTMP%/KOLVariablen.log`
2. This file lists all variables and calculations when the logic block is used
3. Look for variables with value `0` or empty results - that's where the error is
4. Common issues:
   * Division by zero
   * Using undefined variables
   * Incorrect formula syntax

***

### Using Existing Logic Blocks

Before creating new logic blocks, explore what's already available. Dietrich's provides hundreds of pre-built logic blocks.

#### Finding Logic Blocks

**System Logic Blocks**

Located in: `%DHPKOL%` (Program installation directory)

Main categories:

* Windows (Rectangular, Slanting, Pointed)
* Doors (Interior, Exterior, with fixed elements)
* Construction (Connectors, brackets, hold-downs)
* Processes (Drilling patterns, notches, slots)

**Inserting Logic Blocks**

**General Method** (Function 7-8-1):

1. Open the appropriate module (Wall design, Roof design, etc.)
2. Navigate to function 7-8-1 "Insert logic blocks at points, objects"
3. Browse to select the logic block
4. Follow the prompts (click points, select objects, enter variables)
5. Confirm insertion

**For Windows/Doors**:

* Logic blocks execute automatically when placing windows or doors
* Access additional logic blocks through "Further logic blocks" option in window/door dialog

#### Modifying Inserted Logic Blocks

**Function 7-9-4: Re-position Logic Blocks**

Use this to:

* Change variable values
* Adjust positioning
* Switch to a different logic block while keeping inputs
* Update calculations

**Process**:

1. Function 7-9-4
2. Select the inserted logic block
3. Dialog opens with current settings
4. Modify as needed
5. Confirm to recalculate

#### Re-reading Logic Blocks

**Function 7-9-8: Read again and calculate**

When a logic block definition is updated (new version), use this function to update all instances in your project:

1. Function 7-9-8
2. Select which logic blocks to update
3. System reads new definitions
4. Variable values are preserved
5. Logic blocks recalculate with new logic

**Requirements**:

* Logic block must still be in same directory
* File name must match exactly
* Type must be the same
* Number of prompt points/objects must match

***

### Advanced Logic Block Features

Once you're comfortable with basics, these advanced features provide even more power.

#### Conditions

Conditions control whether elements are created or how they behave.

**Syntax**: `Variable = Value` or `Variable <> Value`

**Comparison Operators**:

* `=` Equal to
* `<>` Not equal to
* `<` Less than
* `>` Greater than
* `<=` Less than or equal
* `>=` Greater than or equal

**Examples**:

```
VSink = Yes          (Show element only when VSink variable equals "Yes")
VQuantity > 5        (Only if quantity is more than 5)
Lp0 >= 0.200         (Only if slice thickness is 200mm or more)
```

**Applying Conditions**:

* Objects: Condition determines if object is created
* Processes: Condition determines if process is applied
* Smart Tags: Condition determines if tag is executed

#### Component Definition

Turn a logic block into a **Component** for:

* Separate part drawings
* Dedicated part lists
* Assembly documentation
* Shop drawings

**Settings**:

* "Create component": Yes
* Prefix: e.g., "BR" for Brace
* Component number: Automatic or manual
* Coordinate system: Define with three points (0/0/0, 1/0/0, 0/1/0)
* Views: Select which views to show in component drawings

#### Distribution with Tilde (\~)

The tilde symbol `~` creates distributions (arrays) of elements.

**Syntax**: `Origin~Spacing~Quantity`

**Example** - Drilling Distribution:

```
X-offset: 0.100~0.150~8
```

This creates 8 drillings starting at 0.100m with 0.150m spacing.

**Use Cases**:

* Evenly spaced drillings
* Connector patterns
* Stud layouts
* Fastener arrays

#### Smart Tags

Smart Tags are pre-defined process operations that can be applied to objects.

**Common Smart Tags**:

* Perpendicular drilling (lateral position from axis)
* Notches and cuts
* Birds mouth connections
* Custom tool paths
* Connection hardware

**Advantages**:

* Proven, tested operations
* Consistent results
* Easy to apply
* Can be conditional

**Location**: `%DHPKAL%` directory, organized by process type

#### Affected Objects

When using Smart Tags or processes, specify which objects are affected:

**Filter Options**:

* Prompt object (selected by user)
* Beam types (by item number patterns)
* Slices (by layer)
* Distance criteria
* Current element only

**Example Filters**:

* "Beam type 621/623" (bottom/top plates)
* "Distance 0.01m" (within 10mm)
* "Current Wall" (only this wall)

***

### Practical Examples

#### Example 1: Drilling Pattern with Maximum Spacing

**Objective**: Create evenly-spaced drillings along a beam where you specify the maximum spacing, and the logic block calculates the exact spacing to fit evenly.

**User Inputs**:

* Two points (start and end)
* Prompt object (beam to drill)
* Maximum distance (VDistMax)
* Diameter (VDia)
* Reference side (VRS)
* Edge distances (VX1, VX3)

**Key Calculations**:

```
# Calculate total span
VSpan = DistanceBetweenPoints - VX1 - VX3

# Calculate number of spacings needed
VNumSpaces = ROUND(VSpan / VDistMax)

# Calculate actual spacing
VDist = VSpan / VNumSpaces

# Calculate number of drillings
VNumber = VNumSpaces + 1

# Calculate first drilling position
VX2 = VX1
```

**Smart Tag Application**:

First Drilling:

* X-offset: `VX1`
* Affected objects: Prompt object K1

Intermediate Drillings (using distribution):

* X-offset: `VX2~VDist~VNumber-2`
* Affected objects: Prompt object K1

Last Drilling:

* X-offset: `VX3` (from end)
* Affected objects: Prompt object K1

#### Example 2: Window Bottom Plate Slots

**Objective**: Automatically create saw slots in the bottom plate within door openings for later removal on site.

**Logic Block Type**: For windows/doors

**Configuration**:

**Info Settings**:

* Object mode: All
* Opening type: All
* Shape: All
* Refresh after construction: Yes

**Insertion**:

* Slice: 0
* Reference Edge: Bottom edge of opening
* Insert at opening side: Left

**Smart Tags** (slots):

* X-offset: 0 (left side)
* X-offset: OB-0.01 (right side, using Opening Width system variable)
* Y-offset: 0
* Z-offset: 0
* Affected objects:
  * Beam types 621/623 (bottom plates)
  * Current wall
  * Distance 0.01m

**Result**: When you place a door, two slots automatically appear at the edges of the bottom plate.

#### Example 3: X-Fix Connector Distribution

**Objective**: Automatically distribute X-Fix connectors along component joints based on specified spacing rules.

**User Inputs**:

* Two points (defining the connection line)
* Edge distances (start and end)
* Maximum field spacing
* Connector depth

**Process**:

1. Logic block calculates total connection length
2. Determines number of connectors needed based on max spacing
3. Calculates actual equal spacing
4. Creates tool paths for connector recesses
5. Automatically detects orientation and affected objects

**Key Feature**: Uses the new **Tool Paths** technology for flexible, machine-compatible processing.

***

### Logic Block Organization and Management

#### Directory Structure

**System Logic Blocks**: `%DHPKOL%`

* Provided by Dietrich's
* Updated with software versions
* Organized by function (Windows, Construction, etc.)
* **Do not modify** - copy to user directory instead

**User Logic Blocks**: `%DHPKOL%\Custom` or separate user directory

* Your custom logic blocks
* Company-specific elements
* Modified versions of system blocks
* Project-specific blocks

#### File Management Best Practices

1. **Create a Clear Hierarchy**

   ```
   User_Logic_Blocks/
   ├── Company_Standard/
   │   ├── Connections/
   │   ├── Details/
   │   └── Processes/
   ├── Project_Specific/
   └── Development/
   ```
2. **Use Descriptive Names**
   * `Brace_Diagonal_TBeam_Rod.ksz` ✓
   * `LB001.ksz` ✗
3. **Keep Libraries Organized**
   * Store library files (.gbi) with related logic blocks
   * Use meaningful library position numbers
   * Document what's stored at each position
4. **Version Control**
   * Add version numbers or dates to file names when creating variations
   * Keep a changelog for complex logic blocks
   * Test thoroughly before replacing production versions

#### Copying Logic Blocks

**Important**: Always use the mouse-right functions to copy logic blocks:

1. Right-click on a logic block in the file browser
2. Select "Copy with linked data"
3. Navigate to destination
4. Paste

This ensures all related files (.gbi, .psl, .btz, images) are copied together.

***

#### Getting Help

**When Logic Blocks Don't Work**:

1. **Check the Control File**
   * Location: `%DHPTMP%/KOLVariablen.log`
   * Shows all variables and calculations
   * Identifies where calculations failed (results = 0)
2. **Verify File Locations**
   * Are all linked files (.gbi, .psl) in the correct location?
   * Do file paths in the logic block match actual locations?
3. **Check Variable Names**
   * Are all variables used in calculations defined?
   * Are variable names spelled correctly?
4. **Test Incrementally**
   * Start with minimum elements
   * Add complexity gradually
   * Test after each addition
5. **Review Conditions**
   * Are conditions preventing elements from appearing?
   * Try temporarily removing conditions to isolate issues

***

### Logic Block Best Practices

#### Design Philosophy

1. **Start Simple**
   * Get basic functionality working first
   * Add features incrementally
   * Test thoroughly at each stage
2. **Think About the User**
   * Minimize required inputs
   * Use sensible default values
   * Provide clear help images
   * Write descriptive variable names
3. **Calculate Once, Use Everywhere**
   * Perform calculations in one place
   * Reference calculated values throughout
   * Don't repeat complex formulas
4. **Plan for Flexibility**
   * Use variables instead of hard-coded values
   * Add conditions for different scenarios
   * Design for multiple use cases

#### Performance Considerations

**Speed Optimization** (from V21.02+ updates):

* Logic blocks with referenced query bodies and smart tags execute up to 30% faster
* Component selection organization improved for instant function starts
* Large projects with many logic blocks benefit most

**Memory Optimization** (from V22.01+ updates):

* New Do-Undo strategy reduces memory requirements enormously
* Especially beneficial for projects with many logic blocks
* Allows more Do-Undo steps
* Reduces delays in function calls

**Best Practices for Speed**:

* Use conditions to prevent unnecessary calculations
* Minimize complex formulas where possible
* Reference system variables efficiently
* Avoid redundant object creation

#### Testing and Validation

**Before Deploying**:

1. **Test Edge Cases**
   * Minimum and maximum values
   * Zero values where applicable
   * Negative numbers (if relevant)
   * Very large/small dimensions
2. **Test in Different Contexts**
   * Various wall thicknesses
   * Different module combinations
   * With different system settings
3. **Verify Outputs**
   * Check single beam information
   * Review material lists
   * Inspect machine files
   * Generate drawings
4. **User Testing**
   * Have colleagues test before wide release
   * Collect feedback on usability
   * Document common questions

***

### Troubleshooting Common Issues

#### Issue: Logic Block Won't Insert

**Possible Causes**:

1. **Wrong Module** - Logic block type doesn't match current module
   * Solution: Check type in logic block info, use correct module
2. **Missing Files** - Linked .gbi or .psl files not found
   * Solution: Check file paths, copy missing files to correct location
3. **Incompatible Settings** - System settings conflict with logic block
   * Solution: Review logic block requirements, adjust settings

#### Issue: Elements Appear in Wrong Location

**Possible Causes**:

1. **Coordinate System Confusion** - Using global instead of insertion CS
   * Solution: Review coordinate system definitions, use relative coordinates
2. **Incorrect Slice** - Element inserted in wrong layer
   * Solution: Verify slice settings in object definitions
3. **Missing Offset Calculations** - Positions not adjusted for slice thickness
   * Solution: Add Lp0/2 or similar offsets where needed

#### Issue: Calculations Return Zero

**Possible Causes**:

1. **Undefined Variables** - Using variable before it's defined
   * Solution: Check calculation order, define variables before use
2. **Division by Zero** - Calculation attempts to divide by zero
   * Solution: Add conditional checks, ensure divisor is never zero
3. **Incorrect Syntax** - Formula has syntax errors
   * Solution: Review formula carefully, check parentheses, operators
4. **Failed Condition** - Condition in calculation evaluated to false
   * Solution: Check calculation conditions, verify they can be met

**Debugging Tool**: Always check `%DHPTMP%/KOLVariablen.log` to see exactly what happened.

#### Issue: Objects Overlap or Interfere

**Possible Causes**:

1. **Incorrect Dimensions** - Objects sized wrong for space
   * Solution: Review dimension calculations, test with different inputs
2. **Position Conflicts** - Multiple objects placed at same location
   * Solution: Review position calculations, add offset variables
3. **Missing Processes** - Objects should have notches/cuts but don't
   * Solution: Verify smart tag application, check affected objects filter

#### Issue: Logic Block Slows Down Project

**Possible Causes**:

1. **Too Many Instances** - Hundreds of copies of complex logic block
   * Solution: Simplify logic block, remove unnecessary elements
2. **Complex Calculations** - Heavy formulas executed repeatedly
   * Solution: Optimize calculations, cache intermediate results
3. **Excessive Smart Tags** - Too many process operations
   * Solution: Combine operations where possible, use conditions to limit execution

***

### Conclusion

Logic Blocks are a powerful tool for automation in Dietrich's software. They:

* **Save significant time** on repetitive tasks
* **Ensure consistency** across projects
* **Reduce errors** through automation
* **Enable flexibility** with parametric design
* **Scale with your needs** from simple to complex

#### Next Steps

1. **Practice with existing logic blocks** - Build familiarity with how they work
2. **Start simple** - Create basic logic blocks before attempting complex ones
3. **Learn incrementally** - Follow the learning path outlined in this guide
4. **Experiment freely** - Test ideas in practice projects
5. **Seek help when needed** - Use documentation, forums, and colleagues
6. **Share your knowledge** - Help others learn as you progress

#### Remember

The best way to learn logic blocks is through hands-on practice. Start with the examples in this guide, experiment with variations, and gradually build complexity as your understanding grows.

***

**Document Version**: 1.0\
**Last Updated**: November 2024\
**Based on**: Dietrich's Software V23.01 and earlier versions

For the most current information, always refer to the official Dietrich's documentation and update notes at docs.dietrichs.com.
