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

Adding Relations to a model in J-Link

pstephens
5-Regular Member

Adding Relations to a model in J-Link

Hello J-Link Gurus,

Would anybody please be able to share a code snippet that shows how to import a simple relation into a Pro/E model using J-Link?

I have been trying unsuccessfully.

I could not make sense of how to use RelationImportInstructions in the user guide, nor find any code examples.

I was also unsuccessful getting a solution from PTC Tech support.

Any help offered would be appreciated.

TIA

Paul Stephens

Kenworth Trucks Australia

2 REPLIES 2

You have to read it out - alter it - then add it all back as I recall.

Dave


pstephens
5-Regular Member
(To:pstephens)

Thanks to everybody who replied.

The solution came from Ken at PTC Tech Support:

"Session session = pfcGlobal.GetProESession ();

Model model = session.GetCurrentModel();

RelationImportInstructions instruct = pfcModel.RelationImportInstructions_Create();

model.Import("prt0001_rel.txt", instruct);"

I just had to make sure there were no comment lines in the text filethat containedthe relations before they would read in to the model.

Other replies below:

======================================================================================================

"You have to read it out – alter it – then add it all back as I recall."

=====================================================================================================================

"Attached you wil find te java script HandleParams.java.In this script there are several methods to use parameters in jlink. With thenext goal:naamParam (ModelDescriptor md, Model model, Session session, String param)==> checks if a parameter exists
showParam (ModelDescriptor md, Model model, Session session, String param) ==> gives the value of a parameter
setParam (ModelDescriptor md, Model model, Session session, String param, String newValue) ==> set a new value for a parameter using the next methodes
setStringParam (ModelDescriptor md, Model model, Session session, String param, String newValue) ==> setting Sting parameter
setIntParam (ModelDescriptor md, Model model, Session session, String param, int newValue) ==> setting Integer parameter
setDoubleParam (ModelDescriptor md, Model model, Session session, String param, double newValue) ==> setting double parameter
setBoolParam (ModelDescriptor md, Model model, Session session, String param, boolean newValue) ==> setting boolean parameter
setNoteParam (ModelDescriptor md, Model model, Session session, String param, int newValue) ==? setting Note parameter

getStringParam (ModelDescriptor md, Model model, Session session, String param) ==> gives the value of a String Parameter
getDoubleParam (ModelDescriptor md, Model model, Session session, String param)
==> gives the value of a double Parameter
getBoolParam (ModelDescriptor md, Model model, Session session, String param) ==> gives the value of a boolean Parameter


createParam (ModelDescriptor md, Model model, Session session, String param, String paramValue) ==> creates a new Parameter

createParamValueFromString(String s)==> converts a String value to the Parameter corresponding (integer, Double, String or boolean) value.

short java script to show params (used in async environment):

public static ModelDescriptor md = null;
private static Model model = null;
private static Session session = null;

session = connection.GetSession();
md = pfcModel.ModelDescriptor_CreateFromFileName (objectToRetrieve );
model = session.RetrieveModel(md);

md = pfcModel.ModelDescriptor_CreateFromFileName (objectToRetrieve );

HandleParams HPars = new HandleParams();
try {
Parameters pars = model.ListParams();
System.out.println ("arraysize = " + pars.getarraysize());
for (int x=0;x<pars.getarraysize();x++){<br/>System.out.println (HPars.showParam(md, model, session, pars.get(x).GetName()));
}
}
catch ( Exception x ) {
System.out.println ( "caught exception by arraysize" + x );
}

In this code the showParam method is used, for the parameters in the Proe file. Setting params (setParam) works simular exept that you have to indicate the name of the parameter and the value as string. So HPars.setParam(md, model, session, "name parameter", "value parameter")

f.y.i. most of these methods I never used, but the showParams and the setParam methods I used for sure. So do'not worry is some do not do what they promise to do.


I hope this is what you needed. "

Announcements
Attention: Creo 7.0 Customers
Please consider upgrading
End of Life announcement here.

NEW Creo+ Topics:
PTC Control Center
Creo+ Portal
Real-time Collaboration