Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I have been doing some testing on my end with regards to creating files and deriving parts to them, which seems to be working well. I just noticed however that the tool tips for both the Documents.add and Document.saveAs methods have this in their descriptions:
"Saving a document is not supported within any of the Command related events. When a command is running, a transaction is open, and saving a document cannot be transacted and, as a result, cannot be contained within a command transaction."
Is this still true in the API and if it is is there any workaround that anyone has found? Code that was working on my end is below. Thanks!
def command_execute(args: adsk.core.CommandEventArgs):
# General logging for debug.
futil.log(f'{CMD_NAME} Command Execute Event')
des = adsk.fusion.Design.cast(app.activeProduct)
...
target_body: adsk.fusion.BRepBody = selection.body # Store body
active_doc = des.parentDocument
folder = active_doc.dataFile.parentFolder
new_doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType, True)
new_design: adsk.fusion.Design = new_doc.products.itemByProductType('DesignProductType')
new_comp = new_design.rootComponent
der_feats = new_comp.features.deriveFeatures
der_input = der_feats.createInput(des)
der_input.sourceEntities = [target_body]
der_feat = der_feats.add(der_input)
new_doc.saveAs('new_file', folder, '', '')
Solved! Go to Solution.