jlink
Java automation toolkit for Creo Parametric (J-Link/Object TOOLKIT Java). Use when users ask about: writing Jlink applications, Session management, model/feature/parameter operations, interactive selection, assembly automation, drawing generation, UI/menu integration, batch processing, error handling, performance optimization, or any programmatic Creo design automation via Java.
When & Why to Use This Skill
This Claude skill serves as a specialized technical assistant for Jlink (Object TOOLKIT Java), the automation framework for Creo Parametric. It provides comprehensive guidance on programmatically managing CAD models, features, and assemblies, helping developers implement robust session management, interactive selections, and drawing automation while adhering to Java best practices and Creo-specific API patterns.
Use Cases
- Batch Model Modification: Automating the update of parameters, dimensions, and features across hundreds of part files to ensure design consistency.
- Automated Assembly Generation: Programmatically building complex assemblies by adding components and applying constraints based on external configuration data.
- Engineering Drawing Automation: Streamlining the creation of drawing sheets, views, and annotations to reduce manual drafting effort and human error.
- Custom UI Integration: Developing bespoke menus, toolbars, and interactive selection tools within the Creo Parametric environment to enhance engineering workflows.
- Design-to-Manufacturing Data Extraction: Programmatically extracting geometric data and metadata for downstream use in CAM, CAE, or ERP systems.
| name | jlink |
|---|---|
| description | > |
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:
// 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:
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
// 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:
// 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:
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:
try {
Feature feat = model.GetFeatureByName("EXTRUDE_1");
} catch (jxthrowable x) {
// Feature not found
}
Iterate features:
FeatureTree featTree = model.GetFeatureTree();
Sequence<Feature> features = featTree.GetFeatures();
for (int i = 0; i < features.GetMembersCount(); i++) {
Feature f = features.GetMember(i);
// Process feature
}
Create feature (example: extrude):
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:
try {
Parameter param = model.GetParam("THICKNESS");
ParamValue val = param.GetValue();
double thickness = val.GetDoubleValue();
} catch (jxthrowable x) {
// Parameter not found
}
Set parameter value:
Parameter param = model.GetParam("THICKNESS");
ParamValue newVal = pfcParameter.ParamValue_CreateDoubleParamValue(2.5);
param.SetValue(newVal);
Model parameters:
// Get all parameters
ParameterTable paramTable = model.GetParameters();
Sequence<Parameter> params = paramTable.GetParams();
for (int i = 0; i < params.GetMembersCount(); i++) {
Parameter p = params.GetMember(i);
// Access param
}
4. Interactive Selection
Get user selection:
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:
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:
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:
Constraint constraint = pfcConstraint.Constraint_CreateMateConstraint(
surfaceRef1, // First reference
surfaceRef2 // Second reference
);
model.AddConstraint(constraint);
6. Drawing Automation
Create drawing view:
// 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