Can't get my script to run! No dialog box -_-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
Let me begin by saying I am new to coding with Python (about 3 weeks experience), but am quickly learning how to navigate through the API and execute some tasks. I have been following these videos: click here and learning fast.
BUT I have run into a problem. I am trying to create a little dialogue box within fusion when my script runs. I have defined an event and a handler and all that and still nothing comes up. Here is a breakdown of my code...
1. Random extrusions at start up are created
2. Created a command definition for a button and placed that button inside the toolbar
3. Created an event and handler for the button
4. Created command inputs (selection inputs and then a dropdown)
4. When i click the button in the toolbar.... nothing happens
I am looking to create a dialogue box which I can then link to drawing functions. But I can't even get as far as creating a dialogue.
Any help is appreciated.
CODE:
#Author- #Description- import adsk.core, adsk.fusion, adsk.cam, traceback def run(context): try: app = adsk.core.Application.get() ui = app.userInterface doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType) design = app.activeProduct handlers = [] # Get the root component of the active design. rootComp = design.rootComponent # Create a new sketch on the xy plane. sketches = rootComp.sketches xyPlane = rootComp.xYConstructionPlane sketch1 = sketches.add(xyPlane) Load_circles = sketch1.sketchCurves.sketchCircles #load circle API circle1 = Load_circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), 1.5) #define the circle and draw it #get profile of sketch profile1 = sketch1.profiles.item(0) extrusion1 = rootComp.features.extrudeFeatures #define the extrusion extrude1_input = extrusion1.createInput(profile1,adsk.fusion.FeatureOperations.NewComponentFeatureOperation) #load the extrusion input library extrude1_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(4)) #Set parameters for the extrusion input FinishExtrude1 = extrusion1.add(extrude1_input) #execute the extrusion sketch2 = sketches.add(xyPlane) #create sketch 2 Load_lines = sketch2.sketchCurves.sketchLines #load the line API Line1 = Load_lines.addByTwoPoints(adsk.core.Point3D.create(0, 0, 0), adsk.core.Point3D.create(2, 0, 0)) Line2 = Load_lines.addByTwoPoints(adsk.core.Point3D.create(2,0,0), adsk.core.Point3D.create(2,2,0)) Line3 = Load_lines.addByTwoPoints(adsk.core.Point3D.create(2,2,0), adsk.core.Point3D.create(0,2,0)) #draw lines (start, end) Line4 = Load_lines.addByTwoPoints(adsk.core.Point3D.create(0,2,0), adsk.core.Point3D.create(.5,1,0)) Line5 = Load_lines.addByTwoPoints(adsk.core.Point3D.create(.5,1,0), adsk.core.Point3D.create(0,0,0)) profile2 = sketch2.profiles.item(0) #grab the profile of sketch 2 extrusion2 = rootComp.features.extrudeFeatures #define the extrusion extrude2_input = extrusion2.createInput(profile2,adsk.fusion.FeatureOperations.NewComponentFeatureOperation) #load the extrusion input library extrude2_input.setDistanceExtent(False, adsk.core.ValueInput.createByReal(4)) #Set parameters for the extrusion input FinishExtrude2 = extrusion2.add(extrude2_input) #adding to handler class addin_menu_button_pressedEventHandler(adsk.core.CommandCreatedEventHandler): def __init__(self): super().__init__() def notify(self,args): try: app = adsk.core.Application() ui = app.userInterface cmd = args.commandInputs inputs = cmd.commandinputs handlers = [] input1 = inputs.addSelectionInput(Selection1, "Face: ", "Select a Face") input2 = inputs.addDropDownCommandInput(Dropdown1,Dropdown, 1) on_execute = addin_menu_button_pressedEventHandler() cmd.execute.add(on_execute) handlers.append(on_execute) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) Load_command = ui.commandDefinitions #load command defs definition_1 = Load_command.addButtonDefinition("identifier","BMScript","BOb First Addin for Fusion360!","Resources") #button definition addin_location = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel') #button location addin_menu_button = addin_location.controls.addCommand(definition_1,"Script") #place the button addin_menu_button.isPromotedByDefault = True #premoted = on top of toolbar addin_menu_button.isPromoted = True #handler: addin_menu_button_pressed = addin_menu_button_pressedEventHandler() #make var for class definition_1.commandCreated.add(addin_menu_button_pressed) # handlers.append(addin_menu_button_pressed) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Regards,
X