Skip to main content
1-Visitor
Aug 7, 2017 4:49 AM UTC
Solved

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.

sjurajAnswer
15-Moonstone
Aug 7, 2017 8:11 AM UTC

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);
}

5 replies

15-Moonstone
Aug 7, 2017 7:34 AM UTC

Are your model items components ?

Translate
ddhini1-VisitorAuthor
1-Visitor
Aug 7, 2017 7:49 AM UTC
Yes, model items are components
Translate
sjuraj15-MoonstoneAnswer
15-Moonstone
Aug 7, 2017 8:11 AM UTC

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);
}

Translate