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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

How to get the model from a modelitems using Jlink?

ddhini
15-Moonstone

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.

ACCEPTED SOLUTION

Accepted Solutions
sjuraj
15-Moonstone
(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
15-Moonstone
(To:ddhini)

Are your model items components ?

ddhini
15-Moonstone
(To:sjuraj)

Yes, model items are components
sjuraj
15-Moonstone
(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
15-Moonstone
(To:sjuraj)

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

sjuraj
15-Moonstone
(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.

Announcements


Top Tags