Skip to main content
1-Visitor
January 11, 2018
Solved

List dimensions using jlink

  • January 11, 2018
  • 2 replies
  • 8128 views

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

 

Best answer by tekknow

Hi Martin,

Yes, you were right.  The dims belonged to the part, not the dimension.  I created a separate linear point-to-point dimension in the drawing and then that dim showed up.

Thank you,

Greg

2 replies

24-Ruby III
January 11, 2018

Hi,

 

I guess that your code is not able to find shown model dimension. To test my guess, try to create drawing dimensions and run your application. I hope that it will find them.

 

Unfortunatelly I cannot tell you how to find shown model dimension 😞

tekknow1-VisitorAuthorAnswer
1-Visitor
January 16, 2018

Hi Martin,

Yes, you were right.  The dims belonged to the part, not the dimension.  I created a separate linear point-to-point dimension in the drawing and then that dim showed up.

Thank you,

Greg

24-Ruby III
January 16, 2018

Hi,

 

your code can find drawing dimensions whose symbol names are add0, add1, and so on.

To be able to create such drawing dimensions you have to set following config.pro option

CREATE_DRAWING_DIMS_ONLY yes

Only these dimensions are saved in drawing - this means drawing is their parent.

 

Drawing dimensions whose symbol names are ad0, ad1, and so on are saved in drawing model - this means drawing model is their parent.

tekknow1-VisitorAuthor
1-Visitor
January 16, 2018

Hi Martin,

I do have the config.pro option set as

create_drawing_dims_only yes

 

I was expecting that after I had set that option and then re-opened the model in Creo and did a Save, that any dimensions belonging to the part would now belong to the drawing.  But that was not the case.  It seemed to make no difference.  What does that option do?

Greg

Ps.

Is Dimension2D obsolete? I'm trying to get a list of drawing dimensions and associated attributes. I loop through the session models and if it is of type MDL_DRAWING, I cast it to Drawing and attempt to list it's dimensions using the following command:
Dimension2Ds dims = drawing.ListShownDimensions(model, ModelItemType.ITEM_DIMENSION);
but I get the following error:
exception caught: com.ptc.wfc.Implementation.pfcExceptions$XToolkitObsoleteFunc

I can successfully collect the dims if I instead use the following command:
ModelItems dims = drawing.ListItems(ModelItemType.ITEM_DIMENSION);

I then loop through the ModelItems using the following command:
ModelItem item = dims.get(i);

but the available methods in ModelItem are not as extensive as in Dimension2D. For example Dimension2D has a Location method which I need to distinguish between two dimensions of the same type that have the same nominal value.

Is Dimension2D obsolete? If so, what replaces it to get all the same methods? If not, how to make it work?

24-Ruby III
January 17, 2018

Hi,

 

following code enables me to get drawing dimensions whose symbol names are ad0, ad1, ... and also d0, d1, ...

 

proeModel = proeSession.GetCurrentModel();

Drawing drawing = (Drawing) proeModel;

...

Models drawingModelList = drawing.ListModels();

// my drawing has 1 model only ... I get this model using drawingModelList.get(0)

...

Model2D myModel2D = (Model2D) drawing;

Dimension2Ds drawingShownDimensions = myModel2D.ListShownDimensions(drawingModelList.get(0),ModelItemType.ITEM_DIMENSION);

int i2 = drawingShownDimensions.getarraysize();

for (int i=0; i < i2; i++)
{
  pw.println("about to dims.get("+i +")...");
  Dimension2D dim = (Dimension2D)drawingShownDimensions.get(i);
  int dimId = dim.GetId();
  String dimName = dim.GetName();
  double dimValue = dim.GetDimValue();
  // command to print dimId + ", " + dimName + ", " + dimValue
}