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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

j-link assembly components

MarcioGarcia-di
1-Visitor

j-link assembly components

Hi everybody,

I was trying to use j-link to assembly a componet using csys references. But I got some problems.

I appreciate if everyone can help me.

would like to know how can I assembly a component model like a part
in a sub-assembly using csys as reference.

I have a main assembly and a sub-assembly. So I have to assembly a componet
in the sub-assembly using csys references from the main assembly.

Tree:

Main_Assembly.asm

mainCSYS

Part1.prt
partCSYS1
partCSYS2

SubAssembly.asm 
subassyCSYS
NEW_Assymbly_Part.prt
newpartCSYS


I have to assembly the NEW_Assymbly_Part.prt in the assembly
SubAssembly using as Componet Reference the csys newpartCSYS
(in SubAssembly) and using as Assembly Reference the csys partCSYS2;

Please, How can I do this with j-link.

import com.ptc.cipjava.intseq;
import com.ptc.cipjava.jxthrowable;
import com.ptc.pfc.pfcAssembly.Assembly;
import com.ptc.pfc.pfcAssembly.ComponentPath;
import com.ptc.pfc.pfcAssembly.ExplodedState;
import com.ptc.pfc.pfcAssembly.pfcAssembly;
import com.ptc.pfc.pfcCommand.DefaultUICommandActionListener;
import com.ptc.pfc.pfcComponentFeat.ComponentConstraint;
import com.ptc.pfc.pfcComponentFeat.ComponentConstraintType;
import com.ptc.pfc.pfcComponentFeat.ComponentConstraints;
import com.ptc.pfc.pfcComponentFeat.ComponentFeat;
import com.ptc.pfc.pfcComponentFeat.pfcComponentFeat;
import com.ptc.pfc.pfcGlobal.pfcGlobal;
import com.ptc.pfc.pfcModel.Model;
import com.ptc.pfc.pfcModel.ModelDescriptor;
import com.ptc.pfc.pfcModel.ModelType;
import com.ptc.pfc.pfcModel.pfcModel;
import com.ptc.pfc.pfcModelItem.ModelItem;
import com.ptc.pfc.pfcModelItem.ModelItemType;
import com.ptc.pfc.pfcModelItem.ParamValue;
import com.ptc.pfc.pfcSelect.Selection;
import com.ptc.pfc.pfcSelect.pfcSelect;
import com.ptc.pfc.pfcSession.Session;
import com.ptc.pfc.pfcSolid.Solid;

class MenuButtonListener extends DefaultUICommandActionListener {

 static String title = "Editor de Parametro";
 ParamValue valor;

 @Override
 public void OnCommand() {
 try {
 montarComponente("part.prt");
 } catch (jxthrowable x) {
 x.printStackTrace();
 System.out.println("------------------------------------");
 }

 }

 public void montarComponente(String componentFilename) throws jxthrowable {

 Session session = pfcGlobal.GetProESession();

 ModelDescriptor descrFrom = pfcModel.ModelDescriptor_CreateFromFileName("montagem.asm");
 Model modelFrom = (Model) session.GetModelFromDescr(descrFrom);
 modelFrom = (Solid) session.RetrieveModel(descrFrom);
 if (modelFrom == null || modelFrom.GetType() != ModelType.MDL_ASSEMBLY) {
 session.UIShowMessageDialog("Reference model is not an assembly.", null);
 }
 Assembly assemblyFrom = (Assembly) modelFrom;

 ModelDescriptor descrM = pfcModel.ModelDescriptor_CreateFromFileName("test.asm");
 Model model = (Model) session.GetModelFromDescr(descrM);
 if (model == null) {
 model = (Solid) session.RetrieveModel(descrM);
 }
 if (model == null || model.GetType() != ModelType.MDL_ASSEMBLY) {
 session.UIShowMessageDialog("Current model is not an assembly.",
 null);
 }
 model.Display();
 Assembly assembly = (Assembly) model; 

 ModelDescriptor descr = pfcModel.ModelDescriptor_CreateFromFileName(componentFilename);
 Solid componentModel = (Solid) session.GetModelFromDescr(descr);
 if (componentModel == null) {
 componentModel = (Solid) session.RetrieveModel(descr);
 }

 ComponentFeat asmcomp = (ComponentFeat) assembly.AssembleComponent(
 componentModel, null);
 ComponentConstraint constr = pfcComponentFeat.ComponentConstraint_Create(
 ComponentConstraintType.ASM_CONSTRAINT_CSYS);

 ModelItem compItem = componentModel.GetItemByName(ModelItemType.ITEM_COORD_SYS, "PRT_CSYS_DEF");
 Selection compSel = pfcSelect.CreateModelItemSelection(compItem, null);
 constr.SetComponentReference(compSel);

 //Assembly that has the model that will be use as reference
 /*ModelDescriptor descrFrom = pfcModel.ModelDescriptor_CreateFromFileName("montagem.asm");
 Model modelFrom = (Model) session.GetModelFromDescr(descrFrom);

 if (modelFrom == null) {
 modelFrom = (Solid) session.RetrieveModel(descrFrom);
 }

 if (modelFrom == null || modelFrom.GetType() != ModelType.MDL_ASSEMBLY) {
 session.UIShowMessageDialog("Reference model is not an assembly.", null);
 }
 Assembly assemblyFrom = (Assembly) modelFrom;*/

 ComponentFeat component = (ComponentFeat) assemblyFrom.GetFeatureById(39);
 ModelDescriptor descComp = component.GetModelDescr();
 Solid modelItem = (Solid) session.GetModelFromDescr(descComp);
 ModelItem asmItem = modelItem.GetItemByName(ModelItemType.ITEM_COORD_SYS, "CS0");

 intseq ids = intseq.create();
 ids.set(0, component.GetId());

 ComponentPath path = (ComponentPath) pfcAssembly.CreateComponentPath(assemblyFrom, ids);
 path.SetRoot(assemblyFrom);
 Selection asmSel = pfcSelect.CreateModelItemSelection(asmItem, path);
 constr.SetAssemblyReference(asmSel);

 ComponentConstraints constrs = ComponentConstraints.create();
 constrs.insert(constrs.getarraysize(), constr);
 asmcomp.SetConstraints(constrs, null);

 //assembly.Regenerate(null);
 //session.GetModelWindow(assembly).Repaint();
 }

} would like to know how can I assembly a component model like a part
in a sub-assembly using csys as reference.

I have a main assembly and a sub-assembly. So I have to assembly a componet
in the sub-assembly using csys references from the main assembly.

Tree:

Main_Assembly.asm

mainCSYS

Part1.prt
partCSYS1
partCSYS2

SubAssembly.asm 
subassyCSYS
NEW_Assymbly_Part.prt
newpartCSYS


I have to assembly the NEW_Assymbly_Part.prt in the assembly
SubAssembly using as Componet Reference the csys newpartCSYS
(in SubAssembly) and using as Assembly Reference the csys partCSYS2;

Please, How can I do this with j-link.

import com.ptc.cipjava.intseq;
import com.ptc.cipjava.jxthrowable;
import com.ptc.pfc.pfcAssembly.Assembly;
import com.ptc.pfc.pfcAssembly.ComponentPath;
import com.ptc.pfc.pfcAssembly.ExplodedState;
import com.ptc.pfc.pfcAssembly.pfcAssembly;
import com.ptc.pfc.pfcCommand.DefaultUICommandActionListener;
import com.ptc.pfc.pfcComponentFeat.ComponentConstraint;
import com.ptc.pfc.pfcComponentFeat.ComponentConstraintType;
import com.ptc.pfc.pfcComponentFeat.ComponentConstraints;
import com.ptc.pfc.pfcComponentFeat.ComponentFeat;
import com.ptc.pfc.pfcComponentFeat.pfcComponentFeat;
import com.ptc.pfc.pfcGlobal.pfcGlobal;
import com.ptc.pfc.pfcModel.Model;
import com.ptc.pfc.pfcModel.ModelDescriptor;
import com.ptc.pfc.pfcModel.ModelType;
import com.ptc.pfc.pfcModel.pfcModel;
import com.ptc.pfc.pfcModelItem.ModelItem;
import com.ptc.pfc.pfcModelItem.ModelItemType;
import com.ptc.pfc.pfcModelItem.ParamValue;
import com.ptc.pfc.pfcSelect.Selection;
import com.ptc.pfc.pfcSelect.pfcSelect;
import com.ptc.pfc.pfcSession.Session;
import com.ptc.pfc.pfcSolid.Solid;

class MenuButtonListener extends DefaultUICommandActionListener {

 static String title = "Editor de Parametro";
 ParamValue valor;

 @Override
 public void OnCommand() {
 try {
 montarComponente("part.prt");
 } catch (jxthrowable x) {
 x.printStackTrace();
 System.out.println("------------------------------------");
 }

 }

 public void montarComponente(String componentFilename) throws jxthrowable {

 Session session = pfcGlobal.GetProESession();

 ModelDescriptor descrFrom = pfcModel.ModelDescriptor_CreateFromFileName("montagem.asm");
 Model modelFrom = (Model) session.GetModelFromDescr(descrFrom);
 modelFrom = (Solid) session.RetrieveModel(descrFrom);
 if (modelFrom == null || modelFrom.GetType() != ModelType.MDL_ASSEMBLY) {
 session.UIShowMessageDialog("Reference model is not an assembly.", null);
 }
 Assembly assemblyFrom = (Assembly) modelFrom;

 ModelDescriptor descrM = pfcModel.ModelDescriptor_CreateFromFileName("test.asm");
 Model model = (Model) session.GetModelFromDescr(descrM);
 if (model == null) {
 model = (Solid) session.RetrieveModel(descrM);
 }
 if (model == null || model.GetType() != ModelType.MDL_ASSEMBLY) {
 session.UIShowMessageDialog("Current model is not an assembly.",
 null);
 }
 model.Display();
 Assembly assembly = (Assembly) model; 

 ModelDescriptor descr = pfcModel.ModelDescriptor_CreateFromFileName(componentFilename);
 Solid componentModel = (Solid) session.GetModelFromDescr(descr);
 if (componentModel == null) {
 componentModel = (Solid) session.RetrieveModel(descr);
 }

 ComponentFeat asmcomp = (ComponentFeat) assembly.AssembleComponent(
 componentModel, null);
 ComponentConstraint constr = pfcComponentFeat.ComponentConstraint_Create(
 ComponentConstraintType.ASM_CONSTRAINT_CSYS);

 ModelItem compItem = componentModel.GetItemByName(ModelItemType.ITEM_COORD_SYS, "PRT_CSYS_DEF");
 Selection compSel = pfcSelect.CreateModelItemSelection(compItem, null);
 constr.SetComponentReference(compSel);

 //Assembly that has the model that will be use as reference
 /*ModelDescriptor descrFrom = pfcModel.ModelDescriptor_CreateFromFileName("montagem.asm");
 Model modelFrom = (Model) session.GetModelFromDescr(descrFrom);

 if (modelFrom == null) {
 modelFrom = (Solid) session.RetrieveModel(descrFrom);
 }

 if (modelFrom == null || modelFrom.GetType() != ModelType.MDL_ASSEMBLY) {
 session.UIShowMessageDialog("Reference model is not an assembly.", null);
 }
 Assembly assemblyFrom = (Assembly) modelFrom;*/

 ComponentFeat component = (ComponentFeat) assemblyFrom.GetFeatureById(39);
 ModelDescriptor descComp = component.GetModelDescr();
 Solid modelItem = (Solid) session.GetModelFromDescr(descComp);
 ModelItem asmItem = modelItem.GetItemByName(ModelItemType.ITEM_COORD_SYS, "CS0");

 intseq ids = intseq.create();
 ids.set(0, component.GetId());

 ComponentPath path = (ComponentPath) pfcAssembly.CreateComponentPath(assemblyFrom, ids);
 path.SetRoot(assemblyFrom);
 Selection asmSel = pfcSelect.CreateModelItemSelection(asmItem, path);
 constr.SetAssemblyReference(asmSel);

 ComponentConstraints constrs = ComponentConstraints.create();
 constrs.insert(constrs.getarraysize(), constr);
 asmcomp.SetConstraints(constrs, null);

 //assembly.Regenerate(null);
 //session.GetModelWindow(assembly).Repaint();
 }

}


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
2 REPLIES 2

Please explore the "ComponentPath" if you haven't done that already. You will have to paly with component path in order to reach anywhere in tree. And then you have Leaf and Root option to get he CoSys for constructing constraints.

Hope that helps!

Consegiu Marcio?

Att,

Announcements


Top Tags