Batch import multiple splines of csv files. And adding a loft between those splines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It's my first time using the Fusion API. I am using Windows 10 and Python. I want to import multiple splines into the Fusion (which currently works nicely with the "ImportSplineCSV" sample script), but I find it tedious to do for every csv.file. I was wondering if there was a way to select multiple csv files and create a spline for each seperate one.
In this thread i found a solution, i think, but couldnt get the batch import to work.
#Author-Autodesk Inc.
#Description-Import spline from csv file
import adsk.core, adsk.fusion, tracebac
import io
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Get all components in the active design.
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
title = 'Import Spline csv'
if not design:
ui.messageBox('No active Fusion design', title)
return
dlg = ui.createFileDialog()
dlg.title = 'Open CSV File'
dlg.filter = 'Comma Separated Values (*.csv);;All Files (*.*)'
if dlg.showOpen() != adsk.core.DialogResults.DialogOK :
return
filename = dlg.filename
sketches = []
for i in range(1,202#Loop for csv import
filename = 'C:/*privacy*/layer{}.csv'.format(i)
with io.open(filename, 'r', encoding='utf-8-sig') as f:
points = adsk.core.ObjectCollection.create()
line = f.readline()
data = []
while line:
pntStrArr = line.split(',')
for pntStr in pntStrArr:
try:
data.append(float(pntStr))
except:
break
if len(data) >= 3 :
point = adsk.core.Point3D.create(data[0], data[1], data[2])
points.add(point)
line = f.readline()
data.clear()
if points.count:
sketch = design.rootComponent.sketches.add(design.rootComponent.xYConstructionPlane)
sketch.sketchCurves.sketchFittedSplines.add(points)
sketches.append(sketch)
else:
ui.messageBox('No valid points', title)
loftFeats = rootComp.features.loftFeatures
loftInput = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
loftSectionsObj = loftInput.loftSections
for sketch in skethes:
profile = sketch.profiles.item(0)
loftSectionsObj.add(profile)
loftFeats = rootComp.features.loftFeatures
loftInput = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
loftSectionsObj = loftInput.loftSections
for j in range(0,100#Loop for selecting the scetch profiles for the loft
profile = design.rootComponent.sketches.add(rootComp.xYConstructionPlane).profiles.item(j)
loftSectionsObj.add(profile)
loftInput.isSolid = False
# Create loft feature
loftFeats.add(loftInput)
#design.rootComponent.sketches.add(rootComp.xZConstructionPlane).profiles.item(0)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
After importing the splines, I want to create a loft between the splineprofiles, i wonder if that can be done in the same script. I am working on a propeller and im generating the sectioncurves using openprop v3.3.4. in matlab:
After using the import spline script 20 times i get one blade of the propeller:
Since its always the same process for each propeller, i wonder if its possible to automate the whole process to create a propeller. With the solid loft function iIwant to create a blade. Than i import the hub component and combine the components together. After using a fillet i get a nice transistion between the blades and the hub. With the c-pattern i want to copy the blade with the fillet to the other side.
Thank you in advance and have a nice day,
Tomas