Create a feature on the timeline without closing command dialog in an Add In

Create a feature on the timeline without closing command dialog in an Add In

ebunn3
Advocate Advocate
648 Views
7 Replies
Message 1 of 8

Create a feature on the timeline without closing command dialog in an Add In

ebunn3
Advocate
Advocate

Hi all,

 

is there a way to create a feature (like a draft feature for example) on the timeline without having to close the form in an Add-In?   Currently I get a preview of the feature and then have to hit Enter to create the permanent feature subsequently closing the form.  I’d like to keep it running and have the ability to create additional features before closing.   

If someone could tell me if this is possible and point me towards an example that would be great.  

Eric

0 Likes
Accepted solutions (1)
649 Views
7 Replies
Replies (7)
Message 2 of 8

kandennti
Mentor
Mentor

Hi @ebunn3 .

 

If you create a solid body in advance and run this sample script, it will create a draft without displaying the dialog.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-f8e0b8e8-f30f-11e4-85e6-005056c00008 

1.png

 

0 Likes
Message 3 of 8

ebunn3
Advocate
Advocate

I’ll post some code as an example.   I am building an addin that will provide additional functionality to the user.  I want the user to be able to perform the draft function as well as others.  Currently the command dialog cannot create the actual draft feature without clicking the OK button, it only creates a preview when a face is clicked.  Before that they get only a preview of the draft.   I hope that make sense.   I’ll post a sample.  

Eric

0 Likes
Message 4 of 8

ebunn3
Advocate
Advocate

I found this other post looking to do something similar.   Looks like it is not possible to do what I would like.  

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/dialog-opening-dialog/m-p/9486441#M10000 

 

I am looking to do something similar.   A master user form with multiple commands.   I sited the draft function as an example only.   Could be a draft operation followed by a fillet operation as a for instance.   

Eric

0 Likes
Message 5 of 8

kandennti
Mentor
Mentor

@ebunn3 .

 

I am sorry, but I could not understand the meaning at all just from the words.

0 Likes
Message 6 of 8

ebunn3
Advocate
Advocate

@kandennti 

 

No need to apoligize.  I should have posted an example.  I think I've determined that what I'm trying to do is not possible.  I'm working on learning how to create a toolbar panel and load my addin buttons into that.  There is one style called a split-button command that might work as an alternative?  Not sure.  

 

Eric

0 Likes
Message 7 of 8

BrianEkins
Mentor
Mentor
Accepted solution

You can create your own panel in the UI, to group your commands together. Using a drop-down would be another way. One other possibility is to create a palette and have some buttons in it that, when clicked would execute the corresponding command. A palette doesn't have the same lifetime rules as a command and can remain open while you run other commands. Here's the help content that describes what a palette is. Grouping commands somehow in the UI will be easier though.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-6C0C8148-98D0-4DBC-A4EC-D8E03A8A3B5B

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 8 of 8

ebunn3
Advocate
Advocate

Brian,

 

This worked well for me.  Thank you.  I've posted a code snippet for anyone else trying to do this.

 

Eric

#globals
#these are used in the run and stop functions
butName = 'Mushroom Tray Layout Calculator' #choose a unique id for the button
eco_Tab = 'ecoTab'
eco_Tab_Name = 'Eco Add-Ins'
eco_Panel = 'ecoTrayPanel'
eco_Panel_Name = 'Tray Design Add-In'
controlName = 'TrayLayoutControl' #choose a unique id for the control
butDialogName = 'Tray Layout Dialog' #choose a name for the button
tooltip = 'Auto Create Nested Tray Layout from Cushion Shape' #create a tooltip for the button when someone hovers over it
folderName = 'resources' #create a folder in the directory to hold the icon files and put it's name here

def run(context):
    """The run function is the main function that runs first when loading the Add-in.
    It will add a toolbar button to the ui which will be controlled by the comPressedEventHandler class functions."""
    ui = None
    global units
    try:
        #get the application
        app = adsk.core.Application.get()
        ui  = app.userInterface

         #Get command definitions & design workspace##################################################################################################
        cmd_def = ui.commandDefinitions
        des_wp = ui.workspaces.itemById('FusionSolidEnvironment')

        # Add the Eco Tab to the Workspace.
        eco_tab = des_wp.toolbarTabs.itemById(eco_Tab)
        if not eco_tab:
            eco_tab = des_wp.toolbarTabs.add(eco_Tab, eco_Tab_Name)

        # Add the Tray Design panel.
        addin_panel = eco_tab.toolbarPanels.itemById(eco_Panel)
        if not addin_panel:
            addin_panel = eco_tab.toolbarPanels.add(eco_Panel, eco_Panel_Name,eco_tab.id, False)
        #Get command definitions & design workspace##################################################################################################


        #Add a button CommandDefininition to that collection
        # folder name (within same directory) for icons 16X16, 32X32 & 64X64.png) (change button properties in global variables on top)
        ret = readConstants("RevisionNumber.txt")
        comDef = cmd_def.itemById(butName)
        if not comDef:
            comDef = cmd_def.addButtonDefinition(butName,
            butDialogName + " Rev " + ret[0][1],
            tooltip,
            folderName)

        #Grabbing the correct toolbar panel to add the button to
        addinsToolbarPanel = addin_panel
        #Adding the button to the toolbar Panel
        comControl = addinsToolbarPanel.controls.addCommand(comDef,controlName)
        #Making the button visible without having to use the dropdown
        comControl.isPromotedByDefault = True

        #Setting up the handler if the button is pressed
        #Calling the class
        comPressed = comPressedEventHandler()
        comDef.commandCreated.add(comPressed)
        handlers.append(comPressed)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))