Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hi folks,
Please look at simple assembly flex_top_asm.asm. It contains one component flex_part2.prt.
In part thre are defined:
a) 3 dimensions as flexible (open file in new window, then File > Prepare > Model Properties > Flexible > Dimensions);
b) 3 parameters as flexible (open file in new window, then File > Prepare > Model Properties > Flexible > Parameters);
Based on PTC sample I've modified method, that should be started on asm level. As a result, component flex_part2.prt will be changed into flexible one, and in Varied Items table dimensions will be shown.
Question is:
How to do it with parameters. How to add them to Varied Items table??
Sample code:.
public static void makeFlexibleComponent(int componentID) {
ComponentFeat CFeat = null;
WComponentFeat WCFeat = null;
try {
FileWriter file = new FileWriter("AssemblyItemExample.txt");
BufferedWriter fp_out_asmitem = new BufferedWriter(file);
fp_out_asmitem.write("- gucioFlexibleComponent -");
fp_out_asmitem.newLine();
fp_out_asmitem.write("==============================");
fp_out_asmitem.newLine();
Session session = pfcSession.GetCurrentSession();
/* Open top assembly FLEX_TOP_ASM.asm in Creo Session */
Model CurrModel = session.GetCurrentModel();
Assembly PAsm = (Assembly) (CurrModel);
WAssembly WAsm = (WAssembly) (CurrModel);
Features Feats = PAsm.ListFeaturesByType(Boolean.FALSE, FeatureType.FEATTYPE_COMPONENT);
Model ItemOwner = null;
for (int i = 0; i < Feats.getarraysize(); i++) {
if (Feats.get(i).GetId() == componentID) {
fp_out_asmitem.write("For Feature ID: " + Feats.get(i).GetId());
fp_out_asmitem.newLine();
fp_out_asmitem.write("With Feature Number: " + Feats.get(i).GetNumber());
fp_out_asmitem.newLine();
CFeat = (ComponentFeat) (Feats.get(i));
WCFeat = (WComponentFeat) (CFeat);
intseq seq = intseq.create();
seq.set(seq.getarraysize(), componentID);
String ItemOwnerName = ((ComponentFeat) Feats.get(i)).GetModelDescr().GetFileName();
ItemOwner = session.GetModelFromFileName(ItemOwnerName);
}
}
boolean is_flex = WCFeat.IsFlexible();
fp_out_asmitem.write(" Is Component Already Flexible ? : " + (is_flex ? "YES" : "NO"));
fp_out_asmitem.newLine();
intseq dim_id_array = intseq.create();
dim_id_array.set(0, 8);
dim_id_array.set(1, 4);
dim_id_array.set(2, 5);
AssemblyItems AsmItemArray = AssemblyItems.create();
for (int i = 0; i < dim_id_array.getarraysize(); i++) {
fp_out_asmitem.write("ABC " + dim_id_array.get(i));
fp_out_asmitem.newLine();
AssemblyItemInstructions ThisAsmInstr = wfcComponentFeat.AssemblyItemInstructions_Create(ItemOwner,
ModelItemType.ITEM_DIMENSION, dim_id_array.get(i));
AssemblyItem ThisAsmItem = WAsm.CreateAssemblyItem(ThisAsmInstr);
AsmItemArray.append(ThisAsmItem);
}
fp_out_asmitem.write("before");
fp_out_asmitem.newLine();
WCFeat.SetAsFlexible(AsmItemArray);
Dimension dim1 = ((Dimension) WCFeat.ListVariedItems().get(0));
Dimension dim2 = ((Dimension) WCFeat.ListVariedItems().get(1));
Dimension dim3 = ((Dimension) WCFeat.ListVariedItems().get(2));
dim1.SetDimValue(111);
dim2.SetDimValue(222);
dim3.SetDimValue(333);
fp_out_asmitem.write("after");
fp_out_asmitem.newLine();
fp_out_asmitem.write("==============================");
fp_out_asmitem.newLine();
fp_out_asmitem.write("-gucioFlexibleComponent-");
fp_out_asmitem.close();
return;
} catch (Exception e) {
System.out.println(e + " " + e.getMessage());
}
}
Solved! Go to Solution.
Create instruction AssemblyItemInstructions_Create.
As a type use ModelItemType._ModelItemType_null.
For Parameter you need specify a name AssemblyItemInstructions.SetItemName. Maybe in AssemblyItemInstructions_Create for ItemId you can pass 0 (zero) in case of a parameters.
Create instruction AssemblyItemInstructions_Create.
As a type use ModelItemType._ModelItemType_null.
For Parameter you need specify a name AssemblyItemInstructions.SetItemName. Maybe in AssemblyItemInstructions_Create for ItemId you can pass 0 (zero) in case of a parameters.
Not sure what this mean.
From the documentation
The value of this argument is ignored for
parameter. For parameter, pass this value as _ModelItemType_null.
static final int _ModelItemType_null - Enum null value.
Try to use
null
as the argument.
I've tried earlier - no success.
What is more, I used log to get an error message
Result:
Try to create AssemblyItemInstructions_Create with any ModelItemType.
Then set a name AssemblyItemInstructions.SetItemName.
Maybe, the item type will be ignored in case of a parameters (as described in the documentation).
For me, looks like a bug in Java API. ModelItemType class don't have _ModelItemType_null. Only null
package com.ptc.pfc.pfcModelItem;
import com.ptc.cipjava.jxenum;
public final class ModelItemType implements jxenum {
private int __Value;
public static final int _ITEM_FEATURE = 0;
public int getValue() { return this.__Value; }
public static ModelItemType FromInt(int paramInt) {
switch (paramInt) {
case 0:
return ITEM_FEATURE;
case 1:
return ITEM_SURFACE;
case 2:
return ITEM_EDGE;
case 3:
return ITEM_COORD_SYS;
case 4:
return ITEM_AXIS;
case 5:
return ITEM_POINT;
case 6:
return ITEM_QUILT;
case 7:
return ITEM_CURVE;
case 8:
return ITEM_LAYER;
case 9:
return ITEM_NOTE;
case 10:
return ITEM_DIMENSION;
case 11:
return ITEM_REF_DIMENSION;
case 12:
return ITEM_SIMPREP;
case 13:
return ITEM_SOLID_GEOMETRY;
case 14:
return ITEM_TABLE;
case 15:
return ITEM_DTL_ENTITY;
case 16:
return ITEM_DTL_NOTE;
case 17:
return ITEM_DTL_GROUP;
case 18:
return ITEM_DTL_SYM_DEFINITION;
case 19:
return ITEM_DTL_SYM_INSTANCE;
case 20:
return ITEM_DTL_OLE_OBJECT;
case 21:
return ITEM_EXPLODED_STATE;
case 22:
return ITEM_EDGE_START;
case 23:
return ITEM_LOG_EDGE;
case 24:
return ITEM_EDGE_END;
case 25:
return ITEM_XSEC;
case 26:
return ITEM_LAYER_STATE;
case 27:
return ITEM_COMBINED_STATE;
case 28:
return ITEM_STYLE_STATE;
case 29:
return ITEM_RP_MATERIAL;
case 30:
return ITEM_VIEW;
case 31:
return ITEM_SURF_FIN;
case 32:
return ITEM_ANNOT_PLANE;
case 33:
return ITEM_ANNOTATION_ELEM;
case 34:
return ITEM_SET_DATUM_TAG;
case 35:
return ITEM_GTOL;
case 36:
return ITEM_BODY;
case 37:
return null;
}
return null;
}
public static ModelItemType FromInt(Integer paramInteger) {
if (paramInteger == null) {
return null;
}
return FromInt(paramInteger.intValue());
}
private ModelItemType(int paramInt) { this.__Value = paramInt; }
public static int getValue(ModelItemType paramModelItemType) {
if (paramModelItemType == null) {
return 37;
}
return paramModelItemType.getValue();
}
public static final ModelItemType ITEM_FEATURE = new ModelItemType(false);
public static final int _ITEM_SURFACE = 1;
public static final ModelItemType ITEM_SURFACE = new ModelItemType(true);
public static final int _ITEM_EDGE = 2;
public static final ModelItemType ITEM_EDGE = new ModelItemType(2);
public static final int _ITEM_COORD_SYS = 3;
public static final ModelItemType ITEM_COORD_SYS = new ModelItemType(3);
public static final int _ITEM_AXIS = 4;
public static final ModelItemType ITEM_AXIS = new ModelItemType(4);
public static final int _ITEM_POINT = 5;
public static final ModelItemType ITEM_POINT = new ModelItemType(5);
public static final int _ITEM_QUILT = 6;
public static final ModelItemType ITEM_QUILT = new ModelItemType(6);
public static final int _ITEM_CURVE = 7;
public static final ModelItemType ITEM_CURVE = new ModelItemType(7);
public static final int _ITEM_LAYER = 8;
public static final ModelItemType ITEM_LAYER = new ModelItemType(8);
public static final int _ITEM_NOTE = 9;
public static final ModelItemType ITEM_NOTE = new ModelItemType(9);
public static final int _ITEM_DIMENSION = 10;
public static final ModelItemType ITEM_DIMENSION = new ModelItemType(10);
public static final int _ITEM_REF_DIMENSION = 11;
public static final ModelItemType ITEM_REF_DIMENSION = new ModelItemType(11);
public static final int _ITEM_SIMPREP = 12;
public static final ModelItemType ITEM_SIMPREP = new ModelItemType(12);
public static final int _ITEM_SOLID_GEOMETRY = 13;
public static final ModelItemType ITEM_SOLID_GEOMETRY = new ModelItemType(13);
public static final int _ITEM_TABLE = 14;
public static final ModelItemType ITEM_TABLE = new ModelItemType(14);
public static final int _ITEM_DTL_ENTITY = 15;
public static final ModelItemType ITEM_DTL_ENTITY = new ModelItemType(15);
public static final int _ITEM_DTL_NOTE = 16;
public static final ModelItemType ITEM_DTL_NOTE = new ModelItemType(16);
public static final int _ITEM_DTL_GROUP = 17;
public static final ModelItemType ITEM_DTL_GROUP = new ModelItemType(17);
public static final int _ITEM_DTL_SYM_DEFINITION = 18;
public static final ModelItemType ITEM_DTL_SYM_DEFINITION = new ModelItemType(18);
public static final int _ITEM_DTL_SYM_INSTANCE = 19;
public static final ModelItemType ITEM_DTL_SYM_INSTANCE = new ModelItemType(19);
public static final int _ITEM_DTL_OLE_OBJECT = 20;
public static final ModelItemType ITEM_DTL_OLE_OBJECT = new ModelItemType(20);
public static final int _ITEM_EXPLODED_STATE = 21;
public static final ModelItemType ITEM_EXPLODED_STATE = new ModelItemType(21);
public static final int _ITEM_EDGE_START = 22;
public static final ModelItemType ITEM_EDGE_START = new ModelItemType(22);
public static final int _ITEM_LOG_EDGE = 23;
public static final ModelItemType ITEM_LOG_EDGE = new ModelItemType(23);
public static final int _ITEM_EDGE_END = 24;
public static final ModelItemType ITEM_EDGE_END = new ModelItemType(24);
public static final int _ITEM_XSEC = 25;
public static final ModelItemType ITEM_XSEC = new ModelItemType(25);
public static final int _ITEM_LAYER_STATE = 26;
public static final ModelItemType ITEM_LAYER_STATE = new ModelItemType(26);
public static final int _ITEM_COMBINED_STATE = 27;
public static final ModelItemType ITEM_COMBINED_STATE = new ModelItemType(27);
public static final int _ITEM_STYLE_STATE = 28;
public static final ModelItemType ITEM_STYLE_STATE = new ModelItemType(28);
public static final int _ITEM_RP_MATERIAL = 29;
public static final ModelItemType ITEM_RP_MATERIAL = new ModelItemType(29);
public static final int _ITEM_VIEW = 30;
public static final ModelItemType ITEM_VIEW = new ModelItemType(30);
public static final int _ITEM_SURF_FIN = 31;
public static final ModelItemType ITEM_SURF_FIN = new ModelItemType(31);
public static final int _ITEM_ANNOT_PLANE = 32;
public static final ModelItemType ITEM_ANNOT_PLANE = new ModelItemType(32);
public static final int _ITEM_ANNOTATION_ELEM = 33;
public static final ModelItemType ITEM_ANNOTATION_ELEM = new ModelItemType(33);
public static final int _ITEM_SET_DATUM_TAG = 34;
public static final ModelItemType ITEM_SET_DATUM_TAG = new ModelItemType(34);
public static final int _ITEM_GTOL = 35;
public static final ModelItemType ITEM_GTOL = new ModelItemType(35);
public static final int _ITEM_BODY = 36;
public static final ModelItemType ITEM_BODY = new ModelItemType(36);
public static final int __Last = 37;
}
But in AssemblyItemInstructions_Create I see a check that the arguments must not be equal null.
public static AssemblyItemInstructions AssemblyItemInstructions_Create(Model paramModel, ModelItemType paramModelItemType, int paramInt) throws jxthrowable {
if (paramModel == null) {
throw XNullInNonOptArg.Create("ItemOwner");
}
if (paramModelItemType == null) {
throw XNullInNonOptArg.Create("ItemType");
}
CIPRemoteComm cIPRemoteComm = CIPRemoteApp.getComm();
CIPTransport cIPTransport = CIPRemoteApp.getTransport();
long l = cIPTransport.obtainObjectPtr(paramModel);
cIPRemoteComm.sendCall();
cIPTransport.sendInt(6021);
cIPTransport.sendObjectPtr(l);
cIPTransport.sendInt(ModelItemType.getValue(paramModelItemType));
cIPTransport.sendInt(paramInt);
cIPRemoteComm.processMessages();
return (AssemblyItemInstructions)cIPTransport.recvObject(CIPRemoteApp.getObjectMaker());
}