Use ScriptWriter with MyToolbar Example

Hello,

I wanted to try to modify the example “my toolbar” and added a button (with Swing) that will trigger a script, but i’m stuck.
I’m having trouble understanding the use of ScriptWriter.
if I try to take the example with the generateScript () method. I have an error telling me:
The method generateScript(ScriptWriter) of type MyToolbarContribution must override or implement a supertype method

Can you help me run a script when pressing the button please ?

I could be wrong but I don’t think you need a generateScript() method in the toolbar contribution. Assuming you are using the ScriptCommand and ScriptSender classes, the following code is something I use to jog the robot from the toolbar:

movePose1.addMouseListener(new MouseAdapter() {

		@Override
		public void mousePressed(final MouseEvent e) {
			if(movePose1.isEnabled()) {
				//create a new instance of the ScriptCommand class
				final ScriptCommand moveJ = new ScriptCommand();
				//create a new String to hold the command
				String string = "movej(" + getFavPose1().toString() + ", a=1.4, v=0.30, t=0, r=0)";
				//assign the newly created command as Primary. Secondary commands cannot consume robot time
				moveJ.setAsPrimaryProgram();
				//add the created string to the command
				moveJ.appendLine(string);
				//create a new instance of a ScriptSender
				final ScriptSender sender = new ScriptSender();
				//send the created script using the newly created sender
				sender.sendScriptCommand(moveJ);
			}
		}

		@Override
		public void mouseReleased(final MouseEvent e) {
			if (movePose1.isEnabled()) {
				
				final ScriptCommand stopj = new ScriptCommand();
				String string = "stopj(2)";
				stopj.setAsPrimaryProgram();
				stopj.appendLine(string);
				
				final ScriptSender sender = new ScriptSender();
				sender.sendScriptCommand(stopj);
			}
		}
	});

I don’t remember exactly where I found these 2 classes. They were somewhere on the forum I think.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.