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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

DefaultUICommandBracketListener on user created command

MichelH
12-Amethyst

DefaultUICommandBracketListener on user created command

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
sjuraj
13-Aquamarine
(To:MichelH)

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();

 

View solution in original post

8 REPLIES 8

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...

This sounds VERY interessting! I will test it, as soon as possible  and give a feedback. Thank you ysinitsyn!

 

sjuraj
13-Aquamarine
(To:MichelH)

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();

 

MichelH
12-Amethyst
(To:sjuraj)

That's exactly what I was looking for! Thank you very much sjuraj!

Top Tags