Message 1 of 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm writing a script that creates lots of cylinders, between points in space. As far as I can tell, Lofts are the way to go for this. I have code that works, but it gets incredibly slow - I can make 10 cylinders no problem, but when I try to make 30, it hangs for several minutes. Is this just poor API performance? Is there a more efficient way to make cylinders?
def create_bond(rootComp,bond,r):
start = bond.start.get_point()
end = bond.end.get_point() # Create sketch
#p = adsk.core.Plane.create(bond.start.get_point(), bond.start.get_point().vectorTo(bond.end.get_point()))
planes = rootComp.constructionPlanes
planeInput = planes.createInput()
line_sketch = rootComp.sketches.add(rootComp.xYConstructionPlane)
# Draw a line to use as the axis of revolution.
lines = line_sketch.sketchCurves.sketchLines
line = lines.addByTwoPoints(start, end)
# Create a path and let it find connected curves automatically
path = rootComp.features.createPath(line)
planeInput = rootComp.constructionPlanes.createInput() # you could also specify the occurrence in the parameter list
planeInput.setByDistanceOnPath(path, adsk.core.ValueInput.createByReal(0))
plane1 = rootComp.constructionPlanes.add(planeInput)
sketch1 = rootComp.sketches.add(plane1)
circles = sketch1.sketchCurves.sketchCircles
circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(0, 0, 0), r)
# Create the End Loft Sketch Profile
planeInput.setByDistanceOnPath(path, adsk.core.ValueInput.createByReal(1))
plane2 = rootComp.constructionPlanes.add(planeInput)
sketch2 = rootComp.sketches.add(plane2)
circles = sketch2.sketchCurves.sketchCircles
skPosition = sketch2.modelToSketchSpace(end)
circle2 = circles.addByCenterRadius(skPosition, r)
profile0 = sketch1.profiles.item(0)
profile1 = sketch2.profiles.item(0)
# Create loft feature input
loftFeats = rootComp.features.loftFeatures
loftInput = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
loftSectionsObj = loftInput.loftSections
loftSectionsObj.add(profile0)
loftSectionsObj.add(profile1)
loftInput.isSolid = False
try: # Create loft feature
loftFeats.add(loftInput)
except:
print("couldn't loft {} to {}".format(bond.start, bond.end))
#print(traceback.format_exc())
Solved! Go to Solution.
