Method - "addButtonDefinition"

Method - "addButtonDefinition"

copypastestd
Advocate Advocate
1,115 Views
8 Replies
Message 1 of 9

Method - "addButtonDefinition"

copypastestd
Advocate
Advocate

Hello there

 

I am tring redo Bolt example for my purposes. There is some part of original code.

if not cmdDef:
    cmdDef = commandDefinitions.addButtonDefinition('Bolt',
            'Create Bolt',
            'Create a bolt.',
            './resources') # relative resource file path is specified

I need to change names of some variables and do little changes in apperiance.

 

But after renaming nothing hapend untill I reload Fusion 360.

if not cmdDef:
    cmdDef = commandDefinitions.addButtonDefinition('Box',
            'Create Box',
            'Create a box.',
            './resources') # relative resource file path is specified

Bolt.JPG

0 Likes
1,116 Views
8 Replies
Replies (8)
Message 2 of 9

copypastestd
Advocate
Advocate

Another problem that afrer renaming, at some moment UI input window changed to default. And I couldn't turn it back.

 

Box.JPG

 

 

0 Likes
Message 3 of 9

Six1Seven1
Advocate
Advocate
I'm not sure what exactly you are asking for. The reason you have to reload fusion when you want to re-execute the script is likely due to the STOP function not deleting the button when hitting 'stop' from the addin menu.

Also it's a good idea to make sure you have an icon in the resources path in the button definition.

Regards
0 Likes
Message 4 of 9

copypastestd
Advocate
Advocate

Tnx for your reply.

 

Let me refrase.

 

I am trying to do a script, which would do a box via the code.

 

Actually, general part is done (it works through hardcode parameters), but I wonna add input paramaters window like in picture above.

Where user could fill in thickness, sizes etc for desired box.

 

When I tried to use Bolt example as a template, I had some problems.

 

In code I renamed all variables, handlers, and other names from Bolt to Box (for example: BoltCommandExecuteHandler => BoxCommandExecuteHandler).

I looked at the whole code to double check it.

 

But as a result I have default input window:

large.png

 

I hope that it became a little clearer.

0 Likes
Message 5 of 9

Six1Seven1
Advocate
Advocate

Oh, I see what you are saying.

 

I don't quite see the purpose of re-naming someone elses Add-in anyhow. You will be better off learning how to create a dialogue box by writing your own add-in from the ground up.

 

 

 

 

regards,

0 Likes
Message 6 of 9

ekinsb
Alumni
Alumni

That's not a default input window but is a command window that contains the command inputs defined by that add-in.  You need to look at the handler for the command created event.  You'll find the API calls there where it's creating the selection and drop down command inputs that you're seeing.  You'll want to replace those calls a string value input and several value inputs.  And in the handler function for the execute event you'll need to read the values of those inputs and use those to create the box.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 7 of 9

copypastestd
Advocate
Advocate

You are right, it is not a "default" windows as I thought before.

 

My problem was in renaming. I named my inner class - Box(), this name the same as build-in comand Box.

Box.png

Problem disappered when I change name to something unique - BOX() or Boxx() - work fine.

 

But I still don't know how to change this parameters without reload Fusion 360 - to see changes.

returnValue = commandDefinitions_var.addButtonDefinition(id, name, tooltip, resourceFolder)

 

0 Likes
Message 8 of 9

ekinsb
Alumni
Alumni

You shouldn't have to shut down and restart Fusion after every code change if you're add-in is behaving correctly.  Mainly, by "behaving correctly" I mean that it cleans up everything in the stop function that it added to the UI in the run function.  Otherwise it will try creating a command definition using the name of one that already exists and will fail there.

 

Assuming your add-in does clean up after itself correctly, here are the steps to stopping and restarting an add-in after making changes to your code:

 

  1. Go to the "Scripts and Add-Ins" command, find your add-in (which should have the little circle of dots beside it indicating it is running), select it, and click the "Stop" button on the dialog.
  2. In the "Scripts and Add-Ins" dialog, select your add-in and click the "Run" button.

That should be it.  

 

If you're debugging your add-in, you should first make sure that you're not at a break point and your program is halted.  You can click the "Continue Execution" button to have it continue running.  If there are any message boxes displayed you'll need to click on those so your add-in and continue.  You can also click the "Exit Debug" command to stop execution, which will likely cause one or more message boxes to be displayed that you'll need to dismiss.  Then you'll still need to stop and restart your add-in in the "Scripts and Add-Ins" dialog.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 9 of 9

eric
Contributor
Contributor

k.

0 Likes