I needed a real spiral, so I used the trick of making a set of points in a spreadsheet and importing the .csv file to make a spline using the provided script. I used the Python one, because the Javascript one alway fails with a misspelled error something like "0 ponit length".
The sample scripts aren't doing anything smart about units and are creating the sketch geometry based on Fusion's internal distance units, which are centimeters. So the units in the csv file are always assumed to be in centimeters. The script could be enhanced to see what the current document units are and use that or possibly add the ability to define what the units are in the csv file, but for now they are centimeters. It sounds like you want them to be millimeters so if you just multiply all of the values in the csv file by 10 you should be good.
I also verified the problem you reported with the JavaScript version of the script and we'll get that fixed.
Aha!
It never even occurred to me that the software didn't know what units I was using!
Thanks for clearing that up. And I'd never have guessed centimeters would be the default! That's kind of an anomaly for scientific work, which is supposed to prefer units that differ from the base unit (meters) by any power of 1000. Surprising.
My spiral comes out 10x too big, so I'll just change the spreadsheet to divide the results by 10 and I'm set.
Hi,
As of today, the problem still exists. I used ImportSplineCSV add-in and it draws every coordinate point in my csv file (attached to this message) in a 10x multiplied fashion.
Maybe you missed the explanation, but there wasn't a problem to be fixed. The simple sample script always assumes that the CSV data is defined in centimeters. I made a small change to the script so that it now assumes that the CSV data is defined in whatever the current document units are. Here's the changed version of the script.
import adsk.core, adsk.fusion, traceback def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface # Get the active design. product = app.activeProduct design = adsk.fusion.Design.cast(product) title = 'Import Spline csv' if not design: ui.messageBox('No active Fusion design', title) return # Determine the scale factor to convert from the document units to centimeters. # This assumes that the CSV data is defined in the current document units. scaleFact = design.unitsManager.convert(1, design.unitsManager.defaultLengthUnits, 'cm') # Prompt the user for the CSV file to import. 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 # Read the point data from the file. f = open(filename, 'r') points = adsk.core.ObjectCollection.create() line = f.readline() data = [] while line: line = line.strip() pntStrArr = line.split(',') for pntStr in pntStrArr: try: data.append(float(pntStr) * scaleFact) except: pass if len(data) >= 3 : point = adsk.core.Point3D.create(data[0], data[1], data[2]) points.add(point) line = f.readline() data.clear() f.close() root = design.rootComponent; sketch = root.sketches.add(root.xYConstructionPlane); sketch.sketchCurves.sketchFittedSplines.add(points); except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I do not know if it is appropriate to highjack this thread or if I should have made a new thread.
My question is a very small variation on the original question.
I am new to this API and new to Python, however I did quit some LISP work in Autocad a few decades ago.
My question 1: Why is this parabola -20 to 20 in X and 0 to 40 in Z? Would have expected Z to be 0 to 400 I just found out, I am scaling in the wrong place, compute everything in millimeters and scaleonly when submitting the points.
pnts.add(adsk.core.Point3D.create(x * scaleFact, -z * scaleFact,0))
My question 2: Why -z?
import adsk.core, adsk.fusion, traceback import math def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface des = app.activeProduct root = des.rootComponent sketch = root.sketches.add(root.xZConstructionPlane) # Default unit is cm, convert to current unit scaleFact = des.unitsManager.convert(1, des.unitsManager.defaultLengthUnits, 'cm') pnts = adsk.core.ObjectCollection.create() startX = -20 * scaleFact stopX = 20 * scaleFact pts=20 for pt in range(0, pts+1): x = (stopX -startX) * pt / pts + startX # Actual function here z = x**2 pnts.add(adsk.core.Point3D.create(x,-z,0)) sketch.sketchCurves.sketchFittedSplines.add(pnts) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))