Community Tip - You can change your system assigned username to something more personal in your community settings. X
Hello everyone!
I am working with macros using OTK Java.
I need to run one macro twice.
Once I do this and everything works, and on the second start, an XToolkitNotValid exception is thrown.
I tried to activate the window before running the macro, display the model, etc.
But nothing helped.
Does anyone know what the problem is?
Thanks in advance.
Regards!
Solved! Go to Solution.
Hello all,
There is no need to add macros to config.pro.
What this article is telling us is to make two UI commands. (UICreateCommand in C++ OTK)
The first UI command (which starts the whole process) should be placed on the ribbon for a user to click...
The first UI command does whatever it has to do and in the end calls some macro string which does what you need this macro to accomplish with a user doing something interactively...
This macro string in its last statement has to call the second UI command, something like this:
mapkey(continued) ~ Command `UI2`;
The second UI command, after it would be called by the first macro ,would have a control over pro/e session, again.
The event loop per this article goes like this:
1. a user interactively calls the 'ribbon-shown' command.
2. OTK gets control over pro/e session and does some work.
3 OTK calls a macro at the end of its run.
4. Control returns back to pro/e, macro executes, possible interactive user actions.
5. the macro calls command#2-click at the end of its run.
6. OTK starts execution of command #2 with the control back to OTK.
HIH.
FV.
Macro from toolkit have many limitations. Very depend what you do and were you do this.
Maybe some code sample post there?
Thanks for the answer.
I attach the macro code:
"~ Command `ProCmdMdlTreeSearch` ;" +
"~ Input `selspecdlg0` `SelOptionRadio` `Note`;" +
"~ Activate `selspecdlg0` `SelectButton`;" +
"~ Command `ProCmdEditDelete`;";
Hello.
Macro text looks not bad.
Maybe you call macro sequence from loop?
Please, show Java part of the code where you call macros.
Hello!
I run this macro in two places:
- when creating a part:
private void executeMacroForPartDrw() throws jxthrowable {
drwOfPart.Display();
Macro macro = new Macro(session);
macro.execute(codeSelectionForMacro());
}
- when creating an assembly (here it is used in a loop, but once, for one instance. Using the instanseof operator):
private void executeMacroForAsmDrw(Scheme scheme) throws jxthrowable {
if (scheme instanceof FirstScheme) {
drwOfAsm.Display();
Macro macro = new Macro(session);
macro.execute(codeSelectionForMacro());
}
}
Hm... Looks like you hide OTK functions in your objects and functions, so difficult to see the trues 😉
pfcSession.BaseSession.RunMacro load text of the macros to the stack. The macro is executed only when control returns to Creo Parametric.
Try to execute macro manually by calling wfcWSession.WSession.ExecuteMacro after RunMacro.
And there is.
The fact is that everything is written in my class as you said.
Here is its method:
public void execute (String macroCode) throws jxthrowable {
session.GetCurrentWindow().Activate();
session.RunMacro(macroCode);
((WSession)session).ExecuteMacro();
}
If the Macro (mapkey) does not return the Creo UI to the original state that it should start from... running it again will likely result in an error.
So make sure your macro/mapkey are returning the Creo UI back to the original starting point as part of the complete mapkey.
Thanks for the answer.
It seems that my macro is returning to the starting point.
Here is my code:
"~ Command `ProCmdMdlTreeSearch` ;" +
"~ Input `selspecdlg0` `SelOptionRadio` `Note`;" +
"~ Activate `selspecdlg0` `SelectButton`;" +
"~ Command `ProCmdEditDelete`;";
As I understand it, I need to do this:
"Adding the above commands in Creo Parametric UI."
That is, do I need to write both macros in config.pro?
Hello all,
There is no need to add macros to config.pro.
What this article is telling us is to make two UI commands. (UICreateCommand in C++ OTK)
The first UI command (which starts the whole process) should be placed on the ribbon for a user to click...
The first UI command does whatever it has to do and in the end calls some macro string which does what you need this macro to accomplish with a user doing something interactively...
This macro string in its last statement has to call the second UI command, something like this:
mapkey(continued) ~ Command `UI2`;
The second UI command, after it would be called by the first macro ,would have a control over pro/e session, again.
The event loop per this article goes like this:
1. a user interactively calls the 'ribbon-shown' command.
2. OTK gets control over pro/e session and does some work.
3 OTK calls a macro at the end of its run.
4. Control returns back to pro/e, macro executes, possible interactive user actions.
5. the macro calls command#2-click at the end of its run.
6. OTK starts execution of command #2 with the control back to OTK.
HIH.
FV.
Thank you!