Tool for building a better world.
Introduction
.1. PIComposer Store: Store Management API
.1.1. Introduction
The Store Management API provides a comprehensive interface for managing projects and their metadata within the Blockly-based development environment. This API enables developers to perform essential CRUD (Create, Read, Update, Delete) operations on projects, manage project information, handle backups, and interact with template systems. The API is exposed through Blockly blocks that generate corresponding Dart code, allowing visual programming while maintaining type safety and proper data management patterns.
The store acts as a centralized repository for all project-related data, supporting operations such as project creation, retrieval, deletion, and metadata management. Each project contains both its core data and associated metadata (project info), which includes identifiers, descriptive information, creator details, and timestamps. The API also provides functionality for backup restoration and template management, making it suitable for applications requiring robust project lifecycle management.
.1.2. Usage Notes and Best Practices
Project Lifecycle Management
-
Project Creation: Use
store_create_projectto create new projects with descriptive names and descriptions. The returnedPIProjectobject contains the loaded project database. -
Project Retrieval:
store_get_projectautomatically loads the project database upon retrieval, eliminating the need for separate initialization calls. -
Project Deletion: Both single-project (
store_delete_project) and bulk deletion (store_delete_projects) operations are available. Use caution with bulk deletion as it’s irreversible.
Project Information vs. Project Data
-
Project Information (ProjectInfo): Contains metadata about projects accessible via
store_get_project_infoandstore_get_project_infos. -
Project Data (PIProject): Contains the actual project content and database, accessed via
store_get_project. -
These are separate entities; modifying project info does not affect project data and vice versa.
Type Safety Considerations
-
The
store_project_info_setterblock enforces type matching between input values and field types. Ensure string values for string fields and numeric values for numeric fields. -
Store blocks use strict type checking (
setCheck()methods) to prevent runtime errors.
Null Store Handling
-
Use
store_create_null_storefor initialization or when a store reference is required but no actual store exists. -
Check store validity with
store_is_nullbefore performing operations to avoid null reference errors. -
The
store_get_storefunction typically returns the active store for the current execution context.
Template System Integration
-
The template manager (
store_get_template_manager) provides access to project templates, enabling template-based project creation and management. -
Template operations are separate from project operations and may require additional permissions or context.
Backup and Restoration
-
Backup restoration requires both project ID and backup ID, indicating a robust backup management system.
-
The restore function returns a boolean success indicator; implement appropriate error handling based on this return value.
-
Backup operations typically create immutable copies, while restoration creates new project instances from backup data.
Performance Considerations
-
store_get_project_infosreturns all project metadata at once; for large project collections, consider implementing pagination or filtering at the application level. -
Project count retrieval (
store_get_project_count) is a lightweight operation suitable for UI updates and conditional logic. -
Database loading occurs automatically with
store_get_project, which may have performance implications for large projects.
Error Handling Patterns
-
Most functions return null or empty values for non-existent entities rather than throwing exceptions.
-
Check return values before using project objects to handle "not found" scenarios gracefully.
-
Implement try-catch blocks around store operations in the generated Dart code for production applications.
This API provides a comprehensive foundation for building applications with complex project management requirements, supporting everything from simple project tracking to advanced template-based workflows and backup systems.
.1.3. Block Reference
| Section | Block | Generated Function | Description |
|---|---|---|---|
Project Operations |
|
delete the project with the given id, returns true if success. Delete is not allow if a project has any backup. |
|
Project Operations |
|
delete projects in data store. Return the deleted count. Any project with backup will not be deleted. |
|
Project Operations |
|
Creates a new project with the specified name and description, returning the created project object. |
|
Project Operations |
|
Retrieves a project from the store by its ID, automatically loading its database. Returns null if the project doesn’t exist. |
|
Project Information |
|
Retrieves metadata information about a specific project. |
|
Project Information |
|
Gets metadata information for all projects in the store as an array. |
|
Project Information |
Dynamic field access
|
Accesses specific fields from a project info object using dropdown selection. |
|
Store Management |
|
Creates a null or empty store instance, typically used for initialization, testing, or as a default value. |
|
Store Management |
|
Checks whether a store instance is null or uninitialized. |
|
Store Management |
|
Retrieves the main or default store instance for the current context. |
|
Template Management |
|
Gets the template manager associated with the store for template-related operations. |
|
Backup Management |
|
Restores a project from a backup using both the project ID and backup ID. Returns boolean indicating success. |
|
Utility Functions |
|
Returns the total number of projects currently stored. |
.2. Template Management API Documentation
.2.1. Introduction
The Template Management API provides a comprehensive system for creating, managing, and instantiating templates within the Blockly-based development environment. This API enables developers to work with reusable template components across different schema standards (AP203, AP210, AP214, AP242, CIS2, IFC4x3) and template types, including entity templates, procedural templates, transform templates, and various specialized template categories.
Templates serve as reusable blueprints for creating instances in models, supporting a wide range of applications from simple entity definitions to complex procedural models and transformations. The API provides full lifecycle management including template creation, storage, retrieval, filtering, and file-based import/export operations. Each template is associated with a TemplateInstanceHandle that provides access to template metadata and properties.
.2.2. Usage Notes and Best Practices
Template Types and Schemas
-
Supported Template Types: The system supports 11 template types including user-defined enums, spatial templates, property/quantity sets, entity templates, procedural entities/models, transform templates, and timer/generic procedures.
-
Schema Standards: Templates can be associated with industry standards including AP203, AP210, AP214, AP242, CIS2, and IFC4x3 schemas.
-
Type Conversion: Note that
getTemplatesByType()andgetTemplatesByTag()automatically call.toTypeId()on the input values, requiring proper type ID formatting.
Template Lifecycle Management
-
Creation: Templates can be created either from scratch using
createTemplate()with a type specification, or from existing instances usingcreateTemplateTransform(). -
Storage: Use
saveTemplate()to persist templates to the database. Each template receives a uniqueTemplateInstanceHandle. -
Retrieval: Templates can be retrieved individually by handle or filtered by various criteria (type, tag, schema).
-
Deletion: Templates are deleted by their handle using
deleteTemplate().
Template Instantiation
-
Instantiation Process: Use
instantiate()on a template instance to create actual instances within a model. -
Result Access: After instantiation, use
getInstantiatedRootInstance()andgetInstantiatedItems()to access the created instances. -
Model Requirements: Instantiation requires a valid model context (
PIModel,PIIfcModel, orPISTPModel).
File-Based Operations
-
Export:
saveTemplatesToFile()allows exporting template collections to external files for backup or sharing. -
Import/Export: Two import methods are available -
loadTemplatesFromFile()(returns array) andimportTemplatesFromFile()(imports into system). -
File Format: The file operations imply a structured template serialization format, though the specific format is not detailed in the API.
Procedure Templates
-
Procedure Functions: Specialized templates (procedural entities, model procedures, transform functions) have associated procedure functions.
-
Function Retrieval:
getProcedureForTemplatedynamically calls the appropriate procedure function based on template type. -
Null Handling: Returns null if the template doesn’t exist, requiring null-checking in calling code.
Filtering and Searching
-
Combined Filters: Use
getTemplatesByTagSchema()for precise filtering by both tag and schema. -
Schema-Based:
getTemplatesBySchema()retrieves all templates for a specific industry standard. -
Type-Based:
getTemplatesByType()filters by template type category. -
Performance: For large template collections, consider using specific filters rather than retrieving all templates.
Error Handling and Validation
-
Input Validation: Most functions check for valid input lengths before generating code, returning empty strings for invalid inputs.
-
Type Safety: The blocks enforce type checking through
setCheck()methods on inputs. -
Null Returns: Functions that retrieve data return empty results rather than throwing exceptions for missing entities.
Template Instance Handles
-
Handle Properties: Access template metadata through
.instanceId,.typeId, and.schemaproperties on TemplateInstanceHandle objects. -
Handle Lifetime: Template handles remain valid as long as the template exists in the system.
-
Handle Usage: Use handles for all template operations except initial creation.
Integration with Store API
-
Template Manager Retrieval: Templates are managed through a PITemplateManager, which is typically retrieved via
store_get_template_managerfrom the Store API. -
System Integration: Templates are stored within the project/store system, ensuring persistence across sessions.
This API provides a robust foundation for template-driven development, enabling reusable component creation across multiple industry standards and application domains.
.2.3. Block Reference
| Section | Block | Generated Function | Description |
|---|---|---|---|
Template Access |
Dynamic property access
|
Access template instance handle properties including instance ID, type ID, and schema information. |
|
Template Handle |
|
Create a template handle from json( |
|
Template Handle |
|
get template handle from template. |
|
Template Creation |
|
Create a new template of the specified type using the template manager. |
|
Template Creation |
|
Create an entity template from an existing instance within a model. |
|
Template Persistence |
|
Save a template to the database using the template manager. |
|
Template Persistence |
|
Delete a template from the database using its handle. |
|
Template Retrieval |
|
Retrieve a template from the database using its handle. |
|
Template Filtering |
|
Retrieve templates filtered by both tag and schema type. |
|
Template Filtering |
|
Retrieve templates filtered by schema type only. |
|
Template Filtering |
|
Retrieve templates filtered by type and schema. |
|
Template Filtering |
|
Retrieve templates filtered by type only. |
|
Template Filtering |
|
Retrieve templates filtered by tag only. |
|
Template Listing |
|
List all template handles available in the system. |
|
Template Listing |
|
List all template objects available in the system. |
|
Procedure Management |
Dynamic procedure function call |
Get the procedure function for a template by ID, returns the template procedure function. |
|
Template Instantiation |
|
Instantiate an instance template and save it in the specified model. |
|
Instantiation Results |
|
Get the root instance created when instantiating a template. |
|
Instantiation Results |
|
Get all instantiated instances for a template (first item is root if present). |
|
File Operations |
|
Save a collection of templates to an external file. |
|
File Operations |
|
Load templates from an external file (returns array). |
|
File Operations |
|
Import templates from an external file into the system. |
1. Schema Management API Documentation
1.1. Introduction
The Schema Management API provides access to industry-standard schema definitions and their structural metadata within the Blockly-based development environment. This API enables developers to work with standardized schema systems including AP203, AP210, AP214, AP238, AP242, CIS2, and IFC4x3, which are commonly used in CAD, engineering, and building information modeling (BIM) applications.
The API focuses on schema introspection and descriptor retrieval, allowing programs to dynamically query entity definitions, attribute structures, enumerated types, select types, and defined types. Each schema provides a rich type system with descriptors that expose metadata about entities, their attributes, inheritance hierarchies, and type characteristics. This enables type-safe operations, validation, and dynamic entity creation based on schema definitions.
2. Usage Notes and Best Practices
2.1. Schema Standards Support
-
Supported Schemas: The system supports major industry standards including STEP AP203, AP210, AP214, AP238, AP242, CIS2, and IFC4x3.
-
Schema Enumeration: Use
SupportedSchemaenum values (e.g.,SupportedSchema.ap203,SupportedSchema.ifc4x3) to reference specific schemas. -
Schema Objects: Each schema (
PISchema) provides access to its complete type system and descriptor hierarchy.
2.2. Type ID Conversion
-
String to TypeId: Most descriptor retrieval functions automatically convert string type names to TypeId using
.toTypeId()method. -
Exception:
getComplexEntityDescriptor()accepts aList<String>directly without.toTypeId()conversion. -
Type Safety: TypeId conversion ensures type-safe operations and prevents runtime errors from invalid type names.
2.3. Descriptor Hierarchy
-
EntityDescriptor: Describes entities with attributes, inheritance, and structural metadata.
-
SelectDescriptor: Describes SELECT types that can be one of several possible types.
-
EnumDescriptor: Describes enumerated types with predefined value sets.
-
TypeDescriptor: Describes defined (typedef) types.
-
AttributeDescriptor: Describes individual attributes within entity descriptors.
2.4. Property Access Patterns
-
Dynamic Property Access: Accessor blocks use dropdowns to select from available properties for each descriptor type.
-
Property Types: Return types vary by property (strings, numbers, booleans, arrays, or specialized types like
FundamentalType). -
Null Output: Accessor blocks have
nulloutput type, requiring type inference based on property selection.
2.5. Complex Entity Descriptors
-
Type Lists:
getComplexEntityDescriptor()accepts aList<String>of type names to create combined descriptors. -
Use Cases: Useful for queries that need to match multiple entity types or create flexible type constraints.
-
AND/OR Logic: The "complex" descriptor likely combines types using logical operations (AND/OR) for flexible matching.
2.6. Attribute Descriptor Access
-
Two-Step Process:
getAttributeDescriptor()first callsgetAttributeIndex()to locate the attribute by name, then retrieves the descriptor. -
Attribute Indexing: This pattern suggests attributes are indexed internally for performance optimization.
-
Error Handling: Invalid attribute names are handled at the
getAttributeIndex()stage.
2.7. Select Type System
-
Selectable Types: SELECT types define sets of allowable types for an attribute.
-
Fundamental Type Resolution: Use
getSelectableFundamentalType()to determine the underlying fundamental type for selectable items. -
Type Flexibility: SELECT types provide polymorphism within strongly-typed schemas.
2.8. Schema Introspection Workflow
-
Get Schema: Start with
getSchemaByEnum()to obtain the desired schema instance. -
Retrieve Descriptors: Use appropriate
get*Descriptor()methods for the needed type information. -
Access Properties: Use accessor blocks to query specific descriptor properties.
-
Handle Results: Process descriptor data for validation, UI generation, or dynamic entity creation.
2.9. Performance Characteristics
-
Descriptor Caching: Descriptors are automatically cached upon first access, ensuring subsequent retrievals are efficient.
-
Optimized Storage: Schema data uses efficient binary storage with fast lookup capabilities.
-
Memory Efficiency: The system minimizes memory footprint while providing fast access through shared descriptor instances.
-
Type ID Optimization: Internal integer Type IDs enable rapid descriptor resolution compared to string-based lookups.
-
Indexed Attributes: Attributes are indexed within entity descriptors for efficient access by name.
2.10. Error Handling
-
Invalid Type Names: Functions return appropriate null or error values for non-existent type names.
-
Missing Attributes:
getAttributeIndex()handles missing attribute names gracefully. -
Schema Availability: Ensure requested schemas are available in the runtime environment.
2.11. Integration with Other APIs
-
Template System: Schema descriptors work with the Template API for type-safe template creation.
-
Entity Creation: Use descriptor information to create properly typed entities in models.
-
Validation: Leverage schema metadata for runtime validation of entity structures and attributes.
-
Code Generation: Descriptor metadata supports automated code generation and documentation.
3. Implementation Advantages
The schema system is designed for high-performance access to standardized schema definitions:
-
Binary Efficiency: Schema definitions are stored in optimized binary format for minimal memory usage and fast loading
-
Intelligent Caching: All descriptor types are cached upon first retrieval with automatic memory management
-
Optimized Lookups: Internal indexing and integer-based Type IDs ensure rapid descriptor resolution
-
Scalable Architecture: Efficiently handles large schemas with thousands of entity definitions
-
Consistent Performance: Caching ensures predictable performance across repeated operations
This API provides comprehensive schema introspection capabilities, enabling dynamic, type-safe operations across multiple industry standards. The descriptor system exposes rich metadata that supports validation, code generation, and intelligent entity manipulation within engineering and BIM applications while maintaining optimal performance through intelligent caching and efficient data structures.
3.1. Block Reference
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Schema Access |
|
Get the schema object as specified by SupportedSchema enum. |
|
Entity Descriptors |
|
Get entity descriptor of a given type in schema. |
|
Entity Descriptors |
|
Get complex entity descriptor for a list of type names. |
|
Select Descriptors |
|
Get select descriptor for a specific type. |
|
Enum Descriptors |
|
Get enum descriptor for a specific enumerated type. |
|
Type Descriptors |
|
Get defined type descriptor for a specific type. |
|
Entity Descriptor Properties |
Dynamic property access
|
Access properties from an EntityDescriptor object. |
|
Attribute Descriptor Access |
|
Get an AttributeDescriptor by name from an EntityDescriptor. |
|
Select Descriptor Properties |
Dynamic property access
|
Access properties from a SelectDescriptor object. |
|
Select Type Resolution |
|
Get the fundamental type for a selectable type ID from a SelectDescriptor. |
|
Type Descriptor Properties |
Dynamic property access
|
Access properties from a TypeDescriptor object. |
|
Enum Descriptor Properties |
Dynamic property access
|
Access properties from an EnumDescriptor object. |
|
Attribute Descriptor Properties |
Dynamic property access
|
Access properties from an AttributeDescriptor object. |
Project API Block Reference
4. Introduction
The Project API provides comprehensive functionality for managing PI (Product Information) projects within the Blockly visual programming environment. This API enables users to create, manipulate, and maintain engineering data projects containing multiple models with different schemas (AP203, AP210, AP214, AP242, CIS2, IFC4X3).
Key capabilities include: * Project Management: Create, activate, close, and update project metadata * Model Operations: Add, remove, import, and query models within projects * Schema Support: Handle multiple industry-standard schemas for different engineering domains * Backup System: Create, retrieve, and manage project backups with version control * Memory Models: Create transient in-memory models for temporary operations * Reference Models: Import files as reference models for external data integration
The API is designed to work with the PI Platform’s data model system, providing a visual interface for complex data management operations typically performed programmatically.
5. Usage Notes
5.1. Project Lifecycle Management
-
Always activate projects before performing operations using
activateProject() -
Close projects properly after operations using
closeProject()to ensure data integrity -
Check project state with
isActivated()before critical operations -
Validate project references with
isNullto avoid null pointer exceptions
5.2. Model Operations Best Practices
-
Schema Selection: Choose appropriate schema for your data type:
-
AP203/AP214/AP242: Mechanical CAD data
-
AP210: Electronic assembly data
-
AP238: NC machining data
-
CIS2: Construction industry data
-
IFC4X3: Building information modeling
-
-
Tagging Strategy: Use consistent tagging for model organization
-
ID Management: Model IDs should be unique and persistent
-
Import Considerations: Reference models are read-only; regular imports create editable copies
5.3. Backup System Guidelines
-
Regular Backups: Use
createBackup()before major changes -
Descriptive Names: Provide meaningful descriptions for backup identification
-
Cleanup Policy: Implement
purgeOldBackups()to manage disk space -
Backup Verification: Always check backup success with returned BackupInfo
5.4. Memory Model Usage
-
Temporary Operations: Use memory models for calculations or transformations
-
No Persistence: Memory models are not saved automatically
-
Performance: Memory operations are faster but limited by available RAM
-
Cleanup: Memory models are garbage collected when no longer referenced
5.5. Error Handling
-
Null Checks: Always verify objects are not null before method calls
-
Validation: Check input parameters meet requirements (non-empty strings, valid IDs)
-
Exception Handling: Wrap operations in try-catch blocks for production code
-
State Verification: Confirm project is activated before model operations
5.6. Performance Considerations
-
Batch Operations: Use bulk methods when processing multiple models
-
Selective Loading: Activate only necessary projects
-
Memory Management: Clean up memory models when no longer needed
-
Backup Strategy: Balance backup frequency with storage constraints
This API provides a comprehensive visual interface for PI project management, enabling both novice and expert users to perform complex data operations through intuitive Blockly blocks.
6. API Reference Table
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Model Creation |
|
Creates new model in project with schema and metadata |
|
Model Import |
|
Imports model file into project with options |
|
Model by ID |
|
Retrieves a specific model by ID |
|
All Model Infos |
|
Returns a list of all model information |
|
Models by Tag |
|
Returns model information filtered by tag |
|
Models by Schema |
|
Returns models filtered by schema |
|
Schema in Project |
|
Returns all model schema enum |
|
Model Count |
|
Returns total number of models |
|
Model Deletion |
|
Delete a model by ID from project |
|
Bulk Deletion |
|
Deletes ALL models from project |
|
Project Activation |
|
Activates and loads project |
|
Project Closure |
|
Closes and deactivates project |
|
Status Check |
|
Checks if project is activated |
|
Null Check |
|
Checks if project object is null |
|
Null Project |
|
Creates empty/null project object |
|
Project Update |
|
Updates project name and description |
|
Project Info |
|
Returns project metadata |
|
Memory Model |
|
Creates transient in-memory model |
|
Memory Reference |
|
Creates transient reference from STEP |
|
Backup Creation |
|
Creates backup of project |
|
Backup Info |
|
Returns backup info for ID |
|
All Backups |
|
Returns array of all backups |
|
Backup Delete |
|
Deletes specific backup |
|
Backup Cleanup |
|
Purges old backups, keeps recent |
7. Model API Overview
The Model API provides a comprehensive set of tools for creating, managing, querying, and manipulating model data within the Blockly visual programming environment. This API enables developers to work with structured data models, instances, and their relationships through an intuitive graphical interface.
7.1. Key Features
-
Instance Management: Create, read, update, and delete model instances
-
Type System: Support for different instance types including references, selects, and enums
-
Query Capabilities: Advanced filtering by type, tags, and relationships
-
Pagination: Efficient handling of large datasets through paginated queries
-
Model Operations: Export, import, copying, and comparison between models
-
Metadata Management: Comprehensive model information and property access
7.2. Architecture Principles
The Model API follows these design principles:
-
Type Safety: All blocks enforce type checking through Blockly’s type system
-
Consistency: Similar operations follow consistent patterns across the API
-
Error Resilience: Functions return appropriate defaults or boolean indicators for error conditions
-
Performance: Paginated queries and batch operations for handling large datasets
7.3. Core Concepts
7.3.1. Model
A container for instances and metadata. Models can be: * PIModel: Standard model type * PIIfcModel: IFC-specific model type * PISTPModel: STP-specific model type
7.3.2. Instance
An object within a model, representing a specific entity with: * Type: The class or category of the instance * Handle: Unique identifier within the model * Properties: Attributes and values specific to the instance type
7.4. Usage Notes
7.4.1. Creating Instances
Instances can be created in several ways:
-
By Type Name: Create a basic instance of a specific type
-
From Dictionary: Create and populate an instance using key-value pairs
-
As Reference: Create an instance reference from an existing handle
-
Special Types: Create select or enum instances with type-specific configurations
// Example: Creating different types of instances
var wallInstance = model.createInstance(typeName: 'IfcWall');
var enumInstance = model.createEnum(typeName: 'IfcDoorTypeOperationEnum', stringValue: 'SINGLE_SWING_LEFT');
var selectInstance = model.createSelect(typeName: 'IfcPropertySetDefinitionSelect');
7.4.2. Instance Lifecycle Management
-
Creation: Instances are created using factory methods
-
Population: Values are set through property assignments or dictionary initialization
-
Saving: Instances are persisted to the model using
saveInstance() -
Retrieval: Instances are fetched by handle, type, or tag
-
Deletion: Instances are removed using
deleteInstance()after checking dependencies
7.4.3. Working with Tags
Tags provide a flexible way to categorize and retrieve instances:
// Tag an instance during creation
model.saveInstance(wallInstance, tag: 'exterior_walls');
// Tag an existing instance
model.tagInstance(wallInstance, 'load_bearing');
// Retrieve instances by tag
var exteriorWalls = model.getInstancesByTag('exterior_walls');
7.4.4. Query Patterns
Basic Queries
-
All Instances:
model.getInstances() -
By Handle:
model.getInstance(handle) -
By Type:
model.getInstancesByType(typeName: 'IfcWall')
Advanced Queries
-
With Subtypes: Include derived types in type-based queries
-
Paginated: Retrieve instances in pages for large datasets
-
With Conditions: Filter by multiple criteria using chained operations
Performance Considerations
For large models:
* Use paginated queries instead of loading all instances at once
* Consider using detachAll: true for read-only operations to improve performance
* Use type-specific queries when possible instead of retrieving all instances
Example: Efficient Query Pattern
// Instead of loading all instances
// var allInstances = model.getInstances(); // ❌ Inefficient for large models
// Use paginated queries
var firstPage = model.getInstancesPaginated(null, pageSize: 50);
// Process page by page...
// Or use type-specific queries
var walls = model.getInstancesByType(typeName: 'IfcWall', includeSubType: true);
7.4.5. Model Operations
Export and Import
Models can be exported in multiple formats: * CSV: Comma-separated values for spreadsheet compatibility * JSON: JavaScript Object Notation for web applications * PIB: Proprietary binary format for optimal performance
7.4.6. Error Handling
Most operations return boolean indicators or null values for error conditions:
-
Success/Failure: Boolean return values indicate operation success
-
Null Checks: Use
.isNullto check for null models or instances -
Dependency Checks: Use
canDelete()before removing instances
// Safe deletion pattern
if (model.canDelete(instance)) {
var success = model.deleteInstance(instance);
if (!success) {
// Handle deletion failure
}
} else {
// Handle dependency constraints
}
7.4.7. Best Practices
-
Always Check Dependencies: Use
canDelete()before deleting instances -
Use Pagination for Large Models: Avoid loading entire models into memory
-
Leverage Tags for Organization: Use tags for logical grouping and retrieval
-
Validate Type Names: Ensure type names exist in the model schema
-
Handle Null Returns Gracefully: Always check for null instances after retrieval
-
Use detachAll for Read-Only Access: Improves performance for queries that don’t need write access
7.4.8. Common Patterns
Batch Operations
// Create multiple instances
var instances = [];
for (var i = 0; i < 10; i++) {
var instance = model.createInstance(typeName: 'IfcWall');
instances.add(instance);
}
model.saveInstances(instances);
7.6. Performance Considerations
-
Memory Usage: Large models should use paginated queries
-
detachAll Parameter: Use
detachAll: truefor read-only operations to reduce memory overhead -
Batch Operations: Use
saveInstances()for multiple saves instead of individual calls -
Caching: Consider caching frequently accessed instances or metadata
7.7. Security Notes
-
Input Validation: All user inputs should be validated before passing to model operations
-
Path Security: Validate file paths in export operations
-
Access Control: Implement appropriate access controls at the application level
7.8. Migration and Compatibility
When working with different model types or versions:
1. Check schema compatibility using model.getInfo()
2. Use model.hasSameLengthUnit() before copying between models
3. Handle type name changes or deprecations in your application logic
7.9. Troubleshooting
Common issues and solutions:
-
Null Returns: Check if the model or instance exists before operations
-
Type Errors: Verify type names exist in the model using
model.getInstanceTypes() -
Performance Issues: Implement pagination and use
detachAll: truefor queries -
Export Failures: Verify file paths and permissions
7.10. Further Reading
-
See the complete Block Functions Reference for detailed API documentation
-
Consult the Dart API documentation for specific method signatures
-
Review example projects for implementation patterns
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Model Management |
|
save instance to model data base with optional tag. Returns true if success. |
|
Model Management |
|
save a collection of instances to model. Returns true if success. |
|
Instance Creation |
|
create an instance of the given type in model. If detachAll is true, instance is created in detached mode. |
|
Instance Creation |
|
create an instance reference from instance handle. |
|
Instance Creation |
|
create ISelect of given type and optional set the selected value type. |
|
Instance Creation |
|
create PIEnum of given type and optional set its value. |
|
Instance Creation |
|
create an instance in model and fill the value using a dictionary. Instance type is given by the special key @type, returns the create IInstance. |
|
Instance Deletion |
|
delete an instance from model. Returns true if success. |
|
Instance Deletion |
|
can the instance be safely deleted?. Returns a bool value. |
|
Instance Query |
|
list all instances (InstanceHandle) in the model. Use paginated api if returning List<IInstance> is desirable. |
|
Instance Query |
|
list instances (IInstance) with a given tag in model. |
|
Instance Query |
|
get instance with InstanceHandle in model. The return instance isNull == true if not found. |
|
Instance Query |
|
get instances corresponding to a list of instance handles. Returns List<IInstance>. |
|
Instance Query |
|
list instances by type, optionally, search all subtype in a model. Return List<IInstance>. |
|
Instance Query |
|
get one instance of a type. |
|
Instance Query |
|
approximate instance type count in model. Returns integer count. |
|
Instance Query |
|
get instances that reference the given instance in the model. Returns a list instance handes. |
|
Instance Query |
|
get instance from model paginated, with starting page instance handle, page size. If detachAll is true, instances are in safe mode. |
|
Instance Query |
|
get instance from model paginated, with starting page instance handle, page size. If detachAll is true, instances are in safe mode. |
|
Model Metadata |
|
get model meta info from model. Returns a ModelInfo object. |
|
Model Metadata |
|
list all instance type names that appears in model. Returns a List<String>. |
|
Model Metadata |
|
get the model header instance which contains the header section information. |
|
Model Metadata |
|
get clear text representation of header instance. Returns the clear text string. |
|
Model Metadata |
|
get model’s readonly property, including: id, name, createdAt, schema… |
|
Model Operations |
|
tag instance in model. Return true if success. |
|
Model Operations |
|
update model meta data. Returns true if success. |
|
Model Operations |
|
resolve instanceId of the instance to make sure it does not collide with existing ids, return the update instance. |
|
Model Operations |
|
clear all instance in model. Return true if success. |
|
Model Operations |
|
save model meta data. Return true if success. |
|
Model Operations |
|
harmonize instance ids for the given instances using the id maps, and use the next model instance id when needed. Return true if success. |
|
Model Operations |
|
harmonize instance ids for the instances use the next model instance id. Returns true if success. |
|
Model Operations |
|
copy instance from one model to another and composed dependency when appropriate, updates are saved. Returns a list of updated instance. |
|
Model Operations |
|
copy instance from one model to another, if copying within model, set toModel PIModel.nullModel. Returns the copied instance. |
|
Model Operations |
|
export model to the given location and format. Returns true if success. |
|
Model Factory |
|
create a null model. |
|
Model Factory |
|
is model null? |
|
Model Comparison |
|
does the two models have the same length unit? |
|
Model Comparison |
|
get model’s length unit instance. |
|
Model Comparison |
|
is the given type(name) a reference type. A reference type are those that could compose its attribute instance. |
IFC Model Extension API Documentation
8. Introduction
The IFC Model Extension API provides a comprehensive set of operations for manipulating IFC (Industry Foundation Classes) models within a Blockly-based visual programming environment. This API enables users to perform advanced BIM (Building Information Modeling) operations including spatial structure management, property set manipulation, geometric operations, and model transformation tasks.
8.1. Key Features
-
Spatial Structure Management: Navigate and modify IFC spatial hierarchies (sites, buildings, stories, spaces)
-
Property Operations: Create, modify, and query property sets (PSets) and quantity sets (QSets)
-
Geometric Manipulation: Handle shape representations, placements, and geometric contexts
-
Relationship Management: Manage complex IFC relationships and dependencies
-
Material & Layer Management: Associate materials with elements and manage layer assignments
-
Model Transformation: Copy, convert, and transform model elements between contexts
8.2. API Philosophy
The API follows a consistent pattern where:
. All operations require a model instance as primary context
. Optional parameters follow Dart’s named parameter convention
. Operations return new instances with detachAll option for isolation
. Error conditions return empty strings or default values rather than throwing exceptions
9. Usage Notes
9.1. Model Context Requirement
All API operations require a valid model instance as their primary context. The model instance must be obtained from an existing project or created through the appropriate project management functions.
// Correct usage - model context is required
var children = model.getSpatialChildren(parent);
// Incorrect usage - will generate empty code
var children = getSpatialChildren(parent);
9.2. Parameter Validation
The API performs basic validation on required parameters. If essential parameters are missing or empty, the generated code will return an empty string, which typically results in no operation being performed in the target environment.
// If 'parent' or 'model' are empty, returns ''
var children = model.getSpatialChildren(parent);
// If 'instance' is empty, returns ''
var shapes = model.getShapes(instance);
9.3. Optional Parameters
Most API functions support optional parameters using Dart’s named parameter syntax. The most common optional parameter is detachAll, which controls whether returned instances are detached from the original model context.
// Without optional parameter
var project = model.getIfcProject();
// With optional parameter
var detachedProject = model.getIfcProject(detachAll: true);
9.4. DetachAll Parameter
The detachAll parameter is a boolean flag that determines whether returned instances are:
* false (default): Returned instances maintain references to the original model
* true: Returned instances are fully detached, allowing independent modification
|
Use |
9.5. String Type Parameters
Certain functions require string type parameters that are automatically converted to Dart string literals using the getDartString() utility function.
// The TYPE parameter is automatically converted to a Dart string
var pset = model.createPSetOfType("IfcPropertySingleValue");
// Equivalent to: model.createPSetOfType("IfcPropertySingleValue")
9.6. Error Handling
The API uses defensive programming patterns: * Missing required parameters result in empty code generation * Invalid operations return empty strings or default values * No runtime exceptions are thrown by the generated code
|
Always validate that generated code is not empty before using results in subsequent operations. Empty results indicate missing or invalid inputs. |
9.7. Performance Considerations
-
Batch Operations: When possible, use batch operations like
copyChildrenWithComposedDependencyinstead of individual operations -
Detached Instances: Creating detached instances (
detachAll: true) has higher memory overhead -
Hierarchy Navigation: Use specialized hierarchy functions rather than manual traversal
9.8. Common Patterns
9.8.1. Adding Elements to Collections
// Add a property set to a product
model.addPSet(product, pset);
// Add a child to a parent spatial element
model.addChild(parent, child);
// Add a shape to a layer
model.addToLayer(shape, layer);
9.8.2. Clearing Collections
// Clear all property sets from an instance
model.clearPSets(instance);
// Clear all shapes from an instance
model.clearShapes(instance);
// Clear all materials from a product
model.clearMaterials(product);
9.8.3. Querying with Conditions
// Get relations with specific type and include subtypes
var relations = model.getInstanceRelations(
product,
relType: "IfcRelContainedInSpatialStructure",
bIncludeSub: true
);
// Get shapes with detached instances
var shapes = model.getShapes(instance, detachAll: true);
10. Compatibility Notes
-
IFC Schema Support: The API supports multiple IFC schemas (IFC2x3, IFC4, IFC4x3)
-
Blockly Version: Requires Blockly version 8.0.0 or higher
-
Dart Compatibility: Generated code targets Dart 2.17+ with null safety
11. Examples
11.1. Basic Spatial Navigation
// Get the project
var project = model.getIfcProject();
// Get spatial children of project (typically sites)
var sites = model.getSpatialChildren(project);
// For each site, get building children
foreach (var site in sites) {
var buildings = model.getSpatialChildren(site);
}
11.2. Property Set Management
// Create a new property set from template
var psetTemplate = getPsetTemplate("CustomProperties");
var newPset = model.createPSetFromTemplate(psetTemplate);
// Add property set to a product
model.addPSet(product, newPset);
// Later, retrieve property sets
var psets = model.getPSets(product);
12. Troubleshooting
12.1. Common Issues
-
Empty Code Generation: Check that all required block inputs are connected
-
Incorrect Results: Verify that model instances are from the same context
-
Performance Issues: Consider using
detachAll: falsewhen possible -
Missing Dependencies: Ensure all referenced instances exist in the model
13. See Also
-
API Function Reference for complete function list
-
Blockly Documentation for general visual programming guidance
-
IFC Specification for underlying data model details
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Spatial Structure |
|
Retrieves all spatial structure children of a parent element |
|
Spatial Structure |
|
Gets the spatial parent element of a child element |
|
Placement Hierarchy |
|
Retrieves placement children under a parent element |
|
Placement Hierarchy |
|
Gets the complete placement hierarchy for an instance |
|
Placement Hierarchy |
|
Retrieves the placement transformation for an instance |
|
Placement Hierarchy |
|
Calculates the absolute placement transformation for an instance |
|
Type Information |
|
Gets the type product associated with an instance |
|
Type Information |
|
Removes type product association from an instance |
|
Type Information |
|
Associates a type product with a product instance |
|
Property Sets |
|
Retrieves property sets associated with an instance |
|
Property Sets |
|
Clears all property sets from an instance |
|
Property Sets |
|
Removes a specific property set from an instance |
|
Property Sets |
|
Adds a property set to a product instance |
|
Property Sets |
|
Creates a property set from a template |
|
Property Sets |
|
Creates a quantity set from a template |
|
Property Sets |
|
Creates a property set of specified type |
|
Property Sets |
|
Creates a quantity set of specified type |
|
Shape Management |
|
Retrieves shape representations for an instance |
|
Shape Management |
|
Clears all shape representations from an instance |
|
Shape Management |
|
Removes a specific shape from an instance |
|
Shape Management |
|
Adds a shape representation to a product |
|
Shape Management |
|
Creates a mapped shape representation from an existing shape |
|
Shape Management |
|
Converts a shape to mapped representation format |
|
Child Management |
|
Adds a child element to a parent element |
|
Child Management |
|
Removes a child element from a parent |
|
Child Management |
|
Gets all child element types under a parent |
|
Project Management |
|
Creates a new IFC project in the model |
|
Project Management |
|
Retrieves the IFC project from the model |
|
Project Management |
|
Gets the project’s RelDeclares relationship |
|
Project Management |
|
Gets project declare references |
|
Instance Operations |
|
Clears all relations from a product |
|
Instance Operations |
|
Gets relations of specified type for a product |
|
Representation Items |
|
Adds a representation item to a shape with optional styling |
|
Representation Items |
|
Adds a shape as a mapped item to another shape |
|
Layer Management |
|
Gets layers associated with a shape |
|
Layer Management |
|
Associates a shape with a layer |
|
Layer Management |
|
Removes a shape from a layer |
|
Layer Management |
|
Clears all layer associations from a shape |
|
Layer Management |
|
Gets all shapes in a specific layer |
|
Material Management |
|
Gets materials associated with a product |
|
Material Management |
|
Associates a material with a product |
|
Material Management |
|
Removes a material association from a product |
|
Material Management |
|
Clears all material associations from a product |
|
Styling |
|
Creates a styled item with color information |
|
Context & Units |
|
Gets the 3D geometric context from the model |
|
Context & Units |
|
Creates model unit assignments |
|
Context & Units |
|
Finds a matching geometric context |
|
Copy Operations |
|
Copies children with composed dependency relationships |
|
Copy Operations |
|
Copies children of specific types with composed dependency |
STEP Model Extension API Documentation
14. Introduction
The STEP Model Extension API provides specialized operations for working with STEP (Standard for the Exchange of Product model data, ISO 10303) models within a Blockly-based visual programming environment. This API enables users to create, query, and manipulate complex STEP data structures including complex instances, contexts, and product definitions essential for CAD data exchange.
14.1. What is STEP?
STEP (ISO 10303) is an international standard for representing and exchanging product manufacturing information. Unlike IFC which is focused on building information, STEP is widely used in mechanical CAD, automotive, aerospace, and manufacturing industries for exchanging 3D product data.
14.2. Key Features
-
Complex Instance Management: Create and query complex STEP instances with multiple part types
-
Context Creation: Establish necessary contexts for valid STEP files
-
Type Hierarchy Support: Automatic inclusion of subtype relationships (e.g., SI_UNIT → NAMED_UNIT)
-
Instance Querying: Find instances by ID, part type, or complex structure
-
Detached Instance Support: Work with isolated instances for transformation and analysis
14.3. Key STEP Concepts
-
Complex Instance: A STEP entity composed of multiple part types, e.g.,
#41=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.)) -
Simple Instance: A basic STEP entity with a single type, e.g.,
#156=VERTEX_POINT('',#155) -
Part Type: The individual components of a complex instance (LENGTH_UNIT, NAMED_UNIT, SI_UNIT)
-
Context: Required contextual information for STEP entities (application, geometric, product contexts)
15. Usage Notes
15.1. Model Context Requirement
All API operations require a valid STEP model instance as their primary context. The model must be created as a STEP model or converted from an existing model.
// Correct - model is STEP model
var instances = stepModel.getComplexInstances();
// Incorrect - will generate empty code if model is not STEP
var instances = nonStepModel.getComplexInstances();
15.2. Complex Instance Creation
Complex instances are created from an array of root types only. The API automatically includes necessary subtypes based on STEP type hierarchies.
// User provides root types only
var types = ["LENGTH_UNIT", "SI_UNIT"];
// API automatically includes NAMED_UNIT (subtype of SI_UNIT)
var complexInstance = model.createComplexInstance(typeNames: types);
// Result: (LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.))
15.3. Type Hierarchy Automation
The API automatically manages type inheritance relationships:
-
SI_UNIT→ IncludesNAMED_UNITautomatically -
Other type hierarchies are handled similarly
-
Users only specify the top-level types needed
|
Do not include subtypes in your type array. The system will add them automatically based on STEP type hierarchies. |
15.4. Part Name Queries
When querying for complex instances by part type, specify the exact part type name:
// Find all complex instances containing LENGTH_UNIT
var lengthUnits = model.getComplexInstancesWithPart(partName: "LENGTH_UNIT");
// Find specific instance by ID containing SI_UNIT
var instance = model.getComplexInstanceWithIdPart(41, partName: "SI_UNIT");
15.5. Context Creation Order
STEP contexts have dependencies that should be created in order:
-
Application Context (APPLICATION_CONTEXT)
-
Geometric Representation Context (GEOMETRIC_REPRESENTATION_CONTEXT)
-
Product Context (PRODUCT_CONTEXT)
-
Product Definition Context (PRODUCT_DEFINITION_CONTEXT)
// Create contexts in proper order
var appContext = model.createAppContext();
var geomContext = model.createGeometryContext(3, 0.0);
var productContext = model.createProductContext(appContext);
var productDefContext = model.createProductDefinitionContext(appContext, stage: "design");
15.6. DetachAll Parameter
The detachAll parameter controls instance isolation:
-
false(default): Instance maintains model references -
true: Instance is fully detached for independent modification
// With references to original model
var attached = model.getComplexInstances();
// Fully independent copy
var detached = model.getComplexInstances(detachAll: true);
15.7. String Parameter Handling
String parameters for part names are automatically converted to Dart string literals:
// Block input "LENGTH_UNIT" becomes "LENGTH_UNIT" in Dart
var instances = model.getComplexInstancesWithPart(partName: "LENGTH_UNIT");
15.8. Error Handling
The API uses defensive patterns:
-
Missing required inputs → Empty code generation
-
Non-existent instances →
isNull = truereturned instances -
Invalid operations → Empty results
// Returns isNull=true if instance #999 doesn't exist
var instance = model.getComplexInstanceWithIdPart(999, partName: "LENGTH_UNIT");
if (instance.isNull) {
// Handle missing instance
}
16. Common Patterns
16.1. Creating Measurement Units
// Create millimeter unit complex instance
var mmUnit = model.createComplexInstance(typeNames: ["LENGTH_UNIT", "SI_UNIT"]);
// Result in STEP: #41=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.))
16.2. Querying Complex Structures
// Find all unit definitions
var allUnits = model.getComplexInstances();
// Find specific unit type
var lengthUnits = model.getComplexInstancesWithPart(partName: "LENGTH_UNIT");
// Get specific instance by ID
var unit41 = model.getComplexInstanceWithIdPart(41, partName: "SI_UNIT");
16.3. Setting Up STEP Contexts
// Complete context setup for mechanical design
var appContext = model.createAppContext();
var geomContext = model.createGeometryContext(3, 0.0); // 3D, exact
var productContext = model.createProductContext(appContext);
var designContext = model.createProductDefinitionContext(
appContext,
stage: "design"
);
17. Compatibility Notes
-
STEP Versions: Supports ISO 10303 (STEP) AP203, AP214, AP242
-
CAD Compatibility: Generates data compatible with major CAD systems
-
Blockly Version: Requires Blockly 8.0.0+
-
Dart Compatibility: Targets Dart 2.17+ with null safety
18. Examples
18.1. Basic Complex Instance Workflow
// Create complex instance
var types = ["LENGTH_UNIT", "SI_UNIT"];
var complexInstance = model.createComplexInstance(typeNames: types);
// Get its type name
var typeName = model.getComplexInstanceTypeName(types);
// Returns: "LENGTH_UNIT_AND_NAMED_UNIT_AND_SI_UNIT"
// Later find similar instances
var similar = model.getComplexInstancesWithPart(partName: "LENGTH_UNIT");
18.2. Context Management
// Create necessary contexts for product data
var contexts = [];
// Application context
contexts.add(model.createAppContext());
// 3D geometric context (exact measurements)
contexts.add(model.createGeometryContext(3, 0.0));
// Product context using application context
var appContext = contexts[0];
contexts.add(model.createProductContext(appContext));
// Design stage product definition
contexts.add(model.createProductDefinitionContext(
appContext,
stage: "design"
));
19. Troubleshooting
20. See Also
-
API Function Reference for complete function list
-
ISO 10303 (STEP) specification for underlying data model
-
CAD system documentation for STEP import/export requirements
-
IFC Model Extension API for building information modeling
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Complex Instance Creation |
|
Create complex instance like (LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.)) with the given type names [LENGTH_UNIT,SI_UNIT] in model. |
|
Complex Instance Management |
|
Generate complex type name from array of part types. For ['LENGTH_UNIT','SI_UNIT'] returns combined type name LENGTH_UNIT_AND_NAMED_UNIT_AND_SI_UNIT. |
|
Complex Instance Management |
|
Get all complex instances in the stp model. Returns a list of IInstance. |
|
Complex Instance Management |
|
Get complex instances containing specific part type (e.g., 'LENGTH_UNIT'). Returns list of matching IInstance objects. |
|
Complex Instance Management |
|
Get specific complex instance by ID that contains given part type (e.g., instance containing 'LENGTH_UNIT'). Returns IInstance (isNull=true if not found). |
|
Context Creation |
|
Create default STEP application context (APPLICATION_CONTEXT). Returns the context instance. |
|
Context Creation |
|
Create GEOMETRIC_REPRESENTATION_CONTEXT for STEP model. Dimension: coordinate space dimension (3 for 3D). Uncertainty: 0.0 for exact values. Returns context instance. |
|
Context Creation |
|
Create PRODUCT_CONTEXT using given APPLICATION_CONTEXT instance. Returns product context instance. |
|
Context Creation |
|
Create PRODUCT_DEFINITION_CONTEXT. Stage examples: 'design', 'manufacturing', 'inspection'. Default: 'design'. Returns context instance. |
Reference Model API Documentation
21. Introduction
Reference Models in PicoComposer are imported models where the imported content is treated as a reference portion that cannot be deleted. This architectural pattern enables powerful workflows where users can:
-
Import baseline content from CSV or JSON files
-
Add new instances to extend the model
-
Update existing reference instances
-
Load and unload reference content at runtime for memory management
-
Maintain the original reference file while working with a modifiable copy
Reference Models are subtypes of IIfcModel and ISTPModel, inheriting all their functionality while adding reference-specific capabilities.
22. Key Concepts
22.1. Reference vs. Added vs. Updated Instances
-
Reference Instances: Original content imported from reference files (CSV/JSON)
-
Added Instances: New instances created after import, not present in reference files
-
Updated Instances: Reference instances that have been modified
22.2. ID vs. Handle Access Pattern
One of the most important architectural decisions in the Reference Model API is the distinction between ID-based and Handle-based access:
| ID-Based Access | Handle-Based Access | |
|---|---|---|
Data Structure |
Integer value only |
Struct containing |
Used For |
Reference portion operations |
Outside/database operations |
When to Use |
- Checking instance status - Undoing updates - Reference-specific queries |
- Database lookups
- Type-based operations
- Integration with |
Example Operations |
|
|
Conversion |
Use |
Use |
Rule of Thumb: "Inside the reference part, use ID. Outside the reference part, use Handle."
22.3. Load/Unload Architecture
Reference content can be loaded and unloaded at runtime:
-
Loaded State: Reference content is in memory, available for queries and operations
-
Unloaded State: Reference content is persisted to disk, freeing memory while maintaining instance metadata
-
Dynamic Management: Applications can load/unload based on memory constraints or workflow requirements
23. API Overview
23.1. Instance Retrieval Functions
The API provides three primary functions for getting instance collections:
-
getReferenceInstances()- Returns handles for all reference instances -
getAddedInstances()- Returns handles for newly added instances -
getUpdatedInstances()- Returns handles for updated reference instances
All three functions return handles for consistency with the broader model API ecosystem.
23.2. Status Checking Functions
These functions use ID-based access to check instance status:
-
isReferenceInstance(id)- Checks if an instance is part of the reference content -
isAddedInstance(id)- Checks if an instance was added after import -
isUpdatedInstance(id)- Checks if a reference instance has been updated
24. Usage Examples
24.1. Basic Workflow
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Reference Model Instances |
|
get all reference instance handles in a reference model. |
|
Reference Model Instances |
|
get all newly added instance handles in a reference model. |
|
Reference Model Instances |
|
get all updated instance handles in a reference model. |
|
Instance Status Checks |
|
is the given instance a reference instance in a reference model. Returns true if instance is a imported reference instance. |
|
Instance Status Checks |
|
is the given instance a newly added instance in a reference model. Return true if instance is not part of imported reference file. |
|
Instance Status Checks |
|
has instance been updated?. Return true if instance is part of the reference file and had been updated. |
|
Reference Model Operations |
|
undo update to a reference instance. Return true if success. |
|
Reference Model Loading |
|
load the referenced content of the model. Returns true if success. |
|
Reference Model Loading |
|
unload the referenced content of the model from memory. Returns true is success. |
|
Reference Model Loading |
|
is the referenced content of model loaded? |
Instance API Guide
25. Introduction
The Instance API provides a comprehensive, type-safe interface for working with object instances in a Blockly-to-Dart visual programming environment. This API enables developers to create, manipulate, and manage complex object hierarchies with rich attribute systems, relationships, and metadata.
At its core, the Instance API revolves around the IInstance interface, which represents individual object instances with properties, attributes, and relationships. The system supports a wide range of data types—from simple booleans and numbers to complex enumerations, nested instances, and multi-dimensional arrays—all while maintaining strict type safety through Blockly’s visual type system.
The API is particularly well-suited for:
-
Data modeling applications where objects have complex relationships
-
Configuration management systems with hierarchical structures
-
CAD/BIM applications requiring rich object properties
-
Any system needing strong typing with visual programming
Key design principles include:
-
Type safety: Every operation validates input and output types
-
Relationship integrity: Automatic management of references and inverses
-
Performance efficiency: Batch operations and lazy evaluation where possible
-
Developer experience: Consistent patterns across all operations
26. Core Concepts
26.1. Instance Types
IInstance-
The primary object representation. Every instance has a unique ID, type information, and can contain multiple attributes.
InstanceHandle-
A lightweight reference to an instance containing
instanceIdandtypeId. Used for relationships without full object loading. PIEnum-
Type-safe enumeration values with both string and integer representations.
ISelect-
Selection objects that can choose between different instance types.
26.2. Attribute System
The attribute system supports three categories of data:
- Basic Types
-
Simple data types including
BOOL,INT32,UINT32,INT64,FLOAT,REAL,STRING,BINARY, andLOGICAL. - Complex Types
-
Structured types including
ENUM,INSTANCE, andSELECT. - Aggregate Types
-
Collections including 1D arrays (
BOOLS,INT32S, etc.), 2D arrays (INT32S2,REALS2, etc.), and 3D arrays (REALS3,INSTANCES3).
27. Quick Start Guide
27.1. Creating Your First Instance
// 1. Create a null instance as a starting point
create null instance
// 2. Create an attribute on the instance
create [instance] attribute with name: "properties" for instance: [myInstance]
// 3. Set some basic properties
set attribute with name: "name" to value: "Example Object" for instance: [myInstance]
set attribute with name: "width" to value: 100 for instance: [myInstance]
set attribute with name: "height" to value: 200 for instance: [myInstance]
// 4. Create an enum attribute
create [enum] attribute with name: "status" for instance: [myInstance]
set enum: [status] value to: "ACTIVE"
27.2. Working with Relationships
// 1. Create parent and child instances
create [instance] attribute with name: "parentObject"
create [instance] attribute with name: "childComponent"
// 2. Set up the parent-child relationship
add instance: [childComponent] as composite to instance: [parentObject]
// 3. Create a reference to another instance
add instance reference: [externalObject] add inverse? true
to aggregate attribute with name: "dependencies"
for instance: [parentObject]
27.3. Batch Operations
// 1. Create configuration data
set instance: [configInstance] attributes by dictionary: {
"name": "Main Configuration",
"version": 2.1,
"enabled": true
}
// 2. Update multiple attributes by path
set attribute with path: ["components", "0", "settings"]
to value: {"x": 100, "y": 200, "z": 300}
for instance: [mainObject]
28. Best Practices
28.1. Type Safety
Always use the appropriate type-specific getters:
// GOOD: Type-specific getter
get [bool] attribute with name: "enabled" from instance: [config]
// AVOID: Generic getter when type is known
get attribute with path: ["enabled"] for instance: [config]
28.2. Error Handling
Check operation results and null states:
// Check if operation succeeded
set attribute with name: "criticalSetting"
to value: importantValue
for instance: [mainObject]
// Returns Boolean success indicator
// Check for null before using
is instance: [result] null?
if not [isNull] {
// Safe to use result
}
28.3. Performance Optimization
Use appropriate patterns for different scenarios:
-
For deep attribute access: Use path-based operations instead of nested getters
-
For batch updates: Use dictionary loading instead of individual sets
-
For read-heavy operations: Cache results when possible
-
For temporary instances: Use
detach()to release resources
29. Common Patterns
29.1. Configuration Object Pattern
// Create configuration instance
create [instance] attribute with name: "appConfig"
// Set configuration values
set attribute with name: "appName" to value: "My Application" for instance: [appConfig]
set attribute with name: "version" to value: "1.0.0" for instance: [appConfig]
set attribute with name: "debugMode" to value: false for instance: [appConfig]
// Create nested settings
create [instance] attribute with name: "uiSettings" for instance: [appConfig]
set attribute with name: "theme" to value: "dark" for instance: [uiSettings]
set attribute with name: "language" to value: "en-US" for instance: [uiSettings]
29.2. Component Hierarchy Pattern
// Create assembly structure
create [instance] attribute with name: "assembly"
// Add components
create [instance] attribute with name: "component1"
create [instance] attribute with name: "component2"
// Build hierarchy
add instance: [component1] as composite to instance: [assembly]
add instance: [component2] as composite to instance: [assembly]
// Set component properties
set attribute with name: "position" to value: {"x": 0, "y": 0} for instance: [component1]
set attribute with name: "position" to value: {"x": 100, "y": 0} for instance: [component2]
29.3. Data Validation Pattern
// Validate instance state
validate references for instance: [mainInstance]
validate inverses for instance: [mainInstance]
// Check data integrity
is instance: [result] null?
is attribute with name "requiredField" in instance: [data] null?
// Clean up stale references
clear references for instance: [instance]
include internal reference? true
excluding ids: [validIds]
30. Troubleshooting
30.1. Common Issues and Solutions
- Attribute not found
-
Verify attribute names match exactly, including case. Use
get attribute type with name:to check existence. - Null returns
-
Always check with
is null instanceoris null attributeblocks before using results. - Performance issues
-
Use
detach()for temporary instances, prefer batch operations, and validate that references aren’t creating circular dependencies. - Relationship errors
-
Run
validateReferences()andvalidateInverses()periodically to clean stale relationships.
30.2. Debugging Techniques
// 1. Inspect instance properties
get: [instanceId] from instance: [target]
get: [typeName] from instance: [target]
// 2. Check dirty state
is instance: [target] dirty?
// 3. Get all attributes
get: [attributeNames] from instance: [target]
// 4. Export for inspection
get clear text representation of type [json] for instance: [target]
31. Advanced Features
31.1. Custom Type Creation
// Create complex type definition
create complex instance for attribute of name: "customType"
with parts: [
{"name": "id", "type": "INT32"},
{"name": "data", "type": "STRING"},
{"name": "metadata", "type": "INSTANCE"}
]
for instance: [typeRegistry]
32. Conclusion
The Instance API provides a powerful, type-safe foundation for building complex object hierarchies in visual programming environments. By understanding the core concepts of instances, attributes, and relationships, developers can create robust applications with rich data models while maintaining the accessibility of block-based programming.
Remember to:
-
Always use type-specific operations when types are known
-
Validate relationships periodically
-
Clean up unused instances with
detach() -
Use batch operations for performance-critical sections
-
Leverage the comprehensive property system for debugging and inspection
With these patterns and practices, you can build maintainable, efficient applications using the Instance API’s full capabilities.
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Attribute Creation |
|
create select, instance, enum for the attribute of the given name. Optionally set the selected type, instance subtype or enum value. |
|
Complex Attribute |
|
create a complex attribute instance with the given parts. |
|
Enum Operations |
|
set enum’s value |
|
Enum Operations |
|
get enum string value |
|
Enum Operations |
|
get enum integer value |
|
Attribute Information |
|
get instance attribute type, empty string if attribute with name does not exist. |
|
Attribute Information |
|
get instance attribute fundamental type. Return Fundamental.UNKNOWN if attribute with name does not exist. |
|
Attribute Operations |
|
set attribute of name to the given value, returns true if success. |
|
Aggregate Operations |
|
update an element for a list attribute of an instance, return true if success. |
|
Attribute Information |
|
does instance attribute with the given name have null value? |
|
Attribute Operations |
|
get instance attribute value by name. To check null return value, use the isNull utility block. |
|
Bulk Operations |
|
use dictionary to set instance’s attributes. Returns true if success. |
|
Composite Management |
|
get all composite instances for instance. |
|
Composite Management |
|
get composite by instance id, return instance is null if not exists |
|
Composite Management |
|
get composite instances by type. Return a list of IInstances. |
|
Composite Management |
|
add instance to instance as composite. Return true if success. |
|
Composite Management |
|
set instance’s composite with a list of instances. Return true if success. |
|
Composite Management |
|
remove composite from instance by instance id. Returns true if success. |
|
Composite Management |
|
remove composite from instance of the given type. Returns the removed count. |
|
Composite Management |
|
clear instance’s composites. Returns the removed count. |
|
Composite Management |
|
get all instances—attribute instances, composites—stored in instance. Optionally include references and detach the result. |
|
Inverse Management |
|
get all inverse for instance. Returns list of instance handles. |
|
Inverse Management |
|
get all inverse for instance of type. Return list of instance handles |
|
Inverse Management |
|
get inverse (InstanceHandle) with the given instance id. |
|
Inverse Management |
|
clear inverses for the given instance excluding instance on the exclusion list. Returns the removed count. |
|
Inverse Management |
|
add inverse with the given handle. Returns true if success. |
|
Inverse Management |
|
remove inverse from instance with the given id. Returns true if success. |
|
Inverse Management |
|
remove inverse of given type from instance. Returns the removed count. |
|
Aggregate Operations |
|
remove an element from a aggregate attribute of an instance. Returns true if success. |
|
Aggregate Operations |
|
add an value to a list attribute of an instance. Returns true if success. |
|
Aggregate Operations |
|
add instance reference to a aggregate attribute of an instance. If add inverse is true, add inverse to referenced instance. Returns true if success. |
|
2D Aggregate Operations |
|
remove an item from a 2d aggregate attribute of an instance. Returns true if success. |
|
2D Aggregate Operations |
|
update an element of a 2d aggregate attribute of an instance. Return true is success. |
|
3D Aggregate Operations |
|
remove an element from a 3d aggregate attribute of an instance. Return true if success. |
|
3D Aggregate Operations |
|
update an element in a 3d list attribute of an instance. Returns true if successful. |
|
Serialization |
|
get the clear text representation for the instance. |
|
Serialization |
|
convert instance to json object recursively. If set default for Option value is true, set attribute to a default otherwise set value to null for Option.isNone. |
|
Instance Creation |
|
create a null instance. |
|
Instance Information |
|
is instance null object? |
|
Serialization |
|
convert instance handle to json (Map<String, dynamic>). |
|
Serialization |
|
create instance handle from json (Map<String, dynamic>). Return the handle. |
|
Instance Handle Operations |
|
get the instance handle properties: instanceId, typeId. |
|
Path Operations |
|
set attribute specified by the path to given value. Return the updated instance (could be different from the calling instance). |
|
Path Operations |
|
get instance attribute specified by the path. The return value is a record (FundamentalType, dynamic), where the second slot is the value. |
|
Path Operations |
|
remove item from aggregate attribute with the given path and return the modified instance. |
|
Path Operations |
|
clear aggregate attribute with the given path. Return the updated instance (might be different from the calling instance). |
|
Path Operations |
|
get instance attribute specified by the path. The return value is a dynamic value. |
|
Path Operations |
|
get attribute fundamental type addressed by the path. |
|
Path Operations |
|
nullify an optional attribute pointed to by the given path. No effect if attribute is not optional. |
|
Path Operations |
|
set structure attribute (IInstance, ISelect or List of these) value with json. |
|
Version Management |
|
get instance’s version id. |
|
Version Management |
|
set instance’s version id. |
|
Version Management |
|
increment instance’s version id. PIComposer calls this automatically when instance is saved. |
|
Reference Management |
|
get instance’s references to other instances. Returns a list of instance handles. |
|
Reference Management |
|
clear instance references and keep those in the exclusion list. Return a list of removed handles. |
|
State Management |
|
is instance dirty (modified in memory)? |
|
State Management |
|
set instance’s dirty flag. It is automatically set by the system when setAttribute is called and succeeded. |
|
Reference Operations |
|
set instance reference value for an instance attribute. If add inverse is true. An inverse to instance is added to the referenced instance. |
|
Instance Operations |
|
create a duplicate and returns it. |
|
Instance Operations |
|
detach instance from parent buffer. If detachAll is true, then all instance and select returns from this instance will be detached. Return true if success. |
|
Instance Properties |
|
get instance read-only property which includes: id, typeId, typeName, hash… |
|
Validation |
|
validate instance references to other instance in model and remove stale references. Returns list of valid references (InstanceHandle). |
|
Validation |
|
validate instance inverses linking to other instance and remove stale inverses. Returns list of valid inverses (InstanceHandle). |
|
Aggregate Operations (Missing) |
|
remove an element from a aggregate attribute of an instance. Returns true if success. |
|
Aggregate Operations (Missing) |
|
remove an item from a 2d aggregate attribute of an instance. Returns true if success. |
|
Aggregate Operations (Missing) |
|
remove an element from a 3d aggregate attribute of an instance. Return true if success. |
|
Aggregate Operations (Missing) |
|
update an element for a list attribute of an instance, return true if success. |
|
Aggregate Operations (Missing) |
|
update an element of a 2d aggregate attribute of an instance. Return true is success. |
|
Aggregate Operations (Missing) |
|
update an element in a 3d list attribute of an instance. Returns true if successful. |
|
Path Operations (Missing) |
|
get instance attribute specified by the path. The return value is a dynamic value. |
|
Path Operations (Missing) |
|
get attribute fundamental type addressed by the path. |
|
Path Operations (Missing) |
|
nullify an optional attribute pointed to by the given path. No effect if attribute is not optional. |
|
Path Operations (Missing) |
|
set structure attribute (IInstance, ISelect or List of these) value with json. |
SELECT API Reference
33. Introduction
The SELECT API provides a comprehensive interface for working with SELECT objects in the PicoSTEP environment. SELECTs are fundamental components in STEP (Standard for the Exchange of Product model data) that can hold values of multiple possible types, determined at runtime based on the application protocol schema.
33.1. Key Characteristics
-
Type Flexibility: SELECTs can store values of different fundamental types (bool, int32, real, string, etc.) and complex types (instances, enums, other SELECTs)
-
Runtime Type Validation: Type compatibility is validated against the SELECT’s descriptor at execution time
-
Aggregate Support: Supports aggregate types (arrays/lists) for all fundamental types
-
Dynamic Schema Compatibility: Works with any STEP application protocol without static type constraints
34. Block Categories
34.1. Value Management Blocks
34.2. Aggregate Value Operations
34.2.1. select_add_value_item
Adds an element to an aggregate SELECT value.
Inputs:
- VALUE: Value to add
- SELECT: Target SELECT object
Output: Boolean (true if successful)
Dart Equivalent: select.addValue(value)
34.3. Type Management
34.3.1. select_set_selected_type
Sets the selected value type for a SELECT object.
Inputs:
- SELECTEDTYPE: Type name as string (e.g., "IfcCartesianPoint")
- SELECT: Target SELECT object
Output: Boolean (true if type is valid for this SELECT)
Dart Equivalent: select.setSelectedType(typeName: "TypeName")
Note: Type must be compatible with the SELECT’s descriptor. Returns false for invalid types.
34.3.2. select_create_selected_value
Creates a value object for the SELECT’s selected type.
Inputs:
- OBJECTTYPE: Dropdown ("SELECT", "INSTANCE", or "ENUM")
- SELECT: Source SELECT object
Output: Created object (PIEnum, ISelect, or IInstance)
Dart Methods: createSelect(), createInstance(), createEnum()
34.4. Instance Reference Operations
34.4.1. select_set_instance_ref
Sets SELECT value to an instance reference.
Inputs:
- INSTANCE: Instance reference
- ADDINVERSE: Boolean (optional, default false)
- SELECT: Target SELECT object
Output: Boolean (true if successful)
Dart Equivalent: select.setInstanceRef(instance, addInverse?)
34.4.2. select_add_instance_ref
Adds instance reference to aggregate instance values.
Inputs:
- INSTANCE: Instance reference to add
- ADDINVERSE: Boolean (optional, default false)
- SELECT: Target SELECT object
Output: Boolean (true if successful)
Dart Equivalent: select.addInstanceRef(instance, addInverse?)
34.5. Special Operations
34.5.1. select_nullify_value
Sets SELECT value to null.
Inputs:
- SELECT: Target SELECT object
Output: Boolean (true if successful, always true for nullable SELECTs)
Dart Equivalent: select.nullify()
34.6. Property Access
34.6.1. select_get_read_only_properties_access
Retrieves read-only properties from a SELECT object.
Inputs:
- VALUES: Dropdown selecting property to retrieve
- SELECT: Source SELECT object
Output: Property value (type varies by property)
Available Properties:
- descriptor - Type constraints and metadata
- isDetachAll - Detach status
- isDetach - Individual detach status
- type - Current type
- selectedTypeName - Selected type name
- selectedBaseType - Base type
- selectedFundamentalType - Fundamental type category
Dart Equivalent: Direct property access (e.g., select.descriptor)
35. Usage Notes
35.1. Type Compatibility
-
Always validate types: Use the SELECT’s descriptor to check acceptable types before setting
-
Runtime validation:
select_set_selected_typereturns false for incompatible types -
Aggregate consistency: When working with aggregate values, ensure all elements share compatible types
35.2. Best Practices
// Recommended pattern for type-safe operations
set selected_type "IfcCartesianPoint" for select: [SELECT]
if get:descriptor from select: [SELECT] contains "IfcCartesianPoint"
create SELECT for select: [SELECT]
set value: [VALUE] for select: [NEW_SELECT]
else
// Handle type error
35.3. Error Handling
-
Type mismatches: Most operations return boolean indicating success
-
Empty values: Generators return empty string for incomplete blocks
-
Descriptor checks: Use
select_get_read_only_properties_accessfor debugging
35.4. Performance Considerations
-
Duplicate vs Reference: Use
select_duplicatesparingly for memory efficiency -
Detach operations: Use
detachAlljudiciously with nested structures -
Instance references: Inverse relationships (
addInverse: true) add overhead
35.5. Common Patterns
35.5.1. Type-Safe Value Setting
// 1. Check type compatibility
get:descriptor from select: [MY_SELECT]
// 2. Create appropriate value
create INSTANCE for select: [MY_SELECT]
// 3. Set value
set value: [INSTANCE] for select: [MY_SELECT]
36. Dart API Integration
The Blockly generators map directly to Dart method calls:
// Blockly: set value: [VAL] for select: [SEL]
// Generated: sel.setValue(val)
// Blockly: get bool from select: [SEL]
// Generated: sel.getBool()
// Blockly: set selected type: "TYPE" for select: [SEL]
// Generated: sel.setSelectedType(typeName: "TYPE")
37. Limitations
-
Dynamic type constraints: Cannot provide dropdown validation at design time
-
Schema dependence: Behavior varies by STEP application protocol
-
Runtime errors: Type mismatches only caught at execution time
38. Examples
// Example 1: Creating and populating a SELECT
create SELECT for select: [ROOT_SELECT]
set selected type: "IfcCartesianPoint" for select: [NEW_SELECT]
set value: [POINT_INSTANCE] for select: [NEW_SELECT]
// Example 2: Working with aggregate values
add value: 42 to select: [INT_SELECT]
add value: 99 to select: [INT_SELECT]
update element with index: 0 to value: 100 for select: [INT_SELECT]
// Example 3: Instance reference management
set value to instance reference: [WALL_INSTANCE] add inverse? true for select: [REL_SELECT]
add instance reference: [DOOR_INSTANCE] add inverse? false to select instances values for select: [AGG_SELECT]
39. See Also
-
instance_blocks.ts- Instance manipulation blocks -
utility/utility.ts- String formatting utilities -
STEP Application Protocols - Schema definitions for type constraints
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Value Management |
|
Set SELECT’s stored value. Returns true if successful (type must match selected type). |
|
Value Management |
|
Get SELECT’s stored value. Specify expected value type from dropdown. |
|
Aggregate Operations |
|
Add element to aggregate SELECT value. Returns true if successful. |
|
Aggregate Operations |
|
Remove element from aggregate SELECT value. Returns true if successful. |
|
Aggregate Operations |
|
Update element in aggregate SELECT value. Returns true if successful. |
|
Type Management |
|
Set SELECT’s selected value type. Returns true if successful. |
|
Type Management |
|
Create value for SELECT’s selected type. Returns created object (ENUM, SELECT, or INSTANCE). |
|
Type Management |
|
Set complex instance type as SELECT’s selected type using component parts. Returns true if successful. |
|
Instance Operations |
|
Set SELECT value to instance reference. If 'add inverse' is true, adds inverse relationship. Returns true if successful. |
|
Instance Operations |
|
Add instance reference to SELECT’s aggregate instance values. Returns true if successful. |
|
Special Operations |
|
Set SELECT value to null. Returns true if successful (always true for nullable SELECTs). |
|
Special Operations |
|
Create duplicate of SELECT. Returns detached duplicate. |
|
Special Operations |
|
Detach SELECT from parent buffer. If detachAll is true, also detaches all contained instances and nested SELECTs. Returns true if successful. |
|
Property Access |
|
Get SELECT read-only properties: descriptor, type, selectedTypeName, selectedBaseType, etc. |
Dictionary API Reference
40. Overview
The Dictionary API provides a comprehensive set of tools for working with dictionaries (Map<String, dynamic>) in the PicoSTEP environment. Dictionaries are fundamental data structures used throughout the system for configuration, data exchange, and runtime state management.
40.1. Key Features
-
Type-safe operations with runtime validation
-
JSON interoperability - seamless conversion to/from JSON format
-
Nested path support - access deeply nested values using key paths
-
Dual output generation - supports both JSON (static configuration) and Dart (runtime execution) output formats
-
Dynamic typing - values can be of any type (dynamic), providing maximum flexibility
41. Block Categories
41.1. Dictionary Creation
41.1.1. dictionary_create_empty_dictionary
Creates an empty dictionary as Map<String, dynamic>.
Generated Code: <String, dynamic>{}
Tooltip: create an empty dictionary as a Map<String, dynamic>
41.2. Value Access Operations
41.2.1. dictionary_get_value
Retrieves a value by key with optional default value.
Inputs:
- KEY: String key to lookup
- DICTIONARY: Source dictionary
- DEFAULT: Default value if key not found
Generated Code: (getDictionaryValue(dictionary, key) ?? defaultValue)
Tooltip: Get value for the given key. Returns default value if key not found.
41.2.2. dictionary_get_value_by_path
Retrieves a value using a nested key path (e.g., ['user', 'profile', 'name']).
Inputs:
- KEYPATH: Array of keys for nested access
- DICTIONARY: Source dictionary
- DEFAULT: Default value if path not found
Generated Code: (getDictionaryValueByPath(dictionary, keyPath) ?? defaultValue)
Tooltip: Get value using nested key path (e.g., ['user', 'profile', 'name']). Returns default if path not found.
41.3. Value Modification Operations
41.3.1. dictionary_set_value
Sets or updates a value for a key in the dictionary.
Inputs:
- KEY: String key
- VALUE: Value to set
- DICTIONARY: Target dictionary
Generated Code: setDictionaryValue(dictionary, key, value);
Tooltip: set dictionary value.
41.3.2. dictionary_set_value_by_path
Sets a value using a nested key path, creating intermediate dictionaries if needed.
Inputs:
- KEYPATH: Array of keys for nested access
- VALUE: Value to set
- DICTIONARY: Target dictionary
Generated Code: setDictionaryValueByPath(dictionary, keyPath, value);
Tooltip: Set value using nested key path. Creates intermediate dictionaries if needed.
41.4. Dictionary Inspection
41.4.1. dictionary_is_key_in_dictionary
Checks if a key exists in the dictionary.
Inputs:
- KEY: String key to check
- DICTIONARY: Dictionary to inspect
Generated Code: isKeyInDictionary(dictionary, key)
Tooltip: Check if key exists in dictionary. Returns true if key is present.
41.4.2. dictionary_get_keys_or_values
Retrieves all keys or all values from the dictionary as a list.
Inputs:
- KEYVALUE: Dropdown ("keys" or "values")
- DICTIONARY: Source dictionary
Generated Code: getDictionaryKeys(dictionary) / getDictionaryValues(dictionary)
Tooltip: Get all keys or all values from dictionary as a list.
41.5. Format Conversion
41.6. Type Support
41.6.1. dictionary_user_defined_instance_attribute_value_types
Provides type strings for user-defined instance attributes. Used with dictionary construction for custom entity types.
Inputs:
- TYPE: Dropdown of supported types
Generated Code: "TYPE_STRING" (e.g., "BOOLEAN", "INTEGER", "ENTITY")
Tooltip: Returns type strings for user-defined instance attributes. Use with dictionary construction for defined user customer entity type.
42. Usage Patterns
42.1. Basic Dictionary Creation
create empty dictionary
// Then add key-value pairs
key: "name" value: "John"
key: "age" value: 30
// Result: { "name": "John", "age": 30 }
42.2. Nested Dictionary Access
get value with path key: ['user', 'profile', 'email']
from dictionary: [USER_DATA]
if not found: "[email protected]"
43. Technical Notes
43.1. Dual Generator Architecture
The API supports two output formats through separate generator implementations:
-
JSON Generator (
jsonGenerator !== null): Produces static JSON configuration -
Dart Generator (
jsonGenerator === null): Produces runtime Dart code
43.2. String Handling Utilities
The system uses several utility functions for consistent string formatting:
-
getDartString(): Ensures proper Dart string literal formatting -
replaceQuotes(): Converts single quotes to double quotes for JSON compatibility -
removeParentheses()/removeOuterParentheses(): Cleans expression formatting
44. Best Practices
44.1. Always Check for Existence
is key: "requiredKey" in dictionary: [MY_DICT]
if true
get value with key: "requiredKey" from dictionary: [MY_DICT]
else
// Handle missing key
44.2. Use Default Values
get value with key: "optionalKey"
from dictionary: [MY_DICT]
if not found: "defaultValue"
44.3. Validate JSON Strings
convert json string to dictionary: [JSON_STRING]
is dictionary? [RESULT]
if true
// Use dictionary
else
// Handle parse error
44.4. Path-Based Access for Nested Structures
For deeply nested dictionaries, use path-based access instead of multiple get_value calls:
// Instead of chained gets:
get value with key: "user" from dictionary: [DATA]
get value with key: "profile" from dictionary: [RESULT]
get value with key: "email" from dictionary: [PROFILE]
// Use path-based access:
get value with path key: ['user', 'profile', 'email'] from dictionary: [DATA]
45. Error Handling
46. Performance Considerations
-
Path-based operations are more efficient for deeply nested structures
-
Batch operations (keys/values retrieval) are optimized
-
Inline dictionary creation is preferred for static data
-
Reuse dictionaries when possible instead of creating new ones
47. Integration Examples
48. See Also
-
SELECT API - For working with SELECT objects
-
Instance API - For entity instance manipulation
-
Utility Functions - String formatting and type conversion helpers
|
All dictionary operations are implemented as |
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Dictionary Creation |
|
Create an empty dictionary as a Map<String, dynamic>. |
|
Dictionary Creation |
|
Create an empty dictionary literal with key-value pairs. |
|
Dictionary Creation |
|
Dictionary key and value pair. |
|
Dictionary Creation |
|
Key word constant (as key) for dictionary construction. |
|
Value Access |
|
Get value for the given key. Returns default value if key not found. |
|
Value Access |
|
Get value using nested key path (e.g., ['user', 'profile', 'name']). Returns default if path not found. |
|
Value Modification |
|
Set dictionary value. |
|
Value Modification |
|
Set value using nested key path. Creates intermediate dictionaries if needed. |
|
Value Modification |
|
Remove entry with specified key from dictionary. Returns the removed value. |
|
Value Modification |
|
Remove all entries from dictionary, leaving it empty. |
|
Dictionary Inspection |
|
Get all keys or all values from dictionary as a list. |
|
Dictionary Inspection |
|
Get number of key-value pairs in dictionary. |
|
Dictionary Inspection |
|
Is object a dictionary Map<String, dynamic>? |
|
Format Conversion |
|
Convert json string to dictionary. |
|
Format Conversion |
|
Convert dictionary to JSON string format. |
|
Type Support |
|
Returns FundamentalType string value for user-defined instance attributes. Use with dictionary construction for defined user customer entity type. |
File I/O API Reference
49. Overview
The File I/O API provides a comprehensive set of tools for reading, writing, and manipulating STEP model files in the PicoSTEP environment. This API enables programmatic access to file operations, supporting both CSV (Part 21) and JSON formats for model export and data interchange.
49.1. Key Features
-
Stream-based file operations - Efficient buffered I/O with explicit open/close lifecycle
-
Dual format support - Export models in both CSV (ISO 10303-21) and JSON formats
-
Model-aware operations - Specialized functions for STEP model headers, instances, and reference data
-
Error-safe design - All operations return boolean success indicators
-
Path validation - Automatic folder existence checking for file operations
50. Core Concepts
50.1. PIFileStream
The central object for all file operations. Represents a buffered file stream that must be explicitly opened before use and closed after operations are complete.
51. Block Categories
51.1. Stream Management
51.1.1. file_io_create_stream
Creates a new file stream object for output operations.
Generated Code: PIFileStream()
Tooltip: Create an output file stream for write. Returns PIFileStream object.
51.1.2. file_io_open_stream
Opens a file stream to a specific file location.
Inputs:
- FILESTREAM: PIFileStream object
- FILEPATH: String path to file
Generated Code: stream.open(filepath)
Tooltip: Open the file stream to the given file location. The folder to store the file must exist else open returns false.
51.2. Basic File Operations
51.2.1. file_io_write_string_to_stream
Writes a raw string to an open file stream.
Inputs:
- CONTENT: String content to write
- FILESTREAM: Target file stream
Generated Code: stream.writeString(content)
Tooltip: Write a string to the stream. Returns true if success.
51.2.2. file_io_sort_csv_file_instances
Sorts instances in a CSV (Part 21) file by instance ID.
Inputs:
- INPUTFILE: Path to source CSV file
- OUTPUTFILE: Path for sorted output file
Generated Code: PIFileStream.sortInstancesInFile(inputFile, outputFile)
Tooltip: Sort CSV model (part 21) instances in file in ascending order by id. Returns true if success.
51.3. Model Export Operations
51.3.1. file_io_write_header
Exports model header information to file.
Inputs:
- HEADER: IInstance containing header data
- TYPE: Format (CSV or JSON)
- STREAM: Target file stream
Generated Code: stream.writeInstance(header, ExportFormat.values[type])
Tooltip: Output model header instance to the file stream in the selected format. The output will be either the HEADER section of a part21 file (csv) or header object in JSON. Return true if success.
51.3.2. file_io_write_instance
Exports a single model instance to file.
Inputs:
- INSTANCE: IInstance to export
- TYPE: Format (CSV or JSON)
- STREAM: Target file stream
Generated Code: stream.writeInstance(instance, ExportFormat.values[type])
Tooltip: Output the instance to the file stream in the selected format. Return true if success.
51.4. Reference Model Operations
51.4.1. file_io_write_reference_data_section
Exports reference model data section.
Inputs:
- MODEL: Reference model (PIModel/PIIfcModel/PISTPModel)
- TYPE: Format (CSV or JSON)
- STREAM: Target file stream
- SKIPUPDATE: Boolean to skip updates
Generated Code: model.writeReferenceDataSectionToStream(stream, skipUpdate, ExportFormat.values[type])
Tooltip: Write reference model’s data section to stream. If 'skip update' is true, outputs original unmodified content. Returns true if successful. This API is only available to IReferenceModel.
51.4.2. file_io_write_reference_model_updated_data
Exports reference model change log.
Inputs:
- MODEL: Reference model (PIModel/PIIfcModel/PISTPModel)
- TYPE: Format (CSV or JSON)
- STREAM: Target file stream
Generated Code: model.writeUpdatedDataSectionToStream(stream, ExportFormat.values[type])
Tooltip: Output reference model updates to file stream. Returns true if success.
52. Usage Patterns
52.1. Basic File Write Pattern
create file stream
open file stream: [STREAM] with file path: "/path/to/file.txt"
write string: "Hello, World!" to stream: [STREAM]
flush file stream: [STREAM]
close file stream: [STREAM]
52.2. Model Export Pattern
create file stream
open file stream: [STREAM] with file path: "/output/model.csv"
write header: [HEADER_INSTANCE] as csv to stream: [STREAM]
write instance: [INSTANCE_1] as csv to stream: [STREAM]
write instance: [INSTANCE_2] as csv to stream: [STREAM]
close file stream: [STREAM]
53. Best Practices
53.1. Always Use Proper Lifecycle Management
// ✅ CORRECT: Explicit open/close
create file stream
open file stream: [STREAM] with file path: "file.txt"
// ... operations ...
close file stream: [STREAM]
// ❌ AVOID: Missing close can cause resource leaks
53.2. Check Folder Existence Before Opening
// The open() method will fail if parent folders don't exist
// Ensure directory structure exists before calling open()
54. Error Handling
54.1. Return Value Checking
All File I/O operations return boolean values indicating success. Always check these returns:
create file stream
set [STREAM] to [RESULT]
open file stream: [STREAM] with file path: "/path/file.txt"
if [RESULT]
// Success - continue with operations
else
// Handle error - folder may not exist
55. Performance Considerations
-
Buffer management - Use
flush()judiciously; frequent flushing reduces performance -
Stream reuse - Create stream once and reuse for multiple operations
-
Batch operations - Group writes before flushing for better performance
-
Memory usage - Large files may require streaming approach rather than loading entirely
56. Integration Examples
56.1. Exporting Complete Model
create file stream
open file stream: [STREAM] with file path: "model.json"
write header: [MODEL_HEADER] as json to stream: [STREAM]
for each [INSTANCE] in [MODEL_INSTANCES]
write instance: [INSTANCE] as json to stream: [STREAM]
end
close file stream: [STREAM]
56.2. Data Migration Pipeline
// Convert CSV to JSON format
create file stream
open file stream: [STREAM] with file path: "output.json"
write header: [HEADER] as json to stream: [STREAM]
for each instance in read from: "input.csv"
write instance: [INSTANCE] as json to stream: [STREAM]
end
close file stream: [STREAM]
57. Technical Notes
57.1. Format Mapping
-
CSV =
ExportFormat.values[0] -
JSON =
ExportFormat.values[1]
The dropdown values map directly to the ExportFormat enum indices.
57.2. File Path Requirements
All file paths must: 1. Use forward slashes (/) or platform-appropriate separators 2. Have existing parent directories 3. Be valid for the operating system
57.3. Stream State Management
PIFileStream objects maintain internal state: 1. Created - Object exists but not connected to file 2. Open - Connected to file, ready for operations 3. Closed - Connection terminated, cannot perform operations
|
The |
58. See Also
-
SELECT API - For working with SELECT objects in models
-
Instance API - For creating and manipulating model instances
-
Dictionary API - For configuration and data structures used in file operations
|
Always ensure proper error handling when working with file operations. File system permissions, disk space, and path validity can all cause operations to fail even with correct code logic. |
59. Best Practices
-
Always close streams to prevent resource leaks
-
Check return values - all operations return success booleans
-
Use flush() after critical writes to ensure persistence
-
Verify folder existence before opening files
-
Reference models require IReferenceModel interface
60. Error Handling
-
open()fails if parent folders don’t exist -
Operations return
falseon permission issues -
Reference model operations fail without IReferenceModel interface
|
Format mapping: CSV = |
File I/O API Reference
61. Overview
The File I/O API provides tools for reading, writing, and manipulating STEP model files in PicoSTEP. It supports CSV (Part 21) and JSON formats for model export and data interchange.
62. Core Concepts
PIFileStream: Central object for buffered file operations Export Formats: CSV (0) = ISO 10303-21, JSON (1) = JavaScript Object Notation Lifecycle: create → open → operate → flush/close
63. Block Reference
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Stream Management |
|
Create an output file stream for write. Returns PIFileStream object. |
|
Stream Management |
|
Open the file stream to the given file location. The folder must exist. |
|
Stream Management |
|
Close the file stream. Returns true if success. |
|
Stream Management |
|
Flush the file stream to file system. Return true if success. |
|
Basic Operations |
|
Write a string to the stream. Returns true if success. |
|
Basic Operations |
|
Sort CSV model (part 21) instances in ascending order by id. |
|
Model Export |
|
Output model header instance as CSV (Part 21 HEADER) or JSON header object. |
|
Model Export |
|
Output instance to file stream as CSV Part 21 line or JSON object. |
|
Reference Models |
|
Write reference model’s data section. Skip updates outputs original content. (IReferenceModel only) |
|
Reference Models |
|
Output reference model updates to file stream. |
PicoComposer Utility Blocks API
64. Overview
Utility Blocks provide essential helper functions and operations that complement PicoComposer’s core modeling and instance APIs. These blocks handle common programming tasks, type operations, logging, and utility functions needed in CAD/BIM automation workflows.
|
All utility blocks use the |
65. Block Categories
65.1. Type Operations
Type manipulation and checking blocks for working with PicoComposer’s object system.
65.1.1. Cast Object (utility_object_as)
Casts an object to a specific type using Dart’s as operator.
Inputs:
- OBJECT - Object to cast
- OBJECTTYPE - Target type (dropdown selection)
Output: Cast object of specified type
Example Dart Output:
someObject as PIStore
|
This block may throw |
65.1.2. Check Object Type (utility_object_is)
Checks if an object is of a specific type using Dart’s is operator.
Inputs:
- OBJECT - Object to check
- OBJECTTYPE - Type to check against (dropdown)
Output: Boolean (true if type matches)
Example Dart Output:
someObject is PIProject
65.1.3. Check Null Object (utility_is_null_object)
Checks if an object is null using the NullChecker.isNull() method.
Inputs:
- OBJECT - Object to check
Output: Boolean (true if object is null)
Example Dart Output:
NullChecker.isNull(someObject)
65.1.4. Dynamic Cast Object (utility_cast_object_type)
Casts an object to a dynamically specified type.
Inputs:
- OBJECT - Object to cast
- TYPE - Target type as string
Output: Cast object
Example Dart Output:
someObject as "PIStore"
65.1.5. Dynamic Type Check (utility_is_object_type)
Checks if an object is of a dynamically specified type.
Inputs:
- OBJECT - Object to check
- TYPE - Type to check as string
Output: Boolean (true if type matches)
Example Dart Output:
someObject is "PIStore"
Example Dart Output:
index < FundamentalType.values.length ? FundamentalType.values[index] : FundamentalType.values[0]
|
If index is out of bounds, returns the first enum value (index 0). |
65.2. Function and Method Calling
Blocks for calling functions and object methods.
65.2.1. Call Function (utility_call_function)
Calls a function with optional parameters (void return).
Inputs:
- FUNCTIONNAME - Function name as string
- PARAMETERS - Optional parameters as string expression
Output: Statement (no return value)
Example Dart Output:
someFunction(param1, param2);
65.2.2. Call Function with Return (utility_call_function_with_return)
Calls a function with optional parameters and returns result.
Inputs:
- FUNCTIONNAME - Function name as string
- PARAMETERS - Optional parameters as string expression
Output: Function return value
Example Dart Output:
someFunction(param1, param2)
65.2.3. Call Object Method (utility_call_object_method)
Calls a method on an object (void return).
Inputs:
- FUNCTIONNAME - Method name as string
- OBJECT - Target object
- PARAMETERS - Optional parameters as string expression
Output: Statement
Example Dart Output:
someObject.someMethod(param1, param2);
65.2.4. Call Object Method with Return (utility_call_object_method_with_return)
Calls a method on an object and returns result.
Inputs:
- FUNCTIONNAME - Method name as string
- OBJECT - Target object
- PARAMETERS - Optional parameters as string expression
Output: Method return value
Example Dart Output:
someObject.someMethod(param1, param2)
65.3. Object Property Access
65.3.1. Get Object Property (utility_object_get_property)
Retrieves a property value from an object.
Inputs:
- PROPERTYNAME - Property name as string
- OBJECT - Target object
Output: Property value
Example Dart Output:
someObject.propertyName
65.3.2. Set Object Property (utility_object_set_property)
Sets a property value on an object.
Inputs:
- PROPERTYNAME - Property name as string
- VALUE - Value to set
- OBJECT - Target object
Output: Statement
Example Dart Output:
someObject.propertyName = someValue;
65.4. Logging
65.4.1. Log Message (utility_log_message)
Logs a message to the procedure log file.
Inputs:
- MESSAGE - Message string
Output: Statement
Example Dart Output:
piLogger.d("Some message");
65.4.2. Logger with Level (utility_logger)
Logs a message with specified severity level.
Inputs:
- MESSAGETYPE - Log level (debug, info, warning, error)
- MESSAGE - Message string
Output: Statement
Example Dart Output:
piLogger.e("Error message");
|
Log files are written to |
65.5. Time Utilities
65.6. Math Utilities
65.6.1. Degree to Radian (utility_degree_to_radian)
Converts angle from degrees to radians.
Inputs:
- DEGREEINPUT - Angle in degrees
Output: Number (angle in radians)
Example Dart Output:
(someDegrees * Math.pi) / 180.0
65.6.2. String to 32-bit Hash (utility_string_to_32hash)
Computes unsigned 32-bit hash from string.
Inputs:
- STRING - Input string
Output: Number (hash value)
Example Dart Output:
toTypeId("some string")
65.6.3. Create GUID (utility_get_guid)
Generates a GUID string.
Output: String (GUID)
Example Dart Output:
getGuid()
65.6.4. Map Key-Value Pair (utility_map_int_int_pair)
Creates a key-value pair for Map<int, int> construction.
Inputs:
- KEY - Integer key
- VALUE - Integer value
Output: Statement (pair)
Example Dart Output:
1: 100,
2: 200
|
Use multiple blocks chained together, then collect with a Map constructor block. |
65.7. Code Generation
65.7.1. Inline Code Editor (utility_multiline_field_editor)
Inserts inline Dart code as statement.
Inputs:
- CODE - Multiline code input field
Output: Statement
Example Dart Output:
// User's code directly inserted
someCustomCode();
65.7.2. Inline Code Editor with Return (utility_multiline_field_editor_with_return)
Inserts inline Dart code with return value.
Inputs:
- CODE - Multiline code input field
Output: Code expression result
Example Dart Output:
// User's code directly inserted
someCustomExpression
|
These blocks execute user-provided Dart code directly. Ensure code is from trusted sources as it runs in the Dart VM sandbox. |
66. Best Practices
66.1. Type Safety
-
Use
utility_object_isbeforeutility_object_asfor safe casting -
Check for null objects before property/method access
-
Use Option types (
utility_get_option_value) for nullable values
67. Examples
67.1. Safe Type Checking and Casting
[utility_object_is] -> [If] condition
OBJECT: someObject
OBJECTTYPE: PIStore
[If] true branch -> [utility_object_as]
OBJECT: someObject
OBJECTTYPE: PIStore
[utility_object_as] -> [utility_object_get_property]
PROPERTYNAME: "storeName"
68. Supported Types
The following types are supported in type dropdowns:
-
PIStore, PIProject, ProjectInfo
-
PIModel, PIIfcModel, PISTPModel
-
PITemplateManager, PISchema
-
EntityDescriptor, SelectDescriptor, EnumDescriptor
-
TypeDescriptor, AttributeDescriptor
-
PIFileStream, ModelInfo, Dictionary
-
IInstance, PITemplate, InstanceHandle
-
ISelect, PIEnum, List, Matrix4
-
FundamentalType, SupportedSchema, PIAttributeFlag
69. Compatibility
-
Dart Version: 2.12+ (null-safety)
-
Blockly Version: Compatible with Blockly 9+
-
PicoComposer: Requires PicoComposer API 1.0+
-
INullableObject: All generated code respects null-safety
70. Troubleshooting
71. Glossary
- INullableObject
-
Interface for null-safe objects in PicoComposer system
- Option Type
-
Dart’s functional approach to nullable values
- Record
-
Dart’s lightweight tuple-like structure
- GUID
-
Globally Unique Identifier
- Type Cast
-
Converting an object from one type to another
72. Appendix
72.1. Code Generation Details
All utility blocks generate Dart code that:
-
Respects null-safety principles
-
Uses proper Dart syntax and idioms
-
Includes error prevention checks
-
Is compatible with PicoComposer’s execution environment
72.2. Migration from Previous Versions
If upgrading from older PicoComposer versions:
-
Replace manual type checks with
utility_object_is -
Use
utility_get_option_valuefor Option types -
Update logging to use new logger blocks
-
Review any custom code in multiline editors
Document generated for PicoComposer Utility Blocks API v1.0
| Section | Block Image | Generated Function | Description |
|---|---|---|---|
Type Operations |
|
Check object nullness. Returns true if target is null. |
|
Type Operations |
|
create a empty list of give type. |
|
Type Operations |
|
Cast an object to the given type using the as operator. |
|
Type Operations |
|
Check object type using the is operator. Returns true if type matches. |
|
Type Operations |
|
check object is not of given type. Returns true if object is not the given type. |
|
Function Calling |
|
Call a function with void return. Parameters are optional. |
|
Function Calling |
|
Call a function with return. Parameters are optional. |
|
Function Calling |
|
Call an object method with void return. Parameters are optional. |
|
Function Calling |
|
Call an object method with return value. Parameters are optional. |
|
Object Properties |
|
Get property from object. |
|
Object Properties |
|
Set property for object. |
|
Object Properties |
|
Get ith item from a dart record. |
|
Option Handling |
|
Get value from a dart Option object or returns the provided else value. |
|
Logging |
|
Log debug, info, warning or error message to log file. The logger piLogger is managed by PIComposer dart scripting engine. |
|
Time Utilities |
|
Get time stamp as number. |
|
Time Utilities |
|
Get string time stamp from a number. |
|
Math Utilities |
|
Convert angle measure in degree to radian. |
|
Math Utilities |
|
Compute an unsigned 32 bit hash from string. |
|
GUID Generation |
|
Create guid string. |
|
Map Construction |
|
Key and value for Map<int,int> construction. |
|
Code Generation |
|
Inline user input as code. |
|
Code Generation |
|
Inline user input as code with output. |
|
Documentation |
|
Insert a comment. |