jlink
π―Skillfrom dmdorta1111/jac-v1
Automates Creo Parametric design tasks via Java, enabling programmatic model, feature, assembly, and drawing manipulation through a robust session-based API.
Installation
npx skills add https://github.com/dmdorta1111/jac-v1 --skill jlinkSkill Details
>
Overview
# Jlink - Java Automation Toolkit for Creo Parametric
Jlink (Object TOOLKIT Java) is a free Java API that enables programmatic automation of Creo Parametric design tasks. It provides Session-based access to models, features, parameters, assemblies, and drawings.
Quick Start
New to Jlink? Start here:
- Read Architecture Overview below
- Study Basic Patterns for initialization
- Review Common Tasks Decision Tree
- Check Reference Guide for specific operations
Core Concepts
Session Model (Entry Point)
All Jlink operations flow through a single Session object:
```java
// Get active session (main pattern)
Session session = pfcSession.GetCurrentSessionWithCompatibility(
CreoCompatibility.C4Compatible
);
// Now use session for all operations
Model model = session.RetrieveModel(descriptor);
```
Exception Handling (Universal)
All Jlink methods throw jxthrowable:
```java
try {
// Any Jlink operation
Model model = session.RetrieveModel(descriptor);
Feature feat = model.GetFeatureByName("MY_FEATURE");
} catch (jxthrowable x) {
x.printStackTrace();
// Handle error
}
```
Object Hierarchy
```
Session (connection to Creo)
βββ Model (Part, Assembly, or Drawing)
β βββ FeatureTree (all features)
β βββ ParameterTable (model parameters)
β βββ Drawing-specific (sheets, views, notes)
βββ UICommand (menu/toolbar integration)
βββ Selection (interactive user selection)
```
Architecture Overview
Packages (20+ modules, but focus on core 6)
| Package | Purpose | Key Classes |
|---------|---------|------------|
| pfcSession | Session management | Session, Selection, UICommand |
| pfcModel | Models (parts, assemblies, drawings) | Model, ModelDescriptor, ModelType |
| pfcFeature | Feature creation & manipulation | Feature, FeatureCreate, FeatureType |
| pfcParameter | Parameters & dimensions | Parameter, ParamValue, DimensionType |
| pfcGeometry | Geometry operations | Point, Vector, Transform |
| pfcAsyncConnection | Async/remote operations | AsyncConnection, AsyncServer |
Session Lifecycle
```java
// 1. Retrieve session (usually already exists)
Session session = pfcSession.GetCurrentSessionWithCompatibility(
CreoCompatibility.C4Compatible
);
// 2. Work with models/features/parameters
try {
// Do work
} catch (jxthrowable x) {
// Handle errors
}
// 3. Cleanup (usually automatic in application context)
// No explicit disconnect needed for current session
```
Basic Patterns
1. Model Operations
Retrieve existing model:
```java
// By name and type
ModelDescriptor descr = pfcModel.ModelDescriptor_Create(
ModelType.MDL_PART,
"my_part",
null // No directory
);
Model model = session.RetrieveModel(descr);
// Get current model in Creo
Model current = session.GetCurrentModel();
```
Create/save model:
```java
ModelDescriptor descr = pfcModel.ModelDescriptor_Create(
ModelType.MDL_PART,
"new_part",
null
);
Model newModel = session.CreateModel(descr, null);
// Save to working directory
newModel.Save(); // or SaveAs(descriptor)
```
Model types:
ModelType.MDL_PART- Part fileModelType.MDL_ASSEMBLY- Assembly fileModelType.MDL_DRAWING- Drawing file
2. Feature Access & Creation
Get feature by name:
```java
try {
Feature feat = model.GetFeatureByName("EXTRUDE_1");
} catch (jxthrowable x) {
// Feature not found
}
```
Iterate features:
```java
FeatureTree featTree = model.GetFeatureTree();
Sequence
for (int i = 0; i < features.GetMembersCount(); i++) {
Feature f = features.GetMember(i);
// Process feature
}
```
Create feature (example: extrude):
```java
FeatureCreateData createData = pfcFeature.FeatureCreate_Create(
FeatureType.EXTRUDE,
ModelRef.CURRENT, // Current model
"", null, null
);
// Set extrude depth
createData.SetIntParam("depth_type", 1); // ONE_SIDED
createData.SetDoubleParam("depth_1", 10.0); // 10 units
// Create and return feature
Feature newFeat = model.CreateFeature(createData);
```
3. Parameter Operations
Get parameter value:
```java
try {
Parameter param = model.GetParam("THICKNESS");
ParamValue val = param.GetValue();
double thickness = val.GetDoubleValue();
} catch (jxthrowable x) {
// Parameter not found
}
```
Set parameter value:
```java
Parameter param = model.GetParam("THICKNESS");
ParamValue newVal = pfcParameter.ParamValue_CreateDoubleParamValue(2.5);
param.SetValue(newVal);
```
Model parameters:
```java
// Get all parameters
ParameterTable paramTable = model.GetParameters();
Sequence
for (int i = 0; i < params.GetMembersCount(); i++) {
Parameter p = params.GetMember(i);
// Access param
}
```
4. Interactive Selection
Get user selection:
```java
UICommand cmd = session.UICreateCommand("custom.select", selectionListener);
// Selection types
SelectionOptions opts = pfcSelection.SelectionOptions_Create();
opts.AddFilterType(SelectionType.EDGE); // Allow edge selection
opts.SetMaxSelectCount(5); // Max 5 edges
Selection selection = session.UISelect(opts, null);
```
Process selections:
```java
int count = selection.GetSelectionCount();
for (int i = 0; i < count; i++) {
SelectedObject selObj = selection.GetSelectionItem(i);
GeometryType geomType = selObj.GetSelectionType();
// Use selected geometry
}
```
5. Assembly Operations
Add component:
```java
ModelDescriptor compDescr = pfcModel.ModelDescriptor_Create(
ModelType.MDL_PART,
"component_name",
null
);
ComponentFeat compFeat = (ComponentFeat)model.CreateFeature(
pfcFeature.FeatureCreate_Create(
FeatureType.COMPONENT,
ModelRef.CURRENT,
"", compDescr, null
)
);
```
Apply constraints:
```java
Constraint constraint = pfcConstraint.Constraint_CreateMateConstraint(
surfaceRef1, // First reference
surfaceRef2 // Second reference
);
model.AddConstraint(constraint);
```
6. Drawing Automation
Create drawing view:
```java
// Open template or create drawing
ModelDescriptor drawDescr = pfcModel.ModelDescriptor_Create(
ModelType.MDL_DRAWING,
"drawing_name",
null
);
Model drawing = session.CreateModel(drawDescr, null);
// Add view (simplified)
DrawingSheet sheet = drawing.GetCurrentSheet();
DrawingView view = sheet.CreateGeneralView(modelRef, viewData);
```
Common Tasks Decision Tree
Choose task β find reference file β implement pattern
Model Management
- Open/retrieve model β
session.RetrieveModel(descriptor) - Create new model β
session.CreateModel(descriptor, null) - Save model β
model.Save()ormodel.SaveAs(descriptor) - Check if modified β
model.GetModified()β bool
Feature Operations
- Get feature by name β
solid.GetFeatureByName(name) - Iterate all features β
solid.ListFeaturesByType(true, null) - Create feature β
solid.CreateFeature(FeatureCreateInstructions) - Delete feature β
feature.CreateDeleteOp()then execute - Get feature dimensions β
feature.ListSubItems(ITEM_DIMENSION)(returns ModelItems)
Parameters
- Get parameter β
model.GetParam(name)βGetValue() - Set parameter β
param.SetValue(newValue) - List all parameters β
model.GetParameters().GetParams() - Create parameter β
model.AddParam()
Assembly
- Add component β Feature creation with
FeatureType.FEATTYPE_COMPONENT - Apply constraint β
componentFeat.SetConstraints(constraints, path) - List components β
solid.ListFeaturesByType(true, FeatureType.FEATTYPE_COMPONENT) - Get subassembly β
componentFeat.GetModelDescr()βsession.RetrieveModel()
Interactive Selection
- Select edges β
SelectionOptions.AddFilterType(SelectionType.EDGE) - Select surfaces β
SelectionOptions.AddFilterType(SelectionType.SURFACE) - Get selected geometry β
selection.GetSelectionItem(i)β process
Drawing
- Create view β
sheet.CreateGeneralView(modelRef, viewData) - Add note/dimension β
sheet.CreateGeneralNote(position, text) - Export/print β Drawing-specific APIs
- Get sheets β
drawing.GetDrawingSheets()
Best Practices
- Always use try-catch - All Jlink operations throw
jxthrowable - Validate model type before specific operations (part vs assembly vs drawing)
- Regenerate after changes -
model.Regenerate()for feature/parameter changes - Check references validity - Geometry handles may become invalid after regen
- Batch operations - Group model open/close for efficiency
- Session reuse - Don't create new sessions; reuse
GetCurrentSessionWithCompatibility() - Clear resources - Free large collections/selections after use
- Log operations - Essential for debugging batch/async processes
- Handle missing features - Wrap feature access in try-catch
- Test with actual model - Jlink behavior varies by Creo configuration
Reference Files
For detailed information, see:
- jlink-session.md - Session creation, lifecycle, compatibility modes
- jlink-models.md - Model operations (open, create, save, properties)
- jlink-features.md - Feature creation, types, dimension manipulation
- jlink-parameters.md - Parameter access, modification, validation
- jlink-assembly.md - Assembly operations, constraints, components
- jlink-drawing.md - Drawing automation, views, sheets, export
- jlink-selection.md - Interactive selection, geometry types, filters
- jlink-patterns.md - Complete end-to-end workflow patterns
- jlink-error-handling.md - Exception strategies, recovery, logging
- jlink-performance.md - Optimization techniques, caching, async patterns
Installation & Setup
Prerequisites:
- Creo 4.0+ with J-Link/OTK selected during installation
- Java 21+ JDK for Creo 12.4+ (class file version 65.0)
- IDE: Eclipse, IntelliJ, or VS Code
CLASSPATH configuration (Creo 12.4+):
```
${CREO_HOME}/Common Files/text/java/otk.jar
${CREO_HOME}/Common Files/text/java/pfcasync.jar
```
CLASSPATH configuration (Creo 4.0-11.x):
```
${CREO_HOME}/Common Files/otk_java_free/*.jar
```
Application registration (jlink.txt):
```
DESCRIPTION=MyApp
STARTUP=DLL
JAVA_MAIN_CLASS=com.mycompany.MyApp
JLINK_VERSION=11.0
CLASSPATH=MyApp.jar
```
Common Use Cases
Batch Model Modification:
- Get session
- For each model: RetrieveModel() β modify parameters β Regenerate() β Save()
Assembly Generation from Data:
- Create base assembly
- For each component: AddFeature(COMPONENT) β ApplyConstraints()
- Save assembly
Feature Extraction for CAM:
- Get model
- Iterate features by type
- Extract geometry references
- Generate NC code or CNC path data
Parameter-Driven Design:
- Get session
- Modify model parameters
- Regenerate model
- Extract modified geometry
- Generate drawings/exports
UI Integration:
- Create UICommand
- Register in menu/toolbar
- Handle selection via SelectionListener
- Apply changes to model
Creo 12.4 API Quick Reference
Verified Methods (from JAR analysis)
| Interface | Method | Returns | Description |
|-----------|--------|---------|-------------|
| Session | GetCurrentDirectory() | String | Current working dir |
| Session | GetActiveModel() | Model | Current active model |
| Session | RetrieveModel(ModelDescriptor) | Model | Open model |
| Model | GetFullName() | String | Full model path |
| Model | GetFileName() | String | File name only |
| Model | GetType() | ModelType | MDL_PART/MDL_ASSEMBLY |
| Model | ListParams() | Parameters | All parameters |
| Solid | ListFeaturesByType(Boolean, FeatureType) | Features | Get features |
| Solid | GetFeatureByName(String) | Feature | Get single feature |
| Solid | GetPrincipalUnits() | UnitSystem | Unit system |
| Feature | GetName() | String | Feature name |
| Feature | GetFeatType() | FeatureType | Feature type |
| Feature | GetStatus() | FeatureStatus | SUPPRESSED/ACTIVE/etc |
| Feature | ListSubItems(ModelItemType) | ModelItems | Get dimensions etc |
| Feature | ListChildren() | Features | Dependent features |
| BaseDimension | GetDimValue() | double | Dimension value |
| BaseDimension | SetDimValue(double) | void | Set dimension |
| ComponentFeat | GetModelDescr() | ModelDescriptor | Component model |
| Parameter | GetValue() | ParamValue | Parameter value |
| ParamValue | GetDoubleValue() | Double | Numeric value |
| ParamValue | GetStringValue() | String | String value |
Non-Existent Methods (Common Mistakes)
| Wrong Method | Correct Alternative |
|--------------|---------------------|
| session.IsAlive() | Try-catch GetCurrentDirectory() |
| session.GetWorkingDirectory() | GetCurrentDirectory() |
| session.UISetComputeMode() | Not available in Creo 12.4 |
| model.GetModelName() | GetFullName() or GetFileName() |
| feat.GetSuppressed() | GetStatus() == FEAT_SUPPRESSED |
| feat.GetFailed() | GetStatus() == FEAT_UNREGENERATED |
| feat.ListDimensions() | ListSubItems(ITEM_DIMENSION) |
| dim.GetValue() | GetDimValue() (BaseDimension) |
| compFeat.GetModelDescriptor() | GetModelDescr() |
| model.GetUnitsystem() | Solid.GetPrincipalUnits() |
Unresolved Questions
- Async connection best practices for distributed teams
- Performance optimization for large assemblies (100+ components)
- Integration patterns with SmartAssembly scripting workflow