List dimensions using jlink
JLink fails to list dimensions. I created a part in Creo Parametric, 4.0 and then created a drawing from that part There are 10 shown dimensions. I want to get a list of them using jlink. I use the following line of code to get them:
ModelItems dims = drawing.ListItems(ModelItemType.ITEM_DIMENSION);
but when I query the array size, it says "size=0".
int size = dims.getarraysize();
printMsg("size="+size);
Anybody have a clue to what is going on?
Here is more of the code which is derived from jlink exercise 1 (C:\Program Files\PTC\Creo 4.0\M030\Common Files\otk_java_free\exercises\exercise_1_and_2) and C:\Program Files\PTC\Creo 4.0\M030\Common Files\otk_java_free\otk_java_appls\jlinkexamples\pfcDrawingExamples.java.
public void getModelInfo(int index) throws jxthrowable
{
Vector data_i;
Model model;
/* Model data */
String name;
ModelType type;
String typeString;
model = models.get(index);
data_i = new Vector (10);
/* Get model full name */
name = model.GetFullName();
printMsg("Getting information from model: "+name);
data_i.addElement(name);
/* Get model type */
type = model.GetType();
typeString = Labeler.pfcModelType[type.getValue()];
if (typeString.equals("MDL_PART") || typeString.equals("MDL_ASSEMBLY")) {
...
}
else if (typeString.equals("MDL_DRAWING")) {
Drawing drawing = (Drawing) model;
ModelItems dims = drawing.ListItems(ModelItemType.ITEM_DIMENSION);
//Dimension2Ds dims = drawing.ListShownDimensions(model, ModelItemType.ITEM_DIMENSION); //get a "method is deprecated" error message if I use this!
int size = dims.getarraysize();
printMsg("size="+size);
for (int i=0; i<dims.getarraysize(); i++) {
printMsg("about to dims.get("+i +")...");
Dimension2D dim = (Dimension2D)dims.get(i);
int dimId = dim.GetId();
String dimName = dim.GetName();
double dimValue = dim.GetDimValue();
String s = String.format("%d, %s, %.2f", dimId,dimName,dimValue);
printMsg(s); //nothing is printed since array size=0
}
}
modelData[index] = data_i;
return;
}

