cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How to get the model from a modelitems using Jlink?

ddhini
14-Alexandrite

How to get the model from a modelitems using Jlink?

I have a model in my session.Using ModelItems i Sent my model into modelitems and get the Id of features.

Session session=pfcGlobal.GetProESession();
//GET MODEL
Model mod=session.GetCurrentModel();
ModelItems item;
item=mod.ListItems(ModelItemType.ITEM_FEATURE);

I get all the Id's inside a model.Now What i want,Access each model based on the Id using Jlink program.Please help me to solve my problem.

1 ACCEPTED SOLUTION

Accepted Solutions
sjuraj
13-Aquamarine
(To:ddhini)

You do not have to list ModelItems, you can directly list components. This code will add models in your assembly to Models object: 

 

Assembly asm = (Assembly) session.GetActiveModel();
Features components = asm.ListFeaturesByType(null, FeatureType.FEATTYPE_COMPONENT);
Models models = Models.create();
for(int i = 0; i < components.getarraysize(); i++) {
ComponentFeat component = (ComponentFeat) components.get(i);
ModelDescriptor md = component.GetModelDescr();
Model model = session.GetModelFromDescr(md);
models.append(model);
}

View solution in original post

5 REPLIES 5
sjuraj
13-Aquamarine
(To:ddhini)

Are your model items components ?

ddhini
14-Alexandrite
(To:sjuraj)

Yes, model items are components
sjuraj
13-Aquamarine
(To:ddhini)

You do not have to list ModelItems, you can directly list components. This code will add models in your assembly to Models object: 

 

Assembly asm = (Assembly) session.GetActiveModel();
Features components = asm.ListFeaturesByType(null, FeatureType.FEATTYPE_COMPONENT);
Models models = Models.create();
for(int i = 0; i < components.getarraysize(); i++) {
ComponentFeat component = (ComponentFeat) components.get(i);
ModelDescriptor md = component.GetModelDescr();
Model model = session.GetModelFromDescr(md);
models.append(model);
}

ddhini
14-Alexandrite
(To:sjuraj)

Thanku sjuraj ,How to access the model by its id ?

sjuraj
13-Aquamarine
(To:ddhini)

I think this is not possible to get model by id https://community.ptc.com/t5/Additional-Creo-Questions/How-to-get-session-id-of-a-model-using-toolkit/td-p/101410

 

To access model use ModelDescriptor instead. It is more complex and built for handling models.

Top Tags