I have created a code that adds points to a sketch, dimensions them and then I would like a spline to go through it.
For the spline not to be altered by accident in the future, I would like to constrain everything that is possible, starting with the points. I have accomplished that, and if I run my code (at the end of this question) without the line:
spline = sketch.sketchCurves.sketchFittedSplines.add(points)
everything works well and I get a sketch that looks like this:
Unfortunately when I try to add these points to a spline, I lose the constraints. Here if I try to move it to the side, I get double of all the points I have...
Am I duplicating some points by accident, or is there some logical flaw in my process?
here is my code:
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
design = app.activeProduct
# Get the root component of the active design.
rootComp = design.rootComponent
# Create a new sketch on the xy plane.
sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
# Create an object collection for the points.
points = adsk.core.ObjectCollection.create()
dims = adsk.fusion.SketchDimensions.cast(sketch.sketchDimensions)
a = 4
xStart = -2
xEnd = 2
increment = 1
i = 0
for x in range(xStart, xEnd, increment):
y = a * x ** 2
if x > 0:
textY = -x
else:
textY = x
origin = sketch.originPoint
point = sketch.sketchPoints.add(adsk.core.Point3D.create(x, y, 0))
points.add(point)
textPointX = adsk.core.Point3D.create(x, textY, 0)
textPointY = adsk.core.Point3D.create(x*1.5, y, 0)
dim = sketch.sketchDimensions
distanceDimension = dim.addDistanceDimension(origin, points[i], adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, textPointX)
distanceDimension = dim.addDistanceDimension(origin, points[i], adsk.fusion.DimensionOrientations.VerticalDimensionOrientation, textPointY)
i = i +1
spline = sketch.sketchCurves.sketchFittedSplines.add(points)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Looking forward to your replies and ideas 🙂
Solved! Go to Solution.
Solved by Jorge_Jaramillo. Go to Solution.
Hi,
I'd expect the sketchFittedSplines_var.add() method to use the sketchPoints supplied (as it receive both Point3D and SketchPoint objects), but it certainly duplicates them.
One solution could be just make the points collection of Point3Ds instead of SketchPoints, and then add the constraints after the spline creation, like in the following code snippet:
spline = sketch.sketchCurves.sketchFittedSplines.add(points)
for p in spline.fitPoints:
textPointX = adsk.core.Point3D.create(p.geometry.x, -p.geometry.x, 0)
textPointY = adsk.core.Point3D.create(p.geometry.x*1.5, p.geometry.y, 0)
dims.addDistanceDimension(origin, p, adsk.fusion.DimensionOrientations.HorizontalDimensionOrientation, textPointX)
dims.addDistanceDimension(origin, p, adsk.fusion.DimensionOrientations.VerticalDimensionOrientation, textPointY)
I hope this can help.
Regards,
Jorge Jaramillo
Can't find what you're looking for? Ask the community or share your knowledge.