Message 1 of 5
Not applicable
09-28-2018
08:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All.
I've been trying to create an add-in with a button to execute it like:
def run(context):
try:
global _app, _ui, _design, _thistree, thisdocsunits
_app = adsk.core.Application.get()
_ui = _app.userInterface
product = _app.activeProduct
_design = adsk.fusion.Design.cast(product)
thisdocsunits = _design.unitsManager.defaultLengthUnits
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
logging.basicConfig(filename=os.path.join(os.path.expanduser("~"),'urdfgen.log'),level=logging.DEBUG)
workSpace = _ui.workspaces.itemById('FusionSolidEnvironment')
tbPanels = workSpace.toolbarPanels
global tbPanel
tbPanel = tbPanels.itemById('NewPanel')
if tbPanel:
tbPanel.deleteMe()
tbPanel = tbPanels.add('NewPanel', 'New Panel', 'SelectPanel', False)
# Get the existing command definition or create it if it doesn't already exist.
addlinkcmdDef = _ui.commandDefinitions.itemById('cmdInputsAddLink')
if not addlinkcmdDef:
addlinkcmdDef = _ui.commandDefinitions.addButtonDefinition('cmdInputsAddLink', 'Make URDF', 'My attempt to make an URDF.')
# Connect to the command created event.
onCommandCreated = AddLinkCommandCreatedHandler()
addlinkcmdDef.commandCreated.add(onCommandCreated)
_handlers.append(onCommandCreated)
# will try to create a button for this guy
tbPanel.controls.addCommand(addlinkcmdDef)
_thistree = UrdfTree()
# Execute the command definition.
#addlinkcmdDef.execute()
# Prevent this module from being terminated when the script returns, because we are waiting for event handlers to fire.
adsk.autoTerminate(False)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))I create a tab in the class (and also the handles for execute, inputChanged and destroy):
AddLinkCommandCreatedHandler()
## things...
and it all works just fine the first time around.
But once I cancel the command and try to execute it a second time, nothing happens, as in, it does not seem to trigger neither execution nor the class.
I wonder If i should have registered more handles, or if I am creating the tab in the wrong context.
The whole code is rather lengthy, but in case anyone wants to see it, one may see it here: https://github.com/GummiArmCE/fusion360_scripts/tree/master/urdf_generator
Thank you very much for the help,
Frederico.
Solved! Go to Solution.
