Changing Creo Parameter with J-link

Hello again,
I will stay another topic in front of you today and explain changing parameter in PTC Creo with using j-link.
J-link give more flexibility to customize design but it’s limited version of J-toolkit. You can find lots of document to explain what is differences between J-link and J-toolkit. Due to the lack of toolkit license, I keep working on going projects with J-link.

Let start;

Before starting to explain, I have to warn readers for using swing library. I had tried many times working with swing library and j-link together. At the beginning time. everything is working out all right however after clicking buttons or whatever, the GUI hags. In order to avoid this situation, I will use JDialog frames.


public class JLHW_Btn1_CmdListener extends DefaultUICommandActionListener {

// Handler for button push
//
@Override
public void OnCommand () {
try {
//Btn1_callback();
session.SetConfigOption("regen_failure_handling", "resolve_mode");
JDialog f = new JDialog();
JButton jb = new JButton("Değiştir");
JLabel jl1=new JLabel("İç Çap:");
JLabel jl2=new JLabel("Dış Çap:");
jtIc=new JTextField(String.valueOf(getDiameter(DiameterType.INNER)));
jtDis=new JTextField(String.valueOf(getDiameter(DiameterType.OUTER)));
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
changeDiameter(Integer.valueOf(jtDis.getText()), DiameterType.OUTER);
changeDiameter(Integer.valueOf(jtIc.getText()), DiameterType.INNER);
} catch (Exception ex) {
try {
DisplayMessage(ex.getMessage());
} catch (Exception ex1) {
Logger.getLogger(jlinkhelloworld.class.getName()).log(Level.SEVERE, null, ex1);
}
}

}
});
f.setAlwaysOnTop(true);
f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
f.setLayout(new FlowLayout(FlowLayout.LEFT));
f.add(jl1);
f.add(jtIc);
f.add(jl2);
f.add(jtDis);
f.add(jb);
f.pack();
f.setModal(true);
f.setVisible(true);
}
catch (Exception e) {
writeLog("Exception thrown by Btn1_callback method: " + e.toString());
}
}

In order to enable to regenerate the model, we have to set “regen_failure_handling” mode to “resolve_mode”. Please look at the line 9 above codes. Otherwise program will throw exception. As my experience, previously, unfortunately I couldn’t find any solutions for these exceptions.

Above picture also shows how program looks like. When the button is pressed. code calls following codes;


public void changeDiameter(int cap,DiameterType diameterType) {
Parameter param=null;
try {
model = App.session.GetCurrentModel();
switch(diameterType){
case OUTER:
{
param=this.model.GetParam("DISCAP");
ParamValue paramVal= pfcModelItem.CreateIntParamValue(cap);
param.SetValue(paramVal);
}
case INNER:
{
param=this.model.GetParam("ICCAP");
ParamValue paramVal= pfcModelItem.CreateIntParamValue(cap);
param.SetValue(paramVal);
}
}
} catch (jxthrowable ex) {
ex.printStackTrace();
}
finally{
try {

((Solid) model).Regenerate(null);
model.Display();
} catch (jxthrowable ex) {
try {
DisplayMessage(ex.getMessage());
} catch (Exception ex1) {
Logger.getLogger(jlinkhelloworld.class.getName()).log(Level.SEVERE, null, ex1);
}
}
}
}

there are two different parameters to controlling diameter of outer and inner of ring. Outer diameter is controlled by “DISCAP” and inner diameter is called “ICCAP” in parameter table.

However, before the Jdialog comes to screen, these parameters are read by following code in advance. User can see easily what the parameters values are, on Jdialog form.


public int getDiameter(DiameterType diameterType) throws Exception {
model = App.session.GetCurrentModel();
switch (diameterType) {
case OUTER:
{
Parameter param=model.GetParam("DISCAP");
ParamValue paramVal=param.GetValue();
model=null;
return paramVal.GetIntValue();
}
case INNER:
{
Parameter param=model.GetParam("ICCAP");
ParamValue paramVal=param.GetValue();
model=null;
return paramVal.GetIntValue();
}
default:
return 0;
}

}

I have already uploaded all this algorithm files in my GitHub account. You can find download following link.

https://github.com/FrostTiger/changingCreoParameter

But for using this codes you must adjust some following details:

  • C:\Users\[User folder]\Documents\NetBeansProjects\jlinkhelloworld – folder address must be the same.
  • must be checked config.pro, protk.dat and run.bat files. File paths of content of these files must be checked according to user computer.

Regards,
Gökhan

http://www.gokhansaman.com/wp-content/plugins/sociofluid/images/google_48.png http://www.gokhansaman.com/wp-content/plugins/sociofluid/images/myspace_48.png http://www.gokhansaman.com/wp-content/plugins/sociofluid/images/facebook_48.png http://www.gokhansaman.com/wp-content/plugins/sociofluid/images/yahoobuzz_48.png http://www.gokhansaman.com/wp-content/plugins/sociofluid/images/twitter_48.png

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir