Skip to main content
1-Visitor
August 7, 2017
Solved

How to get the model from a modelitems using Jlink?

  • August 7, 2017
  • 1 reply
  • 3312 views

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.

Best answer by sjuraj

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

1 reply

15-Moonstone
August 7, 2017

Are your model items components ?

ddhini1-VisitorAuthor
1-Visitor
August 7, 2017
Yes, model items are components
sjuraj15-MoonstoneAnswer
15-Moonstone
August 7, 2017

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