This guide covers the Export object and its critical role in managing dependencies and scope when working with object instances.
Prerequisites: Read creating-instances.md first
What you'll learn:
Why Export exists and what goes in it
The Dependency Rule (critical!)
Instance scope (inside component vs in instance)
Why missing parameters = 0
What is the Export Object?
The <O T="Export"> object controls what is accessible when someone creates an instance of your component.
Purpose:
Define the public interface of your component
Hide implementation details
Control what other components can access
Basic Structure
The Dependency Rule ⚠️ CRITICAL
The most important rule when using Export:
Any parameter referenced by an exported parameter must also be exported (or be a Role="Input" parameter).
Why This Rule Exists
When you create an instance, exported parameters are copied to the instance. They lose access to non-exported parameters.
Missing parameters evaluate to 0, breaking calculations.
Component definition:
Inside the component - works fine:
In an instance - breaks:
Move all dependencies inside Export:
Now works in instances:
Instance Scope and Isolation
Understanding how scope works is critical for Export.
Two Different Contexts
Context
Can Access
Cannot Access
Inside the Component
Parameters inside Export CAN access parameters outside Export:
Exported parameters are copied and isolated:
The parameters work inside the component but fail in instances!
Why This Happens
System copies inputs and exports to instance
Exported parameters no longer have access to the original component's internal parameters
Missing parameters → evaluate to 0
Chain of Dependencies
All levels of dependency must be exported.
Wrong: Incomplete Dependency Chain
In instance:
Right: Complete Dependency Chain
In instance:
What to Put in Export
✅ Put in Export
Calculated results users need:
Analysis results:
Nested objects for external access:
Status/flags:
❌ Keep Outside Export
Geometry:
Intermediate calculations (if not needed externally):
BUT: If exported parameters reference them, they must be in Export!
Implementation details:
Complex Nested Instances
When instances contain instances, Export becomes crucial.
Example: House Using Cube
Cube component:
House component:
Instance of House:
Access nested values:
What If House_Base Wasn't Exported?
House without exporting House_Base:
Instance:
Problems:
Common Mistakes
❌ Mistake 1: Missing Simple Dependency
Instance:
Fix:
❌ Mistake 2: Partial Dependency Chain
In instance:
Fix:
❌ Mistake 3: Not Exporting Nested Object
Instance:
Fix:
❌ Mistake 4: Over-Exporting (Anti-pattern)
Problems:
❌ Exposes implementation details
✅ Better - Export only what final results depend on:
In this example:
❌ debug_flag, temp_var - NOT exported (not used by exported results)
✅ load_factor, resistance_factor, material_strength - Exported (used by capacity and demand)
✅ capacity, demand - Exported (used by utilization)
✅ utilization, passes - Exported (final results)
In this example:
❌ load_factor, resistance_factor, material_strength - NOT exported (internal only)
✅ capacity, demand - Exported (needed by utilization)
✅ utilization, passes - Exported (final results)
Debugging Export Issues
Problem: Calculation works in component but returns 0 or wrong value in instance
Diagnosis: Missing dependency
Steps:
Find the exported parameter with wrong value
Check each parameter referenced:
Does it have Role="Input"? ✅
If neither → That's the problem
Move missing dependency inside Export
Example:
Problem: Can't access nested object
Diagnosis: Nested object not in Export
Steps:
Find where nested object is defined
Check if it's inside <O T="Export">
If outside → move it inside Export
Example:
Problem: Value is infinity or NaN
Diagnosis: Division by zero - missing parameter evaluates to 0
Steps:
Find the division operation
Check if denominator is:
If neither → That's the problem
Example:
Problem: Instance seems to have old/wrong values
Diagnosis: Dependencies changed but not updated in Export
Steps:
Check if all dependencies are in Export
Verify formulas are correct
Check if intermediate values need to be exported
1. Always Export Dependencies
Rule: If parameter X references parameter Y, both must be exported (or Y must be input).
2. Test with Instances
Always create test instances:
If test fails → fix Export dependencies
3. Minimize Export Surface
Only export what's truly needed:
4. Document Exported Parameters
6. Trace Dependency Chains
When exporting calculated values, trace all dependencies:
7. Use Meaningful Export Names
Dependency Rule: Exported parameters must only reference:
Other exported parameters
Input parameters (Role="Input")
Missing Parameters = 0: Non-exported parameters evaluate to 0 in instances
Scope Isolation: Instances cannot access non-exported parameters
Test with Instances: Working inside ≠ working in instances
Export Nested Objects: For external access, nested instances must be in Export
Quick Checklist
When creating Export:
Last updated