# Document Generation Guide

## Overview

OpenBrIM's document generation system enables creation of professional engineering calculation reports, design check documents, and technical documentation. The system uses XML-based document objects that integrate seamlessly with the parametric engine (ParamML), allowing dynamic content generation based on analysis results and design parameters.

This guide explains the document generation objects, patterns, and best practices for AI agents who will create comprehensive engineering documentation.

**Key Capabilities:**

* **Dynamic Content**: Variables and expressions evaluated from parametric model
* **Conditional Rendering**: Guards control content visibility based on design conditions
* **Rich Formatting**: Tables, sections, text, equations, and visualizations
* **CAD Integration**: Embed section drawings and 3D visualizations
* **Design Code Integration**: Reference code check calculations and results
* **Unit-Aware Output**: Automatic unit conversion and formatting

## Core Concepts

### 1. Document Object Hierarchy

Documents are structured as trees of objects:

* Root document defines title and metadata
* Sections organize content hierarchically
* Content objects (tables, text, CAD, etc.) populate sections
* All objects follow OpenBrIM object model (`<O>` elements with `N`, `T` attributes)

### 2. Variable Embedding

Embed parametric expressions in document content using pipe delimiters:

**Syntax:** `|expression|`

**Example:**

```
|withunits(fc_Input,'DR_StressU','Stress',3)|
```

The expression is evaluated and the result is inserted into the document.

### 3. Conditional Content

Use `Guard` attributes to conditionally include/exclude document objects:

**Syntax:** `Guard="expression"`

**Example:**

```xml
<O T="DocSection" Title="Shear Design" Guard="DesignOpt.EQ.1">
  <!-- Content only appears if DesignOpt equals 1 -->
</O>
```

### 4. Unit Formatting

The `withunits()` function formats values with proper units:

**Syntax:** `withunits(value, unitSystemParam, unitType, precision)`

**Parameters:**

* `value`: Numeric value to format
* `unitSystemParam`: Unit system reference (e.g., 'DR\_PropU1', 'DR\_StressU')
* `unitType`: Type of unit ('Length', 'Force', 'Stress', 'Area', etc.)
* `precision`: Decimal places

**Example:**

```
|withunits(SectionPropsX.HSection,'DR_PropU1','Length',2)|
```

Result: `24.00 in` (depending on unit system)

***

## Core Document Objects

### 1. Document (Root Object)

The root document object defines the overall report structure.

**Object Type:** `Document` **Prefix:** `DOC`

#### Key Properties

| Property | Type | Description              | Default  |
| -------- | ---- | ------------------------ | -------- |
| Title    | Text | Document title           | Required |
| N        | Text | Document name/identifier | Required |
| T        | Text | Always "Document"        | Required |

#### XML Example

```xml
<O N="PileCapCodeCheckReport" T="Document" Title="Pier Footing Code Check Report">
  <!-- Child sections and content -->
  <O T="DocSection" Title="Input Variables">
    <!-- ... -->
  </O>
  <O T="DocSection" Title="Design Results">
    <!-- ... -->
  </O>
</O>
```

***

### 2. DocSection (Document Section)

Hierarchical sections organize content into logical groups.

**Object Type:** `DocSection` **Prefix:** `SEC`

#### Key Properties

| Property | Type       | Description           | Default  |
| -------- | ---------- | --------------------- | -------- |
| Title    | Text       | Section heading       | Required |
| Guard    | Expression | Conditional rendering | -        |

#### Nesting

Sections can contain subsections to create hierarchy:

```xml
<O T="DocSection" Title="Flexural Design">
  <O T="DocSection" Title="Flexural Resistance X-dir">
    <O T="DocSection" Title="Positive Moment">
      <!-- Content -->
    </O>
    <O T="DocSection" Title="Negative Moment">
      <!-- Content -->
    </O>
  </O>
</O>
```

#### XML Examples

**Simple Section:**

```xml
<O T="DocSection" Title="Material Properties">
  <O N="MaterialTable" T="DocTable">
    <!-- Table content -->
  </O>
</O>
```

**Conditional Section:**

```xml
<O T="DocSection" Title="Shear and Torsion Design" Guard="DesignOpt.EQ.1">
  <!-- Only appears if DesignOpt equals 1 -->
  <O T="DocTable">
    <!-- ... -->
  </O>
</O>
```

**Nested Sections:**

```xml
<O T="DocSection" Title="Direction-X">
  <O T="DocSection" Title="Section Properties">
    <!-- Section properties content -->
  </O>
  <O T="DocSection" Title="Material Properties">
    <!-- Material properties content -->
  </O>
</O>
```

***

### 3. DocTable (Document Table)

Tables display tabular data with rows and cells.

**Object Type:** `DocTable` **Prefix:** `TABLE`

#### Key Properties

| Property | Type       | Description           | Default  |
| -------- | ---------- | --------------------- | -------- |
| N        | Text       | Table identifier      | Optional |
| Guard    | Expression | Conditional rendering | -        |

#### Structure

Tables contain:

* `DocRow` objects (rows)
* Each row contains `DocCell` objects (cells)

#### XML Examples

**Two-Column Table with Header:**

```xml
<O N="SectionTable" T="DocTable">
  <!-- Header Row -->
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Description
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Value
    </O>
  </O>

  <!-- Data Row 1 -->
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      Thickness
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      |withunits(SectionPropsX.HSection,'DR_PropU1','Length',2)|
    </O>
  </O>

  <!-- Data Row 2 -->
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      Width
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      |withunits(SectionPropsX.WSection,'DR_PropU1','Length',2)|
    </O>
  </O>
</O>
```

**Three-Column Table (Description, Parameter, Value):**

```xml
<O N="MaterialTable" T="DocTable">
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Description
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Parameter
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Value
    </O>
  </O>

  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      Design compressive strength of concrete
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      f'<sub>c</sub>
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      |withunits(fc_Input,'DR_StressU','Stress',3)|
    </O>
  </O>

  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      Specified minimum yield strength of steel
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      f<sub>y</sub>
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      |withunits(fy_Input,'DR_StressU','Stress',3)|
    </O>
  </O>
</O>
```

***

### 4. DocRow (Table Row)

Represents a single row in a document table.

**Object Type:** `DocRow`

#### Key Properties

| Property | Type       | Description           | Default |
| -------- | ---------- | --------------------- | ------- |
| Guard    | Expression | Conditional rendering | -       |

#### XML Example

```xml
<O T="DocRow">
  <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
    Area
  </O>
  <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
    |withunits(round(SectionPropsX.AreaSection),'DR_PropU1','Area',2)|
  </O>
</O>
```

**Conditional Row:**

```xml
<O T="DocRow" Guard="UseDetailedAnalysis == 1">
  <O T="DocCell">Advanced Analysis Results</O>
  <O T="DocCell">|DetailedResult|</O>
</O>
```

***

### 5. DocCell (Table Cell)

Represents a single cell within a table row.

**Object Type:** `DocCell`

#### Key Properties

| Property | Type   | Description        | Default |
| -------- | ------ | ------------------ | ------- |
| Style    | CSS    | Inline CSS styling | -       |
| colspan  | Number | Column span        | 1       |
| rowspan  | Number | Row span           | 1       |

#### Common Style Properties

```css
text-align: center | left | right
vertical-align: top | middle | bottom
font-weight: normal | bold
font-size: 12px | 14px | 16px
height: 20px
padding: 5px
background-color: #f0f0f0
border: 1px solid #ccc
```

#### Content

Cell content can include:

* Plain text
* Embedded variables: `|expression|`
* HTML formatting: `<sub>`, `<sup>`, `<b>`, `<i>`
* Line breaks: Standard text wrapping

#### XML Examples

**Header Cell:**

```xml
<O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
  Description
</O>
```

**Data Cell with Variable:**

```xml
<O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
  |withunits(SectionPropsX.HSection,'DR_PropU1','Length',2)|
</O>
```

**Cell with Subscript/Superscript:**

```xml
<O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
  f'<sub>c</sub>
</O>
```

**Multi-line Cell:**

```xml
<O T="DocCell" Style="text-align: left; padding: 5px; vertical-align: top; font-size: 14px">
  Effective Depth
  (measured from top to centroid of tension reinforcement)
</O>
```

***

### 6. DocCADD (CAD Drawing/Visualization)

Embeds CAD drawings, section visualizations, or 3D geometry in the document.

**Object Type:** `DocCADD` **Prefix:** `CADD`

#### Key Properties

| Property | Type   | Description             | Default |
| -------- | ------ | ----------------------- | ------- |
| Width    | Number | Drawing width (pixels)  | 800     |
| Height   | Number | Drawing height (pixels) | 600     |

#### Child Elements

Contains a `<P>` element with:

* `N="CADD"`: Parameter name
* `V`: Reference to section/geometry object
* `T`: Type of visualization ("Section", "3D", etc.)

#### XML Examples

**Section Drawing:**

```xml
<O T="DocCADD" Width="1000" Height="800">
  <P N="CADD" V="pilecapSecX" T="Section" />
</O>
```

**3D Visualization:**

```xml
<O T="DocCADD" Width="1200" Height="900">
  <P N="CADD" V="BridgeGeometry" T="3D" />
</O>
```

**With Section Context:**

```xml
<O T="DocSection" Title="Section Properties">
  <O T="DocCADD" Width="1000" Height="800">
    <P N="CADD" V="pilecapSecY" T="Section" />
  </O>

  <O T="DocTable">
    <!-- Table with section properties -->
  </O>
</O>
```

***

### 7. DocDesignCode (Design Code Check Reference)

References design code check calculations and results.

**Object Type:** `DocDesignCode`

#### Key Properties

| Property | Type       | Description                      | Default  |
| -------- | ---------- | -------------------------------- | -------- |
| Obj      | String     | Reference to design check object | Required |
| Guard    | Expression | Conditional rendering            | -        |

#### XML Examples

**Simple Code Check:**

```xml
<O T="DocDesignCode" Obj="FlexuralMembersPosX.SC5_6_3_2_1" />
```

**Conditional Code Check:**

```xml
<O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_3_4" Guard="shear_procedure.EQ.0 .OR. shear_procedure.EQ.1" />
```

**Multiple Code Checks:**

```xml
<O T="DocSection" Title="Minimum Reinforcement Requirements">
  <O T="DocDesignCode" Obj="MaterialProps.SC5_4_2_6" />
  <O T="DocDesignCode" Obj="FlexuralMembersPosX.SC5_6_3_3" />
  <O T="DocDesignCode" Obj="FlexuralMembersNegX.SC5_6_3_3" />
</O>
```

**Code Check with Context:**

```xml
<O T="DocSection" Title="Nominal Shear Resistance">
  <O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_3_4" Guard="shear_procedure.EQ.0 .OR. shear_procedure.EQ.1" />
  <O T="DocDesignCode" Obj="AppendixB5Y.ResultParameters" Guard="shear_procedure.EQ.2" />
  <O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_3_3" />
  <O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_2_1_Check" />
</O>
```

***

### 8. DocRef (Document Reference)

References another document object or table from elsewhere in the model.

**Object Type:** `DocRef`

#### Key Properties

| Property | Type       | Description                  | Default  |
| -------- | ---------- | ---------------------------- | -------- |
| Obj      | String     | Reference to document object | Required |
| Guard    | Expression | Conditional rendering        | -        |

#### Use Cases

* Reuse tables defined elsewhere
* Reference results from other sections
* Include shared content across multiple documents

#### XML Examples

**Reference Table:**

```xml
<O T="DocRef" Obj="XDirConcMY_Doc.UnfactoredTable" />
```

**Reference Multiple Tables:**

```xml
<O T="DocSection" Title="My Concurrent Forces">
  <O T="DocRef" Obj="XDirConcMY_Doc.UnfactoredTable" />
  <O T="DocRef" Obj="XDirConcMY_Doc.SrvTable" />
  <O T="DocRef" Obj="XDirConcMY_Doc.StrTable" />
</O>
```

**Conditional Reference:**

```xml
<O T="DocRef" Obj="DetailedAnalysisResults.Table1" Guard="UseDetailedAnalysis.EQ.1" />
```

***

### 9. DocText (Free-Form Text)

Inserts formatted text content, including markdown.

**Object Type:** `DocText`

#### Key Properties

| Property | Type       | Description           | Default |
| -------- | ---------- | --------------------- | ------- |
| Guard    | Expression | Conditional rendering | -       |

#### Content Format

Text is defined within a `<![CDATA[...]]>` section to preserve formatting and special characters.

**Markdown Support:**

* Start with `--md` to enable markdown processing
* Supports standard markdown syntax

#### XML Examples

**Simple Text:**

```xml
<O T="DocText">
  <![CDATA[
This is a simple text paragraph in the document.
  ]]>
</O>
```

**Markdown Text:**

```xml
<O T="DocText">
  <![CDATA[
--md
## Section Heading

This is **bold** text and this is *italic* text.

- Bullet point 1
- Bullet point 2
- Bullet point 3

1. Numbered item 1
2. Numbered item 2
  ]]>
</O>
```

**Text with Context Label:**

```xml
<O T="DocText">
  <![CDATA[
--md
Concurrent forces for Maximum Moment
  ]]>
</O>
```

**Complete Example in Context:**

```xml
<O T="DocSection" Title="Transverse Reinforcement">
  <O T="DocText">
    <![CDATA[
--md
Concurrent forces for Maximum Moment
    ]]>
  </O>
  <O T="DocDesignCode" Obj="MYMaxShearTorsionX.SC5_7_3_5" Guard="IsTorsionCriticalXDir.EQ.0" />

  <O T="DocText">
    <![CDATA[
--md
Concurrent forces for Minimum Moment
    ]]>
  </O>
  <O T="DocDesignCode" Obj="MYMinShearTorsionX.SC5_7_3_5" Guard="IsTorsionCriticalXDir.EQ.0" />
</O>
```

***

### 10. DocSectionAnalysis (Section Analysis Diagram)

Generates interaction diagrams and section analysis visualizations.

**Object Type:** `DocSectionAnalysis`

#### Key Properties

| Property     | Type       | Description                         | Default  |
| ------------ | ---------- | ----------------------------------- | -------- |
| N            | Text       | Object identifier                   | Optional |
| AnalysisType | Number     | Type of analysis (0=PM, 1=MM, etc.) | 0        |
| Section      | String     | Section reference                   | Required |
| Width        | Number     | Diagram width (pixels)              | 800      |
| Height       | Number     | Diagram height (pixels)             | 600      |
| AxialForce   | Expression | Applied axial force                 | -        |
| Moment       | Expression | Applied moment                      | -        |
| Orientation  | Number     | Section orientation (degrees)       | 0        |
| PhiComp      | Number     | Compression reduction factor φ      | 0.75     |
| PhiTens      | Number     | Tension reduction factor φ          | 0.9      |
| Ecu          | Number     | Concrete ultimate strain            | 0.003    |
| Etu          | Number     | Steel ultimate strain               | 0.005    |
| Refinement   | Number     | Analysis point density              | 500      |

#### Analysis Types

* **0**: P-M interaction diagram (axial-moment)
* **1**: M-M interaction diagram (biaxial moment)
* Additional types depend on section analysis module

#### XML Examples

**P-M Interaction Diagram:**

```xml
<O N="FlexureDocPosX" T="DocSectionAnalysis"
   AnalysisType="0"
   Section="pilecapSecX"
   Width="1000"
   Height="800"
   AxialForce="N_u_inputPosx"
   Moment="M_u_inputPosx"
   Orientation="0"
   PhiComp="0.75"
   PhiTens="0.9"
   Ecu="0.003"
   Etu="0.005"
   Refinement="500" />
```

**With Section Context:**

```xml
<O T="DocSection" Title="Flexural Resistance X-dir">
  <O N="FlexureDocPosX" T="DocSectionAnalysis"
     AnalysisType="0"
     Section="pilecapSecX"
     Width="1000"
     Height="800"
     AxialForce="N_u_inputPosx"
     Moment="M_u_inputPosx"
     Orientation="0"
     PhiComp="0.75"
     PhiTens="0.9"
     Ecu="0.003"
     Etu="0.005"
     Refinement="500" />

  <O T="DocDesignCode" Obj="FlexuralMembersPosX.SC5_6_3_2_1" />
  <O T="DocDesignCode" Obj="FlexuralMembersNegX.SC5_6_3_2_1" />
</O>
```

***

## Variable Embedding and Expressions

### 1. Basic Variable Reference

**Syntax:** `|variableName|`

**Example:**

```xml
<O T="DocCell">
  |footinglength|
</O>
```

### 2. Function Calls

**Syntax:** `|functionName(arg1, arg2, ...)|`

**Examples:**

**Round Values:**

```xml
|round(SectionPropsX.AreaSection)|
```

**Unit Conversion:**

```xml
|withunits(fc_Input,'DR_StressU','Stress',3)|
```

**Nested Functions:**

```xml
|withunits(round(SectionPropsX.topReinfsAreaPos,2),'DR_PropU1','Area',2)|
```

### 3. Object Property Access

**Syntax:** `|objectName.propertyName|`

**Example:**

```xml
|SectionPropsX.HSection|
|SectionPropsX.effectivedepth|
```

### 4. Mathematical Expressions

Expressions are evaluated before display:

```xml
|SectionPropsX.HSection / 2|
|footinglength + footingwidth|
```

### 5. Common Functions

#### `withunits(value, unitSystem, unitType, precision)`

Formats value with units based on the project unit system.

**Parameters:**

* `value`: Number to format
* `unitSystem`: Unit system reference ('DR\_PropU1', 'DR\_StressU', etc.)
* `unitType`: 'Length', 'Force', 'Stress', 'Area', 'Moment', etc.
* `precision`: Decimal places

**Examples:**

```xml
|withunits(SectionPropsX.HSection,'DR_PropU1','Length',2)|
<!-- Result: "24.00 in" or "609.60 mm" depending on unit system -->

|withunits(fc_Input,'DR_StressU','Stress',3)|
<!-- Result: "4.000 ksi" or "27.579 MPa" -->

|withunits(round(SectionPropsX.AreaSection),'DR_PropU1','Area',2)|
<!-- Result: "450.00 in²" or "2903.22 cm²" -->
```

#### `round(value, decimals?)`

Rounds a number to specified decimal places.

**Examples:**

```xml
|round(SectionPropsX.botReinfsAreaPos,2)|
<!-- Result: 5.24 -->

|round(strip_widthx)|
<!-- Result: 36 (default 0 decimals) -->
```

***

## Guard Expressions

Guards control conditional rendering of document content based on design parameters.

### Syntax

```xml
<O T="ObjectType" ... Guard="expression">
  <!-- Content only appears if expression evaluates to true (non-zero) -->
</O>
```

### Comparison Operators

* `.EQ.` : Equals
* `.NE.` : Not equals
* `.GT.` : Greater than
* `.LT.` : Less than
* `.GE.` : Greater than or equal
* `.LE.` : Less than or equal
* `.AND.` : Logical AND
* `.OR.` : Logical OR

**Note:** Use `.EQ.` instead of `==` for guards in document context.

### Examples

**Simple Condition:**

```xml
<O T="DocSection" Title="Shear Design" Guard="DesignOpt.EQ.1">
  <!-- Only appears if DesignOpt equals 1 -->
</O>
```

**Multiple Conditions (OR):**

```xml
<O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_3_4"
   Guard="shear_procedure.EQ.0 .OR. shear_procedure.EQ.1" />
```

**Multiple Conditions (AND):**

```xml
<O T="DocSection" Title="Advanced Analysis"
   Guard="UseDetailedAnalysis.EQ.1 .AND. StrengthCheck.EQ.1">
  <!-- ... -->
</O>
```

**Null Check:**

```xml
<O T="DocRef" Obj="OptionalTable" Guard="OptionalData.NE.NULL">
  <!-- Only includes reference if OptionalData exists -->
</O>
```

**Numeric Comparison:**

```xml
<O T="DocRow" Guard="ShearForce.GT.0">
  <O T="DocCell">Shear Resistance</O>
  <O T="DocCell">|ShearCapacity|</O>
</O>
```

***

## Document Structure Patterns

### 1. Two-Direction Design Report

Common pattern for pier footings, columns, and biaxial elements:

```xml
<O N="DesignReport" T="Document" Title="Pier Footing Code Check Report">
  <O T="DocSection" Title="Input Variables">
    <O T="DocSection" Title="Direction-X">
      <O T="DocSection" Title="Section Properties">
        <O T="DocCADD" Width="1000" Height="800">
          <P N="CADD" V="sectionX" T="Section" />
        </O>
        <O T="DocTable">
          <!-- Section properties table -->
        </O>
      </O>
      <O T="DocSection" Title="Material Properties">
        <O T="DocTable">
          <!-- Material properties table -->
        </O>
      </O>
    </O>

    <O T="DocSection" Title="Direction-Y">
      <!-- Same structure as Direction-X -->
    </O>
  </O>

  <O T="DocSection" Title="Design Results">
    <O T="DocSection" Title="X-Direction">
      <!-- Design checks for X -->
    </O>
    <O T="DocSection" Title="Y-Direction">
      <!-- Design checks for Y -->
    </O>
  </O>
</O>
```

### 2. Load Case Results Pattern

Standard pattern for showing unfactored, service, and strength results:

```xml
<O T="DocSection" Title="Limit States">
  <O T="DocSection" Title="X-Direction">
    <O T="DocSection" Title="My Concurrent Forces">
      <O T="DocRef" Obj="XDirConcMY_Doc.UnfactoredTable" />
      <O T="DocRef" Obj="XDirConcMY_Doc.SrvTable" />
      <O T="DocRef" Obj="XDirConcMY_Doc.StrTable" />
    </O>
  </O>
</O>
```

### 3. Conditional Design Sections

Sections that appear only when specific design options are enabled:

```xml
<O T="DocSection" Title="Flexural Design">
  <O T="DocSection" Title="Flexural Resistance">
    <!-- Always appears -->
  </O>
</O>

<O T="DocSection" Title="Shear and Torsion Design" Guard="DesignOpt.EQ.1">
  <!-- Only appears if shear design is enabled -->
  <O T="DocSection" Title="One-Way Shear">
    <!-- ... -->
  </O>
  <O T="DocSection" Title="Two-Way Shear">
    <!-- ... -->
  </O>
</O>
```

### 4. Properties Table Pattern

Standard two-column table for properties:

```xml
<O T="DocTable">
  <!-- Header -->
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Description
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Value
    </O>
  </O>

  <!-- Data rows -->
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      Thickness
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      |withunits(thickness,'DR_PropU1','Length',2)|
    </O>
  </O>

  <!-- More rows... -->
</O>
```

### 5. Material Properties Table Pattern

Three-column table with description, symbol, and value:

```xml
<O T="DocTable">
  <!-- Header -->
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Description
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Parameter
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
      Value
    </O>
  </O>

  <!-- Data rows -->
  <O T="DocRow">
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      Design compressive strength of concrete
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      f'<sub>c</sub>
    </O>
    <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
      |withunits(fc_Input,'DR_StressU','Stress',3)|
    </O>
  </O>

  <!-- More material properties... -->
</O>
```

***

## Complete Document Examples

### Example 1: Simple Beam Design Report

```xml
<O N="BeamDesignReport" T="Document" Title="Steel Beam Design Check">
  <O T="DocSection" Title="Input Data">
    <O T="DocSection" Title="Section Properties">
      <O T="DocCADD" Width="800" Height="600">
        <P N="CADD" V="BeamSection" T="Section" />
      </O>

      <O T="DocTable">
        <O T="DocRow">
          <O T="DocCell" Style="text-align: center; font-weight: bold;">
            Property
          </O>
          <O T="DocCell" Style="text-align: center; font-weight: bold;">
            Value
          </O>
        </O>

        <O T="DocRow">
          <O T="DocCell" Style="text-align: center;">Depth</O>
          <O T="DocCell" Style="text-align: center;">|withunits(d,'DR_PropU1','Length',2)|</O>
        </O>

        <O T="DocRow">
          <O T="DocCell" Style="text-align: center;">Width</O>
          <O T="DocCell" Style="text-align: center;">|withunits(bf,'DR_PropU1','Length',2)|</O>
        </O>

        <O T="DocRow">
          <O T="DocCell" Style="text-align: center;">Section Modulus</O>
          <O T="DocCell" Style="text-align: center;">|withunits(Sx,'DR_PropU1','SectionModulus',2)|</O>
        </O>
      </O>
    </O>

    <O T="DocSection" Title="Material Properties">
      <O T="DocTable">
        <O T="DocRow">
          <O T="DocCell" Style="text-align: center; font-weight: bold;">Description</O>
          <O T="DocCell" Style="text-align: center; font-weight: bold;">Parameter</O>
          <O T="DocCell" Style="text-align: center; font-weight: bold;">Value</O>
        </O>

        <O T="DocRow">
          <O T="DocCell" Style="text-align: center;">Yield strength</O>
          <O T="DocCell" Style="text-align: center;">F<sub>y</sub></O>
          <O T="DocCell" Style="text-align: center;">|withunits(Fy,'DR_StressU','Stress',1)|</O>
        </O>

        <O T="DocRow">
          <O T="DocCell" Style="text-align: center;">Modulus of elasticity</O>
          <O T="DocCell" Style="text-align: center;">E</O>
          <O T="DocCell" Style="text-align: center;">|withunits(E,'DR_StressU','Stress',0)|</O>
        </O>
      </O>
    </O>
  </O>

  <O T="DocSection" Title="Design Checks">
    <O T="DocDesignCode" Obj="FlexureCheck.AISC_F2" />
    <O T="DocDesignCode" Obj="ShearCheck.AISC_G2" />
    <O T="DocDesignCode" Obj="DeflectionCheck.AISC_L3" />
  </O>
</O>
```

### Example 2: Pier Footing Report (from user example)

```xml
<O N="PileCapCodeCheckReport" T="Document" Title="Pier Footing Code Check Report">
  <O T="DocSection" Title="Input Variables">
    <O T="DocSection" Title="Direction-X">
      <O T="DocSection" Title="Section Properties">
        <O T="DocCADD" Width="1000" Height="800">
          <P N="CADD" V="pilecapSecX" T="Section" />
        </O>

        <O N="SectionTable" T="DocTable">
          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
              Description
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
              Value
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Thickness
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(SectionPropsX.HSection,'DR_PropU1','Length',2)|
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Width
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(SectionPropsX.WSection,'DR_PropU1','Length',2)|
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Area
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(round(SectionPropsX.AreaSection),'DR_PropU1','Area',2)|
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Top reinforcement Area
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(round(SectionPropsX.topReinfsAreaPos,2),'DR_PropU1','Area',2)|
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Bottom reinforcement Area
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(round(SectionPropsX.botReinfsAreaPos,2),'DR_PropU1','Area',2)|
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Effective Depth
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(round(SectionPropsX.effectivedepth,2),'DR_PropU1','Length',2)|
            </O>
          </O>
        </O>
      </O>

      <O T="DocSection" Title="Material Properties">
        <O N="MaterialTable" T="DocTable">
          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
              Description
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
              Parameter
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px">
              Value
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Design compressive strength of concrete
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              f'<sub>c</sub>
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(fc_Input,'DR_StressU','Stress',3)|
            </O>
          </O>

          <O T="DocRow">
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              Specified minimum yield strength of steel
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              f<sub>y</sub>
            </O>
            <O T="DocCell" Style="text-align: center; height: 20px; vertical-align: middle; font-size: 14px">
              |withunits(fy_Input,'DR_StressU','Stress',3)|
            </O>
          </O>
        </O>
      </O>
    </O>

    <O T="DocSection" Title="Direction-Y">
      <!-- Similar structure for Y direction -->
    </O>
  </O>

  <O T="DocSection" Title="Limit States">
    <O T="DocSection" Title="X-Direction">
      <O T="DocSection" Title="My Concurrent Forces">
        <O T="DocRef" Obj="XDirConcMY_Doc.UnfactoredTable" />
        <O T="DocRef" Obj="XDirConcMY_Doc.SrvTable" />
        <O T="DocRef" Obj="XDirConcMY_Doc.StrTable" />
      </O>
    </O>

    <O T="DocSection" Title="Y-Direction">
      <O T="DocSection" Title="My Concurrent Forces">
        <O T="DocRef" Obj="YDirConcMY_Doc.UnfactoredTable" />
        <O T="DocRef" Obj="YDirConcMY_Doc.SrvTable" />
        <O T="DocRef" Obj="YDirConcMY_Doc.StrTable" />
      </O>
    </O>
  </O>

  <O T="DocSection" Title="Flexural Design">
    <O T="DocSection" Title="Flexural Resistance X-dir">
      <O N="FlexureDocPosX" T="DocSectionAnalysis"
         AnalysisType="0"
         Section="pilecapSecX"
         Width="1000"
         Height="800"
         AxialForce="N_u_inputPosx"
         Moment="M_u_inputPosx"
         Orientation="0"
         PhiComp="0.75"
         PhiTens="0.9"
         Ecu="0.003"
         Etu="0.005"
         Refinement="500" />

      <O T="DocDesignCode" Obj="FlexuralMembersPosX.SC5_6_3_2_1" />
      <O T="DocDesignCode" Obj="FlexuralMembersNegX.SC5_6_3_2_1" />
    </O>

    <O T="DocSection" Title="Minimum Reinforcement Requirements X-dir">
      <O T="DocDesignCode" Obj="MaterialProps.SC5_4_2_6" />
      <O T="DocDesignCode" Obj="FlexuralMembersPosX.SC5_6_3_3" />
      <O T="DocDesignCode" Obj="FlexuralMembersNegX.SC5_6_3_3" />
    </O>
  </O>

  <O T="DocSection" Title="Shear and Torsion Design" Guard="DesignOpt.EQ.1">
    <O T="DocSection" Title="X-Direction">
      <O T="DocSection" Title="Fz Concurrent Forces">
        <O T="DocRef" Obj="XDirConcFZ_Doc.UnfactoredTable" />
        <O T="DocRef" Obj="XDirConcFZ_Doc.SrvTable" />
        <O T="DocRef" Obj="XDirConcFZ_Doc.StrTable" />
      </O>

      <O T="DocSection" Title="One-Way Shear">
        <O T="DocSection" Title="Nominal Shear Resistance">
          <O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_3_4"
             Guard="shear_procedure.EQ.0 .OR. shear_procedure.EQ.1" />
          <O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_3_3" />
          <O T="DocDesignCode" Obj="ShearTorsionX.SC5_7_2_1_Check" />
        </O>

        <O T="DocSection" Title="Transverse Reinforcement">
          <O T="DocText">
            <![CDATA[
--md
Concurrent forces for Maximum Moment
            ]]>
          </O>
          <O T="DocDesignCode" Obj="MYMaxShearTorsionX.SC5_7_3_5"
             Guard="IsTorsionCriticalXDir.EQ.0" />

          <O T="DocText">
            <![CDATA[
--md
Concurrent forces for Minimum Moment
            ]]>
          </O>
          <O T="DocDesignCode" Obj="MYMinShearTorsionX.SC5_7_3_5"
             Guard="IsTorsionCriticalXDir.EQ.0" />
        </O>
      </O>

      <O T="DocSection" Title="Two-Way Shear">
        <O T="DocDesignCode" Obj="TwoWayShearX.SC5_12_8_6" />
      </O>
    </O>
  </O>
</O>
```

***

## Best Practices

### 1. Consistent Table Styling

Use consistent cell styles throughout documents:

**Header Cells:**

```css
text-align: center; height: 20px; font-weight: bold; vertical-align: middle; font-size: 14px
```

**Data Cells:**

```css
text-align: center; height: 20px; vertical-align: middle; font-size: 14px
```

**Left-aligned Text Cells:**

```css
text-align: left; padding: 5px; vertical-align: top; font-size: 14px
```

### 2. Unit Formatting

Always use `withunits()` for dimensional quantities:

```xml
<!-- Good -->
|withunits(thickness,'DR_PropU1','Length',2)|

<!-- Avoid -->
|thickness| in
```

### 3. Precision Control

Use appropriate precision for different quantities:

* **Lengths**: 2 decimal places
* **Areas**: 2 decimal places
* **Stresses**: 3 decimal places
* **Forces**: 1-2 decimal places
* **Dimensionless ratios**: 3 decimal places

```xml
|withunits(length,'DR_PropU1','Length',2)|
|withunits(stress,'DR_StressU','Stress',3)|
|withunits(force,'DR_ForceU','Force',1)|
```

### 4. Section Organization

Use hierarchical sections for logical organization:

1. Input Data (geometry, materials, loads)
2. Analysis Results (forces, stresses, displacements)
3. Design Checks (code compliance verification)
4. Summary (design ratios, pass/fail status)

### 5. Guard Usage

Place guards at appropriate levels:

* **Section level**: Hide entire design sections (e.g., optional torsion design)
* **Row level**: Hide individual table rows (e.g., optional parameters)
* **Cell level**: Rarely needed, usually guard at row or section level

```xml
<!-- Section-level guard (preferred for large blocks) -->
<O T="DocSection" Title="Optional Analysis" Guard="UseAdvanced.EQ.1">
  <!-- All content hidden if condition false -->
</O>

<!-- Row-level guard (for individual table rows) -->
<O T="DocRow" Guard="ShowDetail.EQ.1">
  <O T="DocCell">Detail Parameter</O>
  <O T="DocCell">|DetailValue|</O>
</O>
```

### 6. CAD Drawing Placement

Place CAD drawings before related tables:

```xml
<O T="DocSection" Title="Section Properties">
  <!-- Drawing first -->
  <O T="DocCADD" Width="1000" Height="800">
    <P N="CADD" V="sectionGeometry" T="Section" />
  </O>

  <!-- Table second -->
  <O T="DocTable">
    <!-- Properties -->
  </O>
</O>
```

### 7. DocText for Context

Use DocText to provide context between design checks:

```xml
<O T="DocSection" Title="Load Cases">
  <O T="DocText">
    <![CDATA[
--md
The following table shows unfactored load cases:
    ]]>
  </O>
  <O T="DocRef" Obj="UnfactoredLoads.Table" />

  <O T="DocText">
    <![CDATA[
--md
The following table shows factored combinations for Strength I:
    ]]>
  </O>
  <O T="DocRef" Obj="StrengthICombinations.Table" />
</O>
```

### 8. Subscripts and Superscripts

Use HTML tags for mathematical notation:

```xml
<!-- Subscripts -->
f'<sub>c</sub>
f<sub>y</sub>
E<sub>c</sub>

<!-- Superscripts -->
10<sup>6</sup>
x<sup>2</sup>

<!-- Combined -->
σ<sub>max</sub><sup>compression</sup>
```

### 9. Error Handling in Expressions

Use conditional expressions to handle null values:

```xml
<!-- Check for null before formatting -->
|iif(value == NULL, 'N/A', withunits(value,'DR_PropU1','Length',2))|

<!-- Provide default value -->
|iif(isDefined(optionalParam), optionalParam, defaultValue)|
```

### 10. Reusable Content with DocRef

Define tables once and reference multiple times:

```xml
<!-- Define table once -->
<O N="StandardMaterialTable" T="DocTable">
  <!-- Material property rows -->
</O>

<!-- Reference in multiple documents -->
<O T="DocSection" Title="Beam Design">
  <O T="DocRef" Obj="StandardMaterialTable" />
</O>

<O T="DocSection" Title="Column Design">
  <O T="DocRef" Obj="StandardMaterialTable" />
</O>
```

***

## Advanced Patterns

### 1. Dynamic Table Generation

Generate table rows based on lists:

```xml
<!-- Assume StationList = [0, 300, 600, 900, 1200] -->
<O T="DocTable">
  <O T="DocRow">
    <O T="DocCell" Style="font-weight: bold;">Station</O>
    <O T="DocCell" Style="font-weight: bold;">Moment</O>
  </O>

  <!-- Use Repeat to generate rows -->
  <O T="Repeat" S="0" E="length(StationList)-1" I="1" CTRL="i" i="0">
    <O T="DocRow">
      <O T="DocCell">|StationList[i]|</O>
      <O T="DocCell">|MomentList[i]|</O>
    </O>
  </O>
</O>
```

### 2. Multi-Level Conditional Content

Nested guards for complex logic:

```xml
<O T="DocSection" Title="Advanced Design" Guard="UseAdvanced.EQ.1">
  <O T="DocSection" Title="Method A" Guard="Method.EQ.1">
    <!-- Content for Method A -->
  </O>

  <O T="DocSection" Title="Method B" Guard="Method.EQ.2">
    <!-- Content for Method B -->
  </O>

  <O T="DocSection" Title="Additional Checks" Guard="DetailedChecks.EQ.1">
    <!-- Additional content if detailed checks enabled -->
  </O>
</O>
```

### 3. Combined Results Tables

Single table showing multiple limit states:

```xml
<O T="DocTable">
  <O T="DocRow">
    <O T="DocCell" Style="font-weight: bold;">Limit State</O>
    <O T="DocCell" Style="font-weight: bold;">Demand</O>
    <O T="DocCell" Style="font-weight: bold;">Capacity</O>
    <O T="DocCell" Style="font-weight: bold;">Ratio</O>
  </O>

  <O T="DocRow" Guard="StrengthI.EQ.1">
    <O T="DocCell">Strength I</O>
    <O T="DocCell">|withunits(M_u_StrI,'DR_MomentU','Moment',1)|</O>
    <O T="DocCell">|withunits(M_n,'DR_MomentU','Moment',1)|</O>
    <O T="DocCell">|round(M_u_StrI/M_n,3)|</O>
  </O>

  <O T="DocRow" Guard="ServiceI.EQ.1">
    <O T="DocCell">Service I</O>
    <O T="DocCell">|withunits(M_s_SrvI,'DR_MomentU','Moment',1)|</O>
    <O T="DocCell">|withunits(M_allow,'DR_MomentU','Moment',1)|</O>
    <O T="DocCell">|round(M_s_SrvI/M_allow,3)|</O>
  </O>
</O>
```

### 4. Summary Pass/Fail Table

Design check summary with status indicators:

```xml
<O T="DocSection" Title="Design Check Summary">
  <O T="DocTable">
    <O T="DocRow">
      <O T="DocCell" Style="font-weight: bold;">Check</O>
      <O T="DocCell" Style="font-weight: bold;">Ratio</O>
      <O T="DocCell" Style="font-weight: bold;">Status</O>
    </O>

    <O T="DocRow">
      <O T="DocCell">Flexure</O>
      <O T="DocCell">|round(FlexureRatio,3)|</O>
      <O T="DocCell">|iif(FlexureRatio <= 1.0, 'PASS', 'FAIL')|</O>
    </O>

    <O T="DocRow">
      <O T="DocCell">Shear</O>
      <O T="DocCell">|round(ShearRatio,3)|</O>
      <O T="DocCell">|iif(ShearRatio <= 1.0, 'PASS', 'FAIL')|</O>
    </O>

    <O T="DocRow">
      <O T="DocCell">Deflection</O>
      <O T="DocCell">|round(DeflectionRatio,3)|</O>
      <O T="DocCell">|iif(DeflectionRatio <= 1.0, 'PASS', 'FAIL')|</O>
    </O>
  </O>
</O>
```

***

## Common Pitfalls and Solutions

### 1. Missing Variable Delimiters

**Wrong:**

```xml
<O T="DocCell">SectionPropsX.HSection</O>
```

**Correct:**

```xml
<O T="DocCell">|SectionPropsX.HSection|</O>
```

### 2. Incorrect Guard Syntax

**Wrong:**

```xml
<O T="DocSection" Guard="DesignOpt == 1">
```

**Correct:**

```xml
<O T="DocSection" Guard="DesignOpt.EQ.1">
```

### 3. Forgetting CDATA for DocText

**Wrong:**

```xml
<O T="DocText">
  This text contains <special> characters
</O>
```

**Correct:**

```xml
<O T="DocText">
  <![CDATA[
This text contains <special> characters
  ]]>
</O>
```

### 4. Inconsistent Cell Heights

**Problem:** Rows with different cell heights look unprofessional.

**Solution:** Use consistent height in all cells:

```css
height: 20px;
```

### 5. Null Value Handling

**Wrong:**

```xml
|withunits(OptionalValue,'DR_PropU1','Length',2)|
<!-- Crashes if OptionalValue is NULL -->
```

**Correct:**

```xml
|iif(OptionalValue == NULL, 'N/A', withunits(OptionalValue,'DR_PropU1','Length',2))|
```

### 6. Object Reference Syntax

**Wrong:**

```xml
<O T="DocRef" Obj="TableName" />
<!-- Missing object path -->
```

**Correct:**

```xml
<O T="DocRef" Obj="ParentObject.TableName" />
```

***

## Summary

The OpenBrIM document generation system provides comprehensive tools for creating professional engineering reports:

**Core Objects:**

* **Document**: Root object defining report structure
* **DocSection**: Hierarchical organization of content
* **DocTable**: Tabular data with rows and cells
* **DocCADD**: Embedded CAD drawings and visualizations
* **DocDesignCode**: Design code check references
* **DocRef**: Content reuse via references
* **DocText**: Free-form text and markdown
* **DocSectionAnalysis**: Interaction diagrams and section analysis

**Key Features:**

* **Variable Embedding**: `|expression|` syntax for dynamic content
* **Unit Formatting**: `withunits()` for unit-aware display
* **Conditional Rendering**: `Guard` attributes for adaptive documents
* **Rich Formatting**: HTML/CSS styling in cells, subscripts, superscripts
* **Parametric Integration**: Full access to ParamML expressions

**Best Practices:**

* Use consistent table styling throughout documents
* Always format dimensional quantities with `withunits()`
* Place guards at appropriate hierarchical levels
* Organize content logically (Input → Analysis → Design → Summary)
* Use DocText to provide context between technical sections
* Handle null values gracefully in expressions
* Reuse common content with DocRef

By following this guide, AI agents can create comprehensive, professional engineering documentation that integrates seamlessly with OpenBrIM's parametric modeling and analysis capabilities.
