- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have been learning about and working in the Fusion 360 API environment for quite some time now and am starting to get a good grasp of understanding the documentation and object model.
I am trying to make an API that will model stairs infusion 360 using nothing but the script.
One problem I keep running into is units, particularly when plotting points for a sketch, is creating points in inches. I need everything to be in inches to work properly. (This is the for USA construction industry, that's how it is.)
I've read and understand most of the "Understanding Units in Fusion 360" documentation but still can't figure out how to use inches when entering a float value or integer value. I know that I can use createByString to make a Value Input in inches (for something like an extrusion), but I can't enter those when making points. Anything else (like making points) goes by the database units (cm) which I don't want.
Of course, I could divide all of the parameters by 2.54, but that seems like a very indirect and inefficient way of solving the problem.
So is there anyway to change the fusion 360 API database units to inches so I could for example create a point using x,y,z coordinates in inches?
#Note: This code was copy and pasted from "SD468474
#Getting Started with the Fusion 360 API
#Patrick Rainsberry
#Autodesk"
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
rootComp = design.rootComponent
sketches = rootComp.sketches
xyPlane = rootComp.xYConstructionPlane
sketch = sketches.add(xyPlane)
lines = sketch.sketchCurves.sketchLines
#Make Points for Sketch
point0 = adsk.core.Point3D.create(0, 0, 0)#These three values are the ones
that I would like to create using inches
point1 = adsk.core.Point3D.create(0, 1, 0)
point2 = adsk.core.Point3D.create(1, 1, 0)
point3 = adsk.core.Point3D.create(1, 0, 0)
#This way the lines they create would also be in inches
lines.addByTwoPoints(point0, point1)
lines.addByTwoPoints(point1, point2)
lines.addByTwoPoints(point2, point3)
lines.addByTwoPoints(point3, point0)
profile = sketch.profiles.item(0)
extrudes = rootComp.features.extrudeFeatures
ext_input = extrudes.createInput(profile,
adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
#I understand how to change this distance ValueInput to inches by using #createByString
#This would be for CM# distance = adsk.core.ValueInput.createByReal(1)
distance = adsk.core.ValueInput.createByString("2 in")#This would make the
extrusion 2 inches
ext_input.setDistanceExtent(False, distance)
ext_input.isSolid = True
extrudes.add(ext_input)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The code that I am working on is getting a bit long and so I've attached a sample code so it will be easier to answer and make more sense for future readers!
Solved! Go to Solution.