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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

List dimensions using jlink

tekknow
8-Gravel

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

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

View solution in original post

15 REPLIES 15

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 😞


Martin Hanák

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

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

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?

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

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


Martin Hanák

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

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

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

Hi,

 

1.] What Java 8 build do you use ?

On my PC, when you run java -version from command prompt I can see:

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) Client VM (build 25.161-b12, mixed mode, sharing)

 

2.] Did you set PRO_JAVA_COMMAND environment variable ? How ?

 


Martin Hanák

C:\Users\Greg\Projects\Enventive\En360_Creo>java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

 

Yes, PRO_JAVA_COMMAND is set in System Environment variables

C:\Program Files\Java\jre1.8.0_144\bin\java.exe

 

Also PRO_COMM_MSG_EXE is set to

C:\Program Files\PTC\Creo 4.0\M030\Common Files\x86e_win64\obj\pro_comm_msg.exe

I think that is needed only for async apps.

 

I also have PFCLS_START_DIR set to

C:\Program Files\PTC\Creo 4.0\M030\Common Files\x86e_win64\obj

I don't know if that is needed or not.

 

Also have CLASSPATH set to

.;C:\Program Files\PTC\Creo 4.0\M030\Common Files\text\java\otk.jar;%CLASSPATH%

 

Also my Path variable has this as part of it

%ProgramFiles%\PTC\Creo 4.0\M030\Common Files\libs

 

Hi,

 

thanks for sending information. Thanks to that I was able to compile and run my test application. You can find it in attached search_dimensions_CR4_2018-01-20.zip file.

 

1.] on my PC search_dimensions_CR4 sub-directory is located in D:\users\mh\creo4_parametric\PTC_JLink directory

 

2.] application source code ... D:\users\mh\creo4_parametric\PTC_JLink\search_dimensions_CR4\zdrojovy_kod\SDVApp.java

 

3.] compilation batch file ... D:\users\mh\creo4_parametric\PTC_JLink\search_dimensions_CR4\zdrojovy_kod\kompilace_1.8.bat

 

4.] Creo launch command ... D:\users\mh\creo4_parametric\PTC_JLink\search_dimensions_CR4\Creo4 M030.bat

 

5.] application startup file ... D:\users\mh\creo4_parametric\PTC_JLink\search_dimensions_CR4\protk.dat

 

Procedure to launch my application

a.] double-click Creo4 M030.bat

b.] open deska.drw drawing

c.] activate Tools tab > click Tools > File > Hledání kót

Untitled.png

d.] the output is written in seznam_kot.csv file

e.] exception code (if exists) is written in seznam_kot_chyby.txt file

 

Goog luck


Martin Hanák

Hi Martin,

Thank you for the code and detailed instructions.  I opened your java code

C:\Users\Greg\Downloads\search_dimensions_CR4_2018-01-20\search_dimensions_CR4\zdrojovy_kod\SDVapp.java

 

I see you are still using Dimension2D in 2 places,

here:

Dimension2D dim = (Dimension2D)dims.get(i);

here:

and here:

Dimension2D dim = (Dimension2D)drawingShownDimensions.get(i)

 

If I use that in my code I get error 

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

 

You really got it working under Creo4?

Greg

 

 

Hi,

 

I checked the contents of search_dimensions_CR4_2018-01-20.zip archive and found out that the contents of protk.dat file is wrong - it points to Creo 2.0 version of my application.

 

I corrected protk.dat file - now it points to Creo 4.0 version of my application.

 

I also found out that using corrected protk.dat file Creo 4.0 is not able to start my application packed in mh_installtest.jar file. Therefore I deleted mh_installtest.jar file and replaced it with 3 class-files (MenuButtonListener.class, SDVApp.class, SDVApp2.class). Now my Creo 4.0 version application works well. You can modify paths in protk.dat file and Creo4 M030.bat according to your situation and test my application on your computer. See attachment search_dimensions_CR4_2018-01-25.zip.

 

I guess that Exception caught: com.ptc.wfc.Implementation.pfcExceptions$XToolkitObsoleteFunc can be thrown by other function ...

 


Martin Hanák

Hi,

 

I can use mh_installtest.jar file, too. The problem with jar file was caused by missing path in CLASSPATH variable in Creo4 M030.bat.

 

set CLASSPATH=.;E:\PTC\Creo4_M030\CREO4~1.0\M030\COMMON~1\text\java\otk.jar;%CLASSPATH%
set CLASSPATH=D:\users\mh\creo4_parametric\PTC_JLink\search_dimensions_CR4\mh_installtest.jar;%CLASSPATH%

 

The above setting resolved the problem.


Martin Hanák
Top Tags