Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Method - "addButtonDefinition"

8 REPLIES 8
Reply
Message 1 of 9
copypastestd
721 Views, 8 Replies

Method - "addButtonDefinition"

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

8 REPLIES 8
Message 2 of 9
copypastestd
in reply to: copypastestd

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

 

Box.JPG

 

 

Message 3 of 9
Six1Seven1
in reply to: copypastestd

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
Message 4 of 9
copypastestd
in reply to: Six1Seven1

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.

Message 5 of 9
Six1Seven1
in reply to: copypastestd

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,

Message 6 of 9
ekinsb
in reply to: copypastestd

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
Message 7 of 9
copypastestd
in reply to: ekinsb

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)

 

Message 8 of 9
ekinsb
in reply to: copypastestd

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
Message 9 of 9
eric
in reply to: Six1Seven1

k.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report