Fusion API Modify and Export Parameters to File

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am trying to write a Python script to modify certain vehicle parameters, and then output a mass and center of gravity for each parameter combination. I'd like these to output to a single txt or csv file. I've attempted to use the Parameter I/O Add-In to help me write this, but I'm not really sure what I'm doing so the process has been quite difficult. I'm hoping I can get an experts help as I imagine this is a fairly trivial task. I have also tried to incorporate some tips from @ekinsb particularly from This Post, though I'm not sure of how to modify from STL export to inputting data to a text file.
The code I have written thus far is below:
halfbody_range=[4,5,6]
radius_range=[0.4,0.5,0.6]
filename = ‘parameters output.csv’
def writeParametersToFile(filePath):
app = adsk.core.Application.get()
design = app.activeProduct
with open(filePath, 'w', newline='') as csvFile:
csvWriter = csv.writer(csvFile, dialect=csv.excel)
for param in design.allParameters:
try:
paramUnit = param.unit
except:
paramUnit = ""
csvWriter.writerow([param.name, paramUnit, param.expression, param.comment])
# get the name of the file without the path
partsOfFilePath = filePath.split("/")
ui = app.userInterface
ui.messageBox('Parameters written to ' + partsOfFilePath[-1])
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
for angle in halfbody_range:
userParams.itemByName(‘angle_halfbody’).expression = angle
for radius in radius_range:
userParams.itemByName(‘radius_range’).expression = radius
# Let the view have a chance to paint just so you can watch the progress
adsk.doEvents()
propertyValue = Assembly.mass
propertyValue = Assembly.centerOfMass
writeParametersToFile
Basically, I want to cycle through each value in the halfbody_range and radius_range, having the CG and mass of the entire 'assembly' (Forgive me, I typically use Inventor) for that combination of user parameters output to the txt or csv file. In this case I should have 9 separate outputs.
I haven't attempted to run this script yet as I'm not sure I even have all of the required components. Any help you can offer me would be greatly appreciated. Thank you in advance!