Message 1 of 5
I could not able to run this add in
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to create some simple stuff
import adsk.core, adsk.fusion, adsk.cam, traceback
# Global list to keep all event handlers in scope.
# This is only needed with Python.
handlers = []
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Get the CommandDefinitions collection.
cmdDefs = ui.commandDefinitions
# Create a button command definition.
buttonSample = cmdDefs.addButtonDefinition('MyButtonDefIdPython',
'Python Sample Button',
'Sample button tooltip',
'Resources'
)
# Connect to the command created event.
sampleCommandCreated = SampleCommandCreatedEventHandler()
buttonSample.commandCreated.add(sampleCommandCreated)
handlers.append(sampleCommandCreated)
# Get the ADD-INS panel in the model workspace.
addInsPanel = ui.allToolbarPanels.itemById('CAMActionPanel')
# Add the button to the bottom of the panel.
buttonControl = addInsPanel.controls.addCommand(buttonSample)
buttonControl.isPromotedByDefault = True
buttonControl.isPromoted = True
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the commandCreated event.
class SampleCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
cmd = eventArgs.command
# Connect to the execute event.
onExecute = SampleCommandExecuteHandler()
cmd.execute.add(onExecute)
handlers.append(onExecute)
# Event handler for the execute event.
class SampleCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
eventArgs = adsk.core.CommandEventArgs.cast(args)
try:
# Code to react to the event.
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.activeDocument
products = doc.products
product = products.itemByProductType('CAMProductType')
# check if the document has a CAMProductType
if product == None:
ui.messageBox('There are no CAM operations in the active document. This script requires the active document to contain at least one CAM operation.',
'No CAM Operations Exist',
adsk.core.MessageBoxButtonTypes.OKButtonType,
adsk.core.MessageBoxIconTypes.CriticalIconType)
return
cam = adsk.cam.CAM.cast(product)
# specify the program name
programName = doc.name
outputFolder = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
# fileDlg = ui.createFileDialog()
# fileDlg.isMultiSelectEnabled = False
# fileDlg.title = 'Fusion Post File Dialog'
# fileDlg.filter = '*.*'
postConfig = os.path.join(cam.genericPostFolder, 'dump.cps')
# specify the NC file output units
units = adsk.cam.PostOutputUnitOptions.DocumentUnitsOutput
# create the postInput object
postInput = adsk.cam.PostProcessInput.create(programName, postConfig, outputFolder, units)
postInput.isOpenInEditor = True
scenario = 1
if scenario == 1:
# ui.messageBox('All toolpaths will be posted')
cam.postProcessAll(postInput)
elif scenario == 2:
setup = cam.setups.item(0)
cam.postProcess(setup, postInput)
ui.messageBox('Post processing is complete. The results have been written to:\n"' + os.path.join(outputFolder, programName) + '.dmp"')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Clean up the UI.
cmdDef = ui.commandDefinitions.itemById('MyButtonDefIdPython')
if cmdDef:
cmdDef.deleteMe()
addinsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cntrl = addinsPanel.controls.itemById('MyButtonDefIdPython')
if cntrl:
cntrl.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I don't know where i am making mistake.
Boopathi Sivakumar
Sr Application Engineer
www.usamcadsoft.in
Facebook | Twitter | LinkedIn