Hello,
Thank you for sharing dataset. There were two issues as below:
1. Duplicated parameters were found when dump to CSV file.
It was because there was xref component in "book shelf" model. We allow parameters can be duplicated in two different designs. A quick fix would be not to export those parameters from external design to CSV file. The updated script is as below. Please let me know if you want them to be exported. Then I could modify script to support that. We have to make parameter name be unique in CSV file.
#Author-Brian Ekins
#Description-Dumps out parameter info to a specified csv file.
import adsk.core, adsk.fusion, traceback
def insertParameter(param, allParams):
allParams.append(param)
dependentParams = param.dependentParameters
for dependentParam in dependentParams:
if dependentParam in allParams:
allParams.remove(dependentParam)
insertParameter(dependentParam, allParams)
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
des = app.activeProduct
if des.designType == adsk.fusion.DesignTypes.DirectDesignType:
ui.messageBox('No parameters exists in the design.')
return
# Get the name of the file to write to.
fileDialog = ui.createFileDialog()
fileDialog.isMultiSelectEnabled = False
fileDialog.title = "Specify result filename"
fileDialog.filter = 'CSV files (*.csv)'
fileDialog.filterIndex = 0
dialogResult = fileDialog.showSave()
if dialogResult == adsk.core.DialogResults.DialogOK:
filename = fileDialog.filename
else:
return
# Get sorted parameter list according to dependencies
allParams = []
modelParamCompNames = {}
for userParam in des.userParameters:
insertParameter(userParam, allParams)
for comp in des.allComponents:
if comp.parentDesign == des:
for modelParam in comp.modelParameters:
insertParameter(modelParam, allParams)
modelParamCompNames[modelParam.name] = comp.name
result = 'Name,Expression,Units,Value (database units),Comment,Type,Component\n'
# Get the data for all parameters.
for param in allParams:
compName = modelParamCompNames.get(param.name)
if compName != None:
result += (param.name + ',' + param.expression + ',' + param.unit +
',' + str(param.value) + ',' + param.comment + ',Model,' + compName + '\n')
else:
result += (param.name + ',' + param.expression + ',' + param.unit + ',' +
str(param.value) + ',' + param.comment + ',User\n')
output = open(filename, 'w')
output.writelines(result)
output.close()
ui.messageBox('File written to "' + filename + '"')
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
2. No parameters exist in direct modeling design.
The model "secret fingertrip" was the case. A friendly message should be prompted. I modified the script to do that.
Thanks,
Marshal
Marshal Tu
Fusion Developer
>