Message 1 of 3

Not applicable
01-09-2021
10:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everybody,
as the title says I try to import around 200 csv Files in to fusion and then Automatically loft them. As I have not found any script that does a batch import and loft I tried to write my own with limited succes. I managed to import all csv files with modding the importCSV script but I struggle to get them in to a Loft. Here is My Code so far:
#Author-Autodesk Inc.
#Description-Import spline from csv file
import adsk.core, adsk.fusion, traceback
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
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:
design.rootComponent.sketches.add(design.rootComponent.xYConstructionPlane).sketchCurves.sketchFittedSplines.add(points)
else:
ui.messageBox('No valid points', title)
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()))
I get the Error message Bad Index parameter at line 63. Does annybody know why that is or knows a script that does what I try to implement?
Have a nice Day and Thanks for any help!
Solved! Go to Solution.