Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

J-Link Sample Code

conrat

New member
Hi all,



I was wondering if anyone has any examples of J-Link sample code that
will connect to Pro/E and open a model, then retrieve a few
parameters. I know there are samples in the J-Link folder, but
these seem to be having problems compiling.



Here are some examples of the errors:



warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector



package com.ptc.jlinkdemo.common does not exist<br style="color: rgb(0, 0, 255);">
import com.ptc.jlinkdemo.common.UIHelper;



If someone has a java file that I can compile and that will get the
session, open a model, and display some results, I think I might be
able to figure out what I am doing wrong.



Also, if anyone is versed in the mating of Pro/E and Java, you might
want to consider a new career - Author. You see, there are no
J-Link specific books anywhere. Not at PTC, not Amazon or Barnes
and Noble. No where. One could make a pretty penny writing
a book like this.



Thanks,

Jim
 
Here is something to get you started.



try

{

Session session = pfcGlobal.GetProESession();

Model model = session.GetCurrentModel();

}catch(Exception ex)

{


JOptionPane.sh owMessageDialog (null, "ERROR in getting ProE
Session.\nPlease select a part or assembly.","Session Check",
JOptionPane.INFORMATION_MESSAGE );

}



try

{

Parameter param = model.GetParam("PARAMETER");

ParamValue pv = param.GetValue();

String modelParameter = pv.GetStringValue();

JOptionPane.showMessageDialog (null, "Ready to read db for
"+modelParameter,"db Check", JOptionPane.INFORMATION_MESSAGE );

}catch(Exception ex)

{

//display error comcode is missing

JOptionPane.showMessageDialog (null,
"No parameter found.\nPlease update parameter table.","db Check",
JOptionPane.INFORMATION_MESSAGE );

return;

}//close try to get comcode parameter
 
Jeff,



Thanks, this should help out.



I have created one small program. I have one that opens a part,
grabs three parameter values, then runs through a calculation and sends
two different parameter values back. It then regens the
model. I then added six parts that need the same calc done to an
array and was able to loop through each of the parts, doing the same
calcs on each. I used the J-Link guide to figure this out.



J-Link seems like a really great tool. I am extremely new to
Java, but previous programming experience is helping me along the
way. The ability to use arrays and loops is an immense benefit
and I wish they would add some of this higher lever progamming
functionality to Pro/PROGRAM.



I was wondering though, in my first program explanation, if I were to
have an assembly where a part in the assembly needs to be sent through
J-Link to do the calc, would I need to add an action listener so that
the J-Link program is not run before the asm is regenerated? I
need to ensure the new values are present in the assembly before
running the J-Link program, as it relies on asm values to do the
calculation. If so, what action should I be waiting for?



Another thing I am a little confused about. To keep things
compartmentalized, should I be creating an object for each part, then
adding the various PTC classes as properties or methods of the custom
object?



For instance, create a new Object named myPart. Then set it up so that that object contains something like:



myPart.param<br style="color: rgb(0, 0, 255);">
myPart.pv<br style="color: rgb(0, 0, 255);">
myPart.modelParameter<br style="color: rgb(0, 0, 255);">
myPart.param.GetValue()<br style="color: rgb(0, 0, 255);">
etc...



I would create a constructor class
that does all of the repetitive heavy lifting, setting up the
PTC-centric classes for each instance of the object. It just seems like you must initialize many variables just to get a value.



For instance, I could not get this to work:



ParamValue pv = model.GetParam("PARAMETER").GetValue();



It seems like it should work, but does not. I don't really need
to hold the parameter, just the value, but I must create the Parameter
before creating the ParamValue.



I think I need to keep experimenting.

Thanks again,

Jim



ps - Sorry if this was too long winded, but the more I work with
J-Link, the more questions I have. I got two books on Java and
have been studying them constantly. I am having more luck doing
native Java than J-Link though.



pps - I know this is pretty basic, but here is a class that creates a
JOption Pane, which is helpful, as I have been using many of them to
debug. Saves a lot of typing. Maybe you will find it useful
too. Let me know if you see errors.



---------------------------------------------------------- --

import java.awt.*;<br style="color: rgb(0, 0, 255);">
import javax.swing.*;<br style="color: rgb(0, 0, 255);">
import com.ptc.pfc.pfcWindow.*;<br style="color: rgb(0, 0, 255);">
<br style="color: rgb(0, 0, 255);">
public class AlertBox { <br style="color: rgb(0, 0, 255);">
public AlertBox(String myContent, String myTitle) {<br style="color: rgb(0, 0, 255);">
Frame myFrame = new Frame();<br style="color: rgb(0, 0, 255);">
JOptionPane.showMessageDialog( myFrame, myContent,<br style="color: rgb(0, 0, 255);">
myTitle, JOptionPane.INFORMATION_MESSAGE );<br style="color: rgb(0, 0, 255);">
myFrame.setVisible(false);<br style="color: rgb(0, 0, 255);">
} <br style="color: rgb(0, 0, 255);">
}



Calling it:



new AlertBox("myContent", "myTitle");

------------------------------------------------------------
 

Sponsor

Articles From 3DCAD World

Back
Top