Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Dear community,
I am trying to use a pfcCommand.DefaultUICommandBracketListener to catch a call of a user defined command (SESSION.UICreateCommand). This works fine as long as the user interactively clicks that command. But I need to launch the command in my code (by using the OnCommand method). But then the bracket listener is not working.
Does anybody know if I have to trigger the command in a different way?
Thank you and kind regards
Michael
Solved! Go to Solution.
Easy:
//Register your command (you do not even need to Designate command)
... some code with your listener
String cmdName = "MyCommandName";
UICommand cmd = session.UICreateCommand(cmdName, listener);
... another code
//Then call it at end of your first command
... some code
Session.RunMacro(~ Command `" + cmdName + "`;");
I have several commands using this technique. I is workaround for WSession.ExecuteMacro, which is part of paid Java toolkit.
If you need some data to pass DOES NOT use static objects (you could but it is bad design), instead use same instance of object shared by both commands for in constructor eg:
Container container = new Container();
MyCmd1 cmd1 = new MyCmd1(container);
MyCmd2 cmd2 = new MyCmd2(container);
//in cmd1
container.setSomeField(model.GetFileName());
//in cmd2
String fileName = container.getSomeField();
Maybe, something like this
class CommandBracketListener extends DefaultUICommandBracketListener
{
public Session session;
public CommandBracketListener (Session currentSession)
{
session = currentSession;
} /*====================================================================*\
FUNCTION : OnAfterCommand()
PURPOSE : Function called after rename execution is complete.
\*====================================================================*/
public void OnAfterCommand()
{
}
}
CommandBracketListener deflistener = new CommandBracketListener(session);
deflistener.OnAfterCommand();
Thank you ysinitsyn!
This is possible, but I would need to know which CommandBracketListeners are active. I wanted to emulate a click on a button triggering a command inside my code not knowing which BracketListeners are currently active.
Maybe the CommandBracketListener only work for real mouse clicks by the user!?
Not sure that I clear understand you task.
But, you can write a Mapkey (a click on a button) and play this mapkey code from your otk app.
Not very elegant, but should work.
In OTK Java free mapkeys get only executed after Creo gets back the handle - after the code has been executed. So unfortunately in my case mapkeys won't work...
About mapkey, take a look the solution at this post
https://community.ptc.com/t5/Customization/Restarting-macro-OTK-Java/m-p/658004#M9460%3F
This sounds VERY interessting! I will test it, as soon as possible and give a feedback. Thank you ysinitsyn!
Easy:
//Register your command (you do not even need to Designate command)
... some code with your listener
String cmdName = "MyCommandName";
UICommand cmd = session.UICreateCommand(cmdName, listener);
... another code
//Then call it at end of your first command
... some code
Session.RunMacro(~ Command `" + cmdName + "`;");
I have several commands using this technique. I is workaround for WSession.ExecuteMacro, which is part of paid Java toolkit.
If you need some data to pass DOES NOT use static objects (you could but it is bad design), instead use same instance of object shared by both commands for in constructor eg:
Container container = new Container();
MyCmd1 cmd1 = new MyCmd1(container);
MyCmd2 cmd2 = new MyCmd2(container);
//in cmd1
container.setSomeField(model.GetFileName());
//in cmd2
String fileName = container.getSomeField();
That's exactly what I was looking for! Thank you very much sjuraj!