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

List dimensions using jlink

SOLVED
Highlighted
Level 8

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

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: List dimensions using jlink

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

15 REPLIES 15

Re: List dimensions using jlink

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 Smiley Sad


Martin Hanák

Re: List dimensions using jlink

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.


Martin Hanák

Re: List dimensions using jlink

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

Re: List dimensions using jlink

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?

Re: List dimensions using jlink

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
}


Martin Hanák

Re: List dimensions using jlink

BTW ... I am using J-Link with Creo 2.0. I did not test Creo 4.0.


Martin Hanák

Re: List dimensions using jlink

Hi Martin,

Unfortunately, in Creo4 your code will fail at the ListShownDimensions command with error:

Exception caught: com.ptc.wfc.Implementation.pfcExceptions$XToolkitObsoleteFunc

 

ListShownDimensions is replaced with Model2D.CollectShownRefDimensions, and Model2D.CollectShownDimensions.

 

I'm in the process of testing those now.

Greg

Re: List dimensions using jlink

Hi,

 

today I tried to run my application with Creo 4.0 M030. Unfortunately, I can not translate the application to work with Creo 4.0 M030. Please can you help ?

 

1.) What Java version do you use to compile an application ?

 

2.) What Creo 4.0 Mxxx do you use

 

3.) How did you configure Creo startup batch file to run Creo with the application ?

 

Thanks in advance for any piece of information.

 

 


Martin Hanák

Re: List dimensions using jlink

Hi Martin,

1.  Java 8

2. 30

3. My protk.dat file looks like this:

name                DimExtractor
startup                java
java_app_class        en360_creo.En360_Creo
java_app_classpath    C:\Users\Greg\Projects\Enventive\En360_Creo\dist\En360_Creo.jar
java_app_start        app_start
java_app_stop        stop
allow_stop            true
delay_start            true
end

and is located here:

C:\Users\Greg\Projects\Enventive\En360_Creo

This is a NetBeans application.

The config.pro is also located there and contains one line:

create_drawing_dims_only yes

Every time I make a change to the code I do a "Clean and Build" in NetBeans.  This creates the En360_Creo.jar file.

To run it, open a dos shell and go to directory shown then:

C:\Users\Greg\Projects\Enventive\En360_Creo>"C:\Program Files\PTC\Creo 4.0\M030\Parametric\bin\parametric.exe" > out.txt

out.txt will contain output from program commands System.out.println("debugging info")

Hope that helps.

Greg