我在 fusion360 中使用了一个名为 importsplinecsv 的脚本,我想知道是否可以修改脚本,使其每 10 行导入一行?因为正在导入的行数非常大且臃肿。
如果我能得到一些帮助,那就太棒了。
这是文字
作者-Autodesk Inc.
说明-从 csv 文件导入样条
导入 adsk.core、adsk.fusion、回溯导入 io
def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface # 获取活动设计中的所有组件。product = app.activeProduct design = adsk.fusion.Design.cast(product) 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
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:
root = design.rootComponent
sketch = root.sketches.add(root.xYConstructionPlane)
sketch.sketchCurves.sketchFittedSplines.add(points)
else:
ui.messageBox('No valid points', title)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))