Table of Contents
1. Overview
1.1 Purpose
Utility module for RecurDyn Python ProcessNet automation with common functions for simulation setup.
1.2 Global Variables
•
Simulation Model Management:
◦
simModelName: The current model’s name → Active simulation model identifier.
◦
application: RecurDyn application (IApplication).
◦
modelDocument: Active model document (IModelDocument).
◦
plotDocument: Active plot document (IPlotDocument).
•
Directory Structure:
◦
inputFolder: Input data directory path.
◦
simResultsFolder: Simulation results storage directory.
◦
RDModelPath: RecurDyn model file (.rdyn) path.
•
Reference Frames:
◦
refFrame1, refFrame2: Reference frame objects for coordinate (IReferenceFrame).
1.3 Primary Functions
•
Initialize(): System initialization and environment setup.
◦
Returns: Tuple of initialized objects and paths.
•
Dispose(application, modelDocument): Clean shutdown and model finalization.
◦
Returns: Updated application and model document objects.
•
ValidationCheckAndUpateModelDocument(modelDocument): Model integrity verification and UI synchronization.
◦
Returns: Validated model document.
•
ReadInputData(inputFolder, partName, dataPath): Generic data file reader for simulation inputs.
◦
Returns: 2D list of numerical data.
•
CreateMotionExpressionWithCSV(model, inputFolder, partName, entityName, dataPath): Generation of motion expression entity with spline entity using CSV data.
◦
Returns: Updated model and expression entity.
2. Initialize()
See Script
2.1 Purpose
•
Primary Function: Initializes global variables and establishes RecurDyn application connection before ProcessNet execution.
•
Critical Role: Prepares all necessary interfaces and paths for RecurDyn model operations.
2.2 Input
•
Parameters: No input parameters required
•
Dependencies:
◦
RecurDyn application installation
◦
Predefined directory structure with Simulation_Model folder
◦
Current_RDModel_Name.dat file containing model name
◦
Existing RecurDyn model file (.rdyn) or capability to create new model
2.3 Output
•
Return Type: Tuple with 9 elements
•
Return Structure: (simModelName, application, modelDocument, model, inputFolder, simResultsFolder, RDModelPath, refFrame1, refFrame2)
•
Return Components:
◦
simModelName: String identifier for current simulation
◦
application: RecurDyn application interface object (IApplication)
◦
modelDocument: Active model document interface (IModelDocument)
◦
model: Subsystem model interface (ISubSystem)
◦
inputFolder: Complete path to input data directory
◦
simResultsFolder: Complete path to simulation results directory
◦
RDModelPath: Complete path to RecurDyn model file
◦
refFrame1: First reference frame interface object (IReferenceFrame)
◦
refFrame2: Second reference frame interface object (IReferenceFrame)
2.4 Workflow
1.
Working Directory Setup
•
Determines parent directory of current script location using os.path.
•
Constructs absolute path to simulation workspace.
•
Builds path to Current_RDModel_Name.dat configuration file.
•
Reads simulation model name from configuration file.
•
Constructs complete simulation model folder path.
2.
Path Configuration
•
Input Folder: {workingFolder}\Simulation_Model\{simModelName}\Input.
•
Results Folder: {workingFolder}\Simulation_Model\{simModelName}\Simulation_Results.
•
Model File: {workingFolder}\Simulation_Model\{simModelName}\{simModelName}.rdyn.
3.
RecurDyn Application Interface
•
Dispatches RecurDyn application instance via dispatch_recurdyn().
•
Creates IApplication interface wrapper.
•
Opens specified model document using constructed .rdyn path.
•
Establishes active model document reference.
•
Wraps model document in IModelDocument interface.
•
Creates ISubSystem interface for model operations.
•
Establishes active plot document reference with IPlotDocument wrapper.
4.
Error Handling & Recovery
•
Missing Model Document Check: Validates existence of active model document.
•
Missing Plot Document Check: Validates existence of active plot document.
•
Error Message: Prints "No Simulation Model File !" if both documents are missing.
•
Automatic Recovery: Creates new model document with specified name if none exists.
•
Interface Re-wrapping: Ensures proper COM interface encapsulation after recovery.
5.
Reference Frame Creation
•
Instantiates first reference frame via modelDocument.CreateReferenceFrame().
•
Wraps first frame in IReferenceFrame interface.
•
Instantiates second reference frame via modelDocument.CreateReferenceFrame().
•
Wraps second frame in IReferenceFrame interface.
•
Prepares coordinate system foundation for geometric calculations.
6.
Return Value Assembly
•
Assembles all initialized variables into tuple structure.
•
Returns complete set of interfaces and paths for subsequent ProcessNet operations.
•
Ensures global variable accessibility throughout module scope.
3. Dispose(application, modelDocument)
See Script
3.1 Purpose
•
Primary Function: Finalizes and updates model document after ProcessNet function execution.
•
Critical Role: Ensures model consistency and saves modification history for undo operations.
3.2 Input
•
Parameters:
◦
application: RecurDyn application interface object (IApplication).
◦
modelDocument: Model document interface object (IModelDocument).
•
Dependencies:
◦
Active RecurDyn application instance.
◦
Valid model document with potential modifications from ProcessNet operations.
3.3 Output
•
Return Type: Tuple with 2 elements.
•
Return Structure: (application, modelDocument).
•
Return Components:
◦
application: Updated RecurDyn application interface object.
◦
modelDocument: Validated and updated model document interface.
•
Side Effects:
◦
Model document validation and redraw operations.
◦
Database window updates and modification flags set.
◦
Undo history entry creation.
3.4 Workflow
1.
Active Model Document Retrieval
•
Retrieves active model document from application interface.
•
Wraps retrieved document in IModelDocument interface.
•
Performs null check for document existence.
•
Returns early if no active document is found.
2.
Model Validation Check
•
Executes model validation using modelDocument.Validate() method.
•
Checks for model integrity and consistency issues.
•
Returns early if validation fails to prevent further operations.
•
Ensures model is in valid state before updates.
3.
Model Document Update Operations
•
Executes modelDocument.Redraw() to refresh visual representation.
•
Updates database window using modelDocument.UpdateDatabaseWindow().
•
Sets modification flag using modelDocument.SetModified().
•
Records undo history entry with "Python ProcessNet" description.
4.
Return Value Assembly
•
Assembles updated application and model document interfaces.
•
Returns tuple containing both updated interface objects.
•
Ensures proper interface state for subsequent operations.
4. ValidationCheckAndUpateModelDocument(modelDocument)
See Script
4.1 Purpose
•
Primary Function: Validates model integrity and updates model document components.
•
Critical Role: Maintains model state integrity during intermediate processing steps.
4.2 Input
•
Parameters:
◦
modelDocument: Model document interface object (IModelDocument).
•
Dependencies:
◦
Valid model document interface with potential modifications.
◦
Active RecurDyn model with accessible validation methods.
4.3 Output
•
Return Type: Single object.
•
Return Structure: modelDocument.
•
Return Components:
◦
modelDocument: Validated and updated model document interface.
•
Side Effects:
◦
Model validation execution and error checking.
◦
Visual redraw operations and database window updates.
◦
Modification flag setting for document state tracking.
4.4 Workflow
1.
Model Validation Execution
•
Executes model validation using modelDocument.Validate() method.
•
Checks for model integrity, consistency, and constraint violations.
•
Identifies potential geometric or kinematic issues in model structure.
•
Ensures model components are properly defined and connected.
2.
Visual Representation Update
•
Executes modelDocument.Redraw() to refresh graphical display.
•
Updates all visual elements including bodies, joints, and forces.
•
Refreshes viewport rendering and geometric representations.
•
Ensures visual consistency with current model state.
3.
Database Window Synchronization
•
Updates database window using modelDocument.UpdateDatabaseWindow().
•
Synchronizes entity tree with current model structure.
•
Refreshes property panels and component listings.
•
Ensures database view reflects all model modifications.
4.
Document State Management
•
Sets modification flag using modelDocument.SetModified().
•
Marks document as changed for save operations.
•
Updates document status indicators in user interface.
•
Prepares document for potential save or export operations.
5.
Return Value Assembly
•
Returns updated model document interface object.
•
Ensures proper interface state for subsequent operations.
•
Maintains interface consistency for continued processing.
5. ReadInputData(inputFolder, partName, dataPath)
See Script
5.1 Purpose
•
Primary Function: Reads and parses numerical data from text files in the input directory structure.
•
Critical Role: Provides standardized data input interface for RecurDyn simulation parameters.
5.2 Input
•
Parameters:
◦
inputFolder: Complete path to input data directory (string).
◦
partName: Specific part subdirectory name (string or None).
◦
dataPath: Relative path to data file within directory structure (string).
•
Dependencies:
◦
Existing input folder structure with proper file organization.
◦
Valid text files containing space-separated numerical data.
◦
Readable file permissions for specified data files.
5.3 Output
•
Return Type: List of lists.
•
Return Structure: data.
•
Return Components:
◦
data: Two-dimensional list containing numerical values from input file.
◦
Each inner list represents one row of data from the input file.
◦
All values are converted to numpy double precision format.
•
Data Format:
◦
Outer list contains rows, inner lists contain column values.
◦
All string values converted to floating-point numbers.
5.4 Workflow
1.
Input Path Construction
•
Checks if partName parameter is provided (not None).
•
Constructs full file path using inputFolder + '\' + partName + '\' + dataPath if part-specific.
•
Constructs direct path using inputFolder + '\' + dataPath if general input file.
•
Creates complete absolute path to target data file.
2.
File Reading and Initial Processing
•
Opens specified file using built-in open() function.
•
Reads all lines from file using readlines() method.
•
Strips whitespace from each line using strip() method.
•
Splits each line into individual elements using split() method.
•
Creates list comprehension structure for efficient data processing.
3.
Data Structure Analysis
•
Determines total number of data rows using len(dataSet).
•
Initializes empty data list for numerical conversion results.
•
Prepares loop structure for row-by-row processing.
4.
Numerical Conversion Process
•
Iterates through each row in the dataset using range loop.
•
Converts each string element to numpy double precision using np.double().
•
Appends converted numerical list to main data structure.
•
Maintains row order and column structure from original file.
5.
Return Value Assembly
•
Returns complete two-dimensional numerical data structure.
•
Ensures all values are in proper floating-point format.
•
Provides ready-to-use data array for simulation input parameters.
6. CreateMotionExpressionWithCSV(model, inputFolder, partName, entityName, dataPath)
See Script
6.1 Purpose
•
Primary Function: Creates time-based motion expressions using CSV data files for RecurDyn simulations.
•
Critical Role: Provides interface between external motion data and RecurDyn's AKISPL interpolation system.
6.2 Input
•
Parameters:
◦
model: RecurDyn model interface object (ISubSystem).
◦
inputFolder: Complete path to input data directory (string).
◦
partName: Specific part subdirectory name (string).
◦
entityName: Base name for spline and expression entities (string).
◦
dataPath: Relative path to CSV file within part directory (string).
•
Dependencies:
◦
Valid RecurDyn model with entity creation capabilities.
◦
Existing CSV file with time-based motion data.
◦
Proper file permissions for CSV file access.
6.3 Output
•
Return Type: Tuple with 2 elements.
•
Return Structure: (model, EX_data).
•
Return Components:
◦
model: Updated RecurDyn model interface object with new/modified entities.
◦
EX_data: Expression entity interface object (IExpression) containing AKISPL function.
•
Side Effects:
◦
Creation or update of spline entity in RecurDyn model.
◦
Creation or update of expression entity with time-based interpolation.
◦
Model database updates with new motion definition entities.
6.4 Workflow
•
CSV File Path Construction
◦
Constructs complete CSV file path using input parameters.
◦
Combines inputFolder, partName, and dataPath with backslash separators.
◦
Creates absolute path reference for spline entity file association.
◦
Stores path in CSVPath variable for subsequent entity operations.
•
Spline Entity Management
◦
Searches for existing spline entity using naming convention 'SP_' + entityName.
◦
Creates new spline entity with CSV file if none exists using CreateSplineWithFile() method.
◦
Wraps new spline in ISpline interface for proper entity management.
◦
Updates existing spline's file reference using FileName property if entity already exists.
•
Expression Entity Management
◦
Searches for existing expression entity using naming convention 'EX_' + entityName.
◦
Creates new expression entity if none exists using CreateExpression() method.
◦
Defines AKISPL interpolation function with time variable and spline reference.
◦
Updates existing expression's formula using Text property if entity already exists.
•
AKISPL Function Configuration
◦
Constructs AKISPL function string with standard parameters.
◦
Uses time as independent variable for motion interpolation.
◦
Sets derivative order to 0 for position-based interpolation.
◦
References spline entity by name for data source linkage.
◦
Configures interpolation mode parameter to 0 for standard operation.
•
Return Value Assembly
◦
Returns updated model interface with new motion entities.
◦
Returns expression entity interface for direct access to motion function.
◦
Ensures proper entity linkage between spline data and expression evaluation.