Hello everyone! My company uses Creo 7.0.9. I am utilizing J-Link (Java Object Toolkit free) to create some programs to automate some repetitive tasks. I need your help in automating the running of predefined FEA simulations, or at least fixing my code so far...
_______________________________________________________________________________________________
Problem Background / Goal:
One of the features I want to have in my J-Link programs is the ability to rerun predefined simulations from code... meaning I as the engineer set up everything from conditions to loads, and get the simulation all ready to go, and my J-Link application really just has to hit the run button. The use case here is: I have other already functioning j-link code to change parameters of loads, so the idea is in the future, I can have some automated way of testing 15 different loads, running the FEA each time, saving results, and maybe even making me a graphic or something like that...
____________________________________________________________________________________________
Efforts so far:
I have attempted a few ways to do this.
1. I successfully created a map key that opens the simulate environment, opens the analysis and design study window and clicks run. This works perfectly. When I am in creo. I just hit F2, and then my simulation runs... I then attempted to use J-Link to run the mapkey, but Jlink does not do this. There are no errors no crashes, and nothing in the Trail.txt file, but also nothing happens when I run the program. I have attached code and my config.pro file with the mapkey below in case you want to see... Eventually I gave up on this.
2. I attempted directly running each of the macros contained within the mapkey file in JLink using session.RunMacro("MACRO TEXT HERE") and session.ExecuteMacro(). This ended up working (sort of)... I was able to run the first few macros to open up the simulation environment and to open the analysis and design studies window, but after that it just stops. Regardless of what windows I activate or what I try to do, it refuses to actually run the FEA. I basically want the program to hit the green flag button, but it will not.
3. I have tried to find a way to do this natively through the creo API, but so far I have not found anything promising. I tried to use pushbutton to simulate a button click, but I just get a bunch of errors. I am pretty sure the API isn't designed for me to use this to simulate clicking the run button, but correct me if there is a good way to do this...
_________________________________________________________________________________________________
What I am looking to hear from you
1. does anyone know if this is even allowed/possible? The thought occurred to me that perhaps this is intentionally blocked with J-Link and only possible with the full OTK. Do I need to buy something, so this gets enabled?
2. Is this some sort of permissions issue? Is the program not allowed to run simulations?
3. Is there any obvious error in my code? Do you have any fixes or suggestions for me?
4. Is there another/better way to do this?
I would greatly appreciate any concrete sample code you can provide to help me solve this issue.
_________________________________________________________________________________________________
config.pro file containing Mapkey for running my FEA
mapkey $F2 @MAPKEY_NAMEEnable Jlink to automate running FEA studies;\
mapkey(continued) @MAPKEY_LABELLinkRunFEA;\
mapkey(continued) ~ Activate `main_dlg_cur` `page_Applications_control_btn` 1;\
mapkey(continued) ~ Command `ProCmdAppMechanica` 1;~ Command `ProCmdSimMechSol` ;\
mapkey(continued) ~ Activate `run` `RunToolBtn`;~ Activate `UI Message Dialog` `yes`;\
mapkey(continued) ~ Activate `UI Message Dialog` `no`;~ Activate `run` `ClosePush`;\
mapkey(continued) ~ Command `ProCmdAppMechanicaExit`;
__________________________________________________________________________________________________
An attempt to run the FEA using directly(note: I have tried adding 5 second delays between all macros just to give creo a moment to enter the simulate environment properly before spamming another macro through J-Link, but it did not make a difference).
method call:
runFEAAnalysis(session);
method:
public void runFEAAnalysis(Session session) {
try {
System.out.println("Starting FEA analysis...");
// Step 1: Activate the Applications tab
session.RunMacro("~ Activate `main_dlg_cur` `page_Applications_control_btn` 1;");
System.out.println("Activated Applications tab.");
// Step 2: Enter Simulate mode
session.RunMacro("~ Command `ProCmdAppMechanica` 1;");
System.out.println("Entered Simulate mode.");
// Step 3: Open the Analysis and Design Studies window
session.RunMacro("~ Command `ProCmdSimMechSol`;");
System.out.println("Opened Analysis and Design Studies window.");
// Step 4: Click the green flag to run the simulation
session.RunMacro("~ Activate `run` `RunToolBtn`;");
System.out.println("Clicked the green flag to run the simulation.");
// Step 5: Handle file overwrite prompt
session.RunMacro("~ Activate `UI Message Dialog` `yes`;");
System.out.println("Handled file overwrite prompt.");
// Step 6: Handle diagnostics prompt
session.RunMacro("~ Activate `UI Message Dialog` `no`;");
System.out.println("Handled diagnostics prompt.");
// Step 7: Close the results window
session.RunMacro("~ Activate `run` `ClosePush`;");
System.out.println("Closed results window.");
// Step 8: Exit Simulate mode
session.RunMacro("~ Command `ProCmdAppMechanicaExit`;");
System.out.println("Exited Simulate mode.");
System.out.println("FEA analysis completed successfully.");
} catch (jxthrowable e) {
System.err.println("Error during FEA analysis: " + e.getMessage());
e.printStackTrace();
}
}
___________________________________________________________________________________________________
Attempt using MapKey...
attempted method calls:
executeMacroAsync(session, "F2");
executeMacroAsync(session, "$F2");
executeMacroAsync(session, "LinkRunFEA");
executeMacroAsync(session, "Enable Jlink to automate running FEA studies");
method (2 different approaches):
public void executeMacroAsync(Session session, String macroCommand) {
try {
System.out.println("Running macro: " + macroCommand);
// Construct the mapkey command string
String macroString = "~ Activate `proe_win`; %" + macroCommand + ";";
try {
Thread.sleep(5000); // Add a delay
} catch (InterruptedException e) {
System.err.println("Thread was interrupted: " + e.getMessage());
Thread.currentThread().interrupt(); // Restore the interrupted status
}
// Run the macro
session.RunMacro(macroString);
System.out.println("RunMacro executed successfully for mapkey: " + macroCommand);
try {
Thread.sleep(5000); // Add another delay
} catch (InterruptedException e) {
System.err.println("Thread was interrupted: " + e.getMessage());
Thread.currentThread().interrupt(); // Restore the interrupted status
}
// Step 2: Cast Session to WSession and execute the macro explicitly
if (session instanceof WSession) {
WSession wSession = (WSession) session;
wSession.ExecuteMacro();
System.out.println("ExecuteMacro executed successfully.");
//JOptionPane.showMessageDialog(null, "Executing Macro Command!");
} else {
System.err.println("Session is not an instance of WSession. ExecuteMacro cannot be called.");
//JOptionPane.showMessageDialog(null, "Unable to connect to Wsession");
}
// Flush the current window to process UI updates
//session.FlushCurrentWindow();
System.out.println("FlushCurrentWindow executed successfully.");
} catch (jxthrowable e) {
System.err.println("Error executing macro: " + e.getMessage());
e.printStackTrace();
}
}
public void executeMacroAsync(Session session, String macroCommand) {
try {
System.out.println("Running macro: " + macroCommand);
// Step 1: Activate the Applications tab
String activateApplicationsTab = "~ Activate `main_dlg_cur` `page_Applications_control_btn` 1;";
session.RunMacro(activateApplicationsTab);
System.out.println("Activated Applications tab.");
// Step 2: Construct the mapkey command string
// Escape special characters if necessary
String macroString = "~ Command `$" + macroCommand.replace("`", "\\`") + "`;";
System.out.println("Constructed macro string: " + macroString);
// Step 3: Run the macro
session.RunMacro(macroString);
System.out.println("RunMacro executed successfully for mapkey: " + macroCommand);
// Step 4: Flush the current window to process UI updates
session.FlushCurrentWindow();
System.out.println("FlushCurrentWindow executed successfully.");
} catch (jxthrowable e) {
System.err.println("Error executing macro: " + e.getMessage());
e.printStackTrace();
}
}
_______________________________________________________________________________________________
Problem Background / Goal:
One of the features I want to have in my J-Link programs is the ability to rerun predefined simulations from code... meaning I as the engineer set up everything from conditions to loads, and get the simulation all ready to go, and my J-Link application really just has to hit the run button. The use case here is: I have other already functioning j-link code to change parameters of loads, so the idea is in the future, I can have some automated way of testing 15 different loads, running the FEA each time, saving results, and maybe even making me a graphic or something like that...
____________________________________________________________________________________________
Efforts so far:
I have attempted a few ways to do this.
1. I successfully created a map key that opens the simulate environment, opens the analysis and design study window and clicks run. This works perfectly. When I am in creo. I just hit F2, and then my simulation runs... I then attempted to use J-Link to run the mapkey, but Jlink does not do this. There are no errors no crashes, and nothing in the Trail.txt file, but also nothing happens when I run the program. I have attached code and my config.pro file with the mapkey below in case you want to see... Eventually I gave up on this.
2. I attempted directly running each of the macros contained within the mapkey file in JLink using session.RunMacro("MACRO TEXT HERE") and session.ExecuteMacro(). This ended up working (sort of)... I was able to run the first few macros to open up the simulation environment and to open the analysis and design studies window, but after that it just stops. Regardless of what windows I activate or what I try to do, it refuses to actually run the FEA. I basically want the program to hit the green flag button, but it will not.
3. I have tried to find a way to do this natively through the creo API, but so far I have not found anything promising. I tried to use pushbutton to simulate a button click, but I just get a bunch of errors. I am pretty sure the API isn't designed for me to use this to simulate clicking the run button, but correct me if there is a good way to do this...
_________________________________________________________________________________________________
What I am looking to hear from you
1. does anyone know if this is even allowed/possible? The thought occurred to me that perhaps this is intentionally blocked with J-Link and only possible with the full OTK. Do I need to buy something, so this gets enabled?
2. Is this some sort of permissions issue? Is the program not allowed to run simulations?
3. Is there any obvious error in my code? Do you have any fixes or suggestions for me?
4. Is there another/better way to do this?
I would greatly appreciate any concrete sample code you can provide to help me solve this issue.
_________________________________________________________________________________________________
config.pro file containing Mapkey for running my FEA
mapkey $F2 @MAPKEY_NAMEEnable Jlink to automate running FEA studies;\
mapkey(continued) @MAPKEY_LABELLinkRunFEA;\
mapkey(continued) ~ Activate `main_dlg_cur` `page_Applications_control_btn` 1;\
mapkey(continued) ~ Command `ProCmdAppMechanica` 1;~ Command `ProCmdSimMechSol` ;\
mapkey(continued) ~ Activate `run` `RunToolBtn`;~ Activate `UI Message Dialog` `yes`;\
mapkey(continued) ~ Activate `UI Message Dialog` `no`;~ Activate `run` `ClosePush`;\
mapkey(continued) ~ Command `ProCmdAppMechanicaExit`;
__________________________________________________________________________________________________
An attempt to run the FEA using directly(note: I have tried adding 5 second delays between all macros just to give creo a moment to enter the simulate environment properly before spamming another macro through J-Link, but it did not make a difference).
method call:
runFEAAnalysis(session);
method:
public void runFEAAnalysis(Session session) {
try {
System.out.println("Starting FEA analysis...");
// Step 1: Activate the Applications tab
session.RunMacro("~ Activate `main_dlg_cur` `page_Applications_control_btn` 1;");
System.out.println("Activated Applications tab.");
// Step 2: Enter Simulate mode
session.RunMacro("~ Command `ProCmdAppMechanica` 1;");
System.out.println("Entered Simulate mode.");
// Step 3: Open the Analysis and Design Studies window
session.RunMacro("~ Command `ProCmdSimMechSol`;");
System.out.println("Opened Analysis and Design Studies window.");
// Step 4: Click the green flag to run the simulation
session.RunMacro("~ Activate `run` `RunToolBtn`;");
System.out.println("Clicked the green flag to run the simulation.");
// Step 5: Handle file overwrite prompt
session.RunMacro("~ Activate `UI Message Dialog` `yes`;");
System.out.println("Handled file overwrite prompt.");
// Step 6: Handle diagnostics prompt
session.RunMacro("~ Activate `UI Message Dialog` `no`;");
System.out.println("Handled diagnostics prompt.");
// Step 7: Close the results window
session.RunMacro("~ Activate `run` `ClosePush`;");
System.out.println("Closed results window.");
// Step 8: Exit Simulate mode
session.RunMacro("~ Command `ProCmdAppMechanicaExit`;");
System.out.println("Exited Simulate mode.");
System.out.println("FEA analysis completed successfully.");
} catch (jxthrowable e) {
System.err.println("Error during FEA analysis: " + e.getMessage());
e.printStackTrace();
}
}
___________________________________________________________________________________________________
Attempt using MapKey...
attempted method calls:
executeMacroAsync(session, "F2");
executeMacroAsync(session, "$F2");
executeMacroAsync(session, "LinkRunFEA");
executeMacroAsync(session, "Enable Jlink to automate running FEA studies");
method (2 different approaches):
public void executeMacroAsync(Session session, String macroCommand) {
try {
System.out.println("Running macro: " + macroCommand);
// Construct the mapkey command string
String macroString = "~ Activate `proe_win`; %" + macroCommand + ";";
try {
Thread.sleep(5000); // Add a delay
} catch (InterruptedException e) {
System.err.println("Thread was interrupted: " + e.getMessage());
Thread.currentThread().interrupt(); // Restore the interrupted status
}
// Run the macro
session.RunMacro(macroString);
System.out.println("RunMacro executed successfully for mapkey: " + macroCommand);
try {
Thread.sleep(5000); // Add another delay
} catch (InterruptedException e) {
System.err.println("Thread was interrupted: " + e.getMessage());
Thread.currentThread().interrupt(); // Restore the interrupted status
}
// Step 2: Cast Session to WSession and execute the macro explicitly
if (session instanceof WSession) {
WSession wSession = (WSession) session;
wSession.ExecuteMacro();
System.out.println("ExecuteMacro executed successfully.");
//JOptionPane.showMessageDialog(null, "Executing Macro Command!");
} else {
System.err.println("Session is not an instance of WSession. ExecuteMacro cannot be called.");
//JOptionPane.showMessageDialog(null, "Unable to connect to Wsession");
}
// Flush the current window to process UI updates
//session.FlushCurrentWindow();
System.out.println("FlushCurrentWindow executed successfully.");
} catch (jxthrowable e) {
System.err.println("Error executing macro: " + e.getMessage());
e.printStackTrace();
}
}
public void executeMacroAsync(Session session, String macroCommand) {
try {
System.out.println("Running macro: " + macroCommand);
// Step 1: Activate the Applications tab
String activateApplicationsTab = "~ Activate `main_dlg_cur` `page_Applications_control_btn` 1;";
session.RunMacro(activateApplicationsTab);
System.out.println("Activated Applications tab.");
// Step 2: Construct the mapkey command string
// Escape special characters if necessary
String macroString = "~ Command `$" + macroCommand.replace("`", "\\`") + "`;";
System.out.println("Constructed macro string: " + macroString);
// Step 3: Run the macro
session.RunMacro(macroString);
System.out.println("RunMacro executed successfully for mapkey: " + macroCommand);
// Step 4: Flush the current window to process UI updates
session.FlushCurrentWindow();
System.out.println("FlushCurrentWindow executed successfully.");
} catch (jxthrowable e) {
System.err.println("Error executing macro: " + e.getMessage());
e.printStackTrace();
}
}