Feedback: Issue importing components
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm currently writing an add-in that brings in several components and have been having a weird issue where the add-in would become de-active (not sure if this is the right term, I mean that the my add-in can't be run again) after run once. This would only happen when one specific if statement was opened (that opened a component based on an input - in this case the problematic input was 'droplet'). The code seemed to otherwise run and complete without issue.
I have now put a time.sleep(1) command just before the if statement which has fixed the add-in deactivation issue. Putting a ui.messageBox command also worked. If anyone could provide some clarity as to why this might be happening that would be great. I'm quite happy leaving it as is, but it would be good to try and avoid the issue in future.
I have attached some of my code for reference.
def jointcreate(app, ui, importManager, userParams): try: # Get active design product = app.activeProduct design = adsk.fusion.Design.cast(product) # Create list of joints used jointlist = [] jointlist.append(_jointa.selectedItem.name) jointlist.append(_jointb.selectedItem.name) jointlist.append(_jointc.selectedItem.name) jointlist.append(_jointd.selectedItem.name) # Get root component rootComp = design.rootComponent # Opens joint a # Sets filename for opening (with path) filename = "%s/resources/parts/%s.f3d" %(_filelocation,jointlist[0]) # Sets options using file path f3dImportOptions = app.importManager.createFusionArchiveImportOptions(filename) # Opens file into current document app.importManager.importToTarget(f3dImportOptions, rootComp) # Opens joint b # Sets filename for opening (with path) filename = "%s/resources/parts/%s.f3d" %(_filelocation,jointlist[1]) # Sets options using file path f3dImportOptions = app.importManager.createFusionArchiveImportOptions(filename) # Opens file into document app.importManager.importToTarget(f3dImportOptions, rootComp) time.sleep(1) if _filein.selectedItem.name == 'y_junction': # Opens joint c # Sets filename for opening (with path) filename = "%s/resources/parts/%s.f3d" %(_filelocation,jointlist[2]) # Sets options using file path f3dImportOptions = app.importManager.createFusionArchiveImportOptions(filename) # Opens file into current document app.importManager.importToTarget(f3dImportOptions, rootComp)
# This is the problematic if statement, though the code is identical to above with a changed open condition if _filein.selectedItem.name == 'droplet': # Opens joint c # Sets filename for opening (with path) filename = "%s/resources/parts/%s.f3d" %(_filelocation,jointlist[2]) # Sets options using file path f3dImportOptions = app.importManager.createFusionArchiveImportOptions(filename) # Opens file into document app.importManager.importToTarget(f3dImportOptions, rootComp) except: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))