making a 3D spline using points of existing sketch splines

making a 3D spline using points of existing sketch splines

franck.gressier
Enthusiast Enthusiast
772 Views
2 Replies
Message 1 of 3

making a 3D spline using points of existing sketch splines

franck.gressier
Enthusiast
Enthusiast

I have been searching to do this in various ways but nothing worked out.

What I want to do:

I have a bunch of sketch splines that I use to create a loft.

As guide rail I would like to make a spline going by point #5 of each of the sketch splines...

 

xYplane = design.rootComponent.xYConstructionPlane
sketch3dSplines = sketches.add(xYplane)
sketch3dSplines.name ="sketch3dSplines"
SplineRailPoints = adsk.core.ObjectCollection.create()
for loc in sections: # I have a dictionary indexing my sketch Splines
courbe = sketchsProfils[loc].sketchCurves.sketchFittedSplines.item(0)
sketch3dSplines.include(courbe.fitPoints(5))
SplineExPoints.add(sketch3dSplines.points(-1))

SplineEx = sketch3dSplines.sketchCurves.sketchFittedSplines.add(SplineExPoints)

This says that SkechPointList object is not callable... when I try to include the spline fitPoint  5 .

Adding without including isn't better.

 

I have also tryed to make a list of the points while creating the splines but then I get a curve all messed up in the xY plane and not at all what I expect...

 

Do I need to add some .geometry in this ?

 

 

 

0 Likes
Accepted solutions (1)
773 Views
2 Replies
Replies (2)
Message 2 of 3

franck.gressier
Enthusiast
Enthusiast
Accepted solution

I have kept searching.

I can access the 3d coordinates of the points like this:

 

import adsk.core, adsk.fusion, traceback


def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface

spline = adsk.fusion.SketchFittedSpline.cast(ui.activeSelections.item(0).entity)
if spline:
result = ''
for sketchpoint in spline.fitPoints:
point = sketchpoint.worldGeometry
result += '{}, {}, {}\n'.format(point.x, point.y, point.z)
ui.messageBox('Spline points: {}\n {}'.format(spline.fitPoints.count, result))

except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

But that is not really what I want. I would like to reuse the existing points.

I guess I could create new points and merge but it seems heavy. 

0 Likes
Message 3 of 3

franck.gressier
Enthusiast
Enthusiast

Sometimes you look for complicate things....

Not callable is because I used "()" which are for functions...

.item(5) is better.

[5] could do I guess

But I get another error:

2019-11-24_19h56_39.png

However, i was able to avercome this with world.geometry...

This works ! 🐵

import adsk.core, adsk.fusion, traceback


def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
comp = design.activeComponent
#ui.messageBox(comp.name)
sketches = comp.sketches
SplineExPoints = adsk.core.ObjectCollection.create()

for sk in sketches:
spline = sk.sketchCurves.sketchFittedSplines.item(0)
SplineExPoints.add(spline.fitPoints.item(5).worldGeometry)

xYplane = design.rootComponent.xYConstructionPlane
sketch3dSplines = sketches.add(xYplane)
SplineEx = sketch3dSplines.sketchCurves.sketchFittedSplines.add(SplineExPoints)


except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
 

 

0 Likes