Hello everyone,
my goal is to make a twisted sweep feature guided by path with known height (ex. 30.0 / 4.5) and later, merge this sweep with a cyllinder with the same height. It's important for get a smooth top surface (one planar BRepFace). All of this I can perform by API but I noticed that for some cases, especially for irrational numbers, I cannot get such surface because of difference in heights - left body:
Two bodies - left with with faultA - height difference
Here's my code used for the test:
import adsk.core, adsk.fusion, traceback
import math
def createPath(sketches: adsk.fusion.Sketches,
plane: adsk.fusion.ConstructionPlane,
coordinates: adsk.core.Point2D,
height: float) -> adsk.fusion.Path:
pathSketch = sketches.add(plane)
pathSketch.name = "Path"
pathSketch.isVisible = False
line = pathSketch.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(coordinates.x, coordinates.y, 0), adsk.core.Point3D.create(coordinates.x, coordinates.y, height))
path = plane.component.features.createPath(line)
return path
def createSweep(profile: adsk.fusion.Profile,
path: adsk.fusion.Path,
guide: adsk.fusion.Path = None,
twistAngle: float = 0) -> adsk.fusion.SweepFeature:
sweeps = profile.parentSketch.parentComponent.features.sweepFeatures
sweepInput = sweeps.createInput(profile, path, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
if guide:
sweepInput.guideRail = guide
sweepInput.profileScaling = adsk.fusion.SweepProfileScalingOptions.SweepProfileNoScalingOption
sweepInput.twistAngle = adsk.core.ValueInput.createByReal(twistAngle)
sweep = sweeps.add(sweepInput)
return sweep
def extrudeProfile(profile: adsk.fusion.Profile,
distance: float,
featureOperation: adsk.fusion.FeatureOperations = adsk.fusion.FeatureOperations.NewBodyFeatureOperation) -> adsk.fusion.ExtrudeFeature:
distanceInput = adsk.core.ValueInput.createByReal(distance)
extrusionResult = profile.parentSketch.parentComponent.features.extrudeFeatures.addSimple(profile, distanceInput, featureOperation)
return extrusionResult
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
# 1. First test - thickness as a periodic irrational number - top faces no coincident
# Prepare profile for twisting
cuboidBaseCenter = adsk.core.Point3D.create(0, 2, 0)
cuboidBaseCorner = adsk.core.Point3D.create(-0.5, 3, 0)
sketches = rootComp.sketches
twistedCuboidSketch = sketches.add(rootComp.xYConstructionPlane)
twistedCuboidSketch.name = "Twisted cuboid sketch 1"
twistedCuboidSketch.isVisible = False
twistedCuboidSketch.sketchCurves.sketchLines.addCenterPointRectangle(cuboidBaseCenter, cuboidBaseCorner)
# Prepare profile for core
coreRadius = 1.3
coreCenter = rootComp.originConstructionPoint.geometry
coreSketch = sketches.add(rootComp.xYConstructionPlane)
coreSketch.name = "Core sketch 1"
coreSketch.isVisible = False
coreSketch.sketchCurves.sketchCircles.addByCenterRadius(coreCenter, coreRadius)
# Create twisted cuboid
thickness = 30.0 / 4.5
path = createPath(sketches, rootComp.xYConstructionPlane, adsk.core.Point2D.create(0, 0), thickness)
createSweep(twistedCuboidSketch.profiles.item(0), path, twistAngle=math.pi / 2)
# Merge it with core
extrudeProfile(coreSketch.profiles.item(0), thickness, adsk.fusion.FeatureOperations.JoinFeatureOperation)
# 2. Second test - thickness as a finite number - top faces coincident
# Prepare profile for twisting
cuboidBaseCenter = adsk.core.Point3D.create(10, 2, 0)
cuboidBaseCorner = adsk.core.Point3D.create(9.5, 3, 0)
sketches = rootComp.sketches
twistedCuboidSketch = sketches.add(rootComp.xYConstructionPlane)
twistedCuboidSketch.name = "Twisted cuboid sketch 2"
twistedCuboidSketch.isVisible = False
twistedCuboidSketch.sketchCurves.sketchLines.addCenterPointRectangle(cuboidBaseCenter, cuboidBaseCorner)
# Prepare profile for core
coreRadius = 1.3
coreCenter = adsk.core.Point3D.create(10, 0, 0)
coreSketch = sketches.add(rootComp.xYConstructionPlane)
coreSketch.name = "Core sketch 2"
coreSketch.isVisible = False
coreSketch.sketchCurves.sketchCircles.addByCenterRadius(coreCenter, coreRadius)
# Create twisted cuboid
thickness = 30.0 / 1.5
path = createPath(sketches, rootComp.xYConstructionPlane, adsk.core.Point2D.create(10, 0), thickness)
createSweep(twistedCuboidSketch.profiles.item(0), path, twistAngle=math.pi / 2)
# Merge it with core
extrudeProfile(coreSketch.profiles.item(0), thickness, adsk.fusion.FeatureOperations.JoinFeatureOperation)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I also tried:
- extrude circle to top twisted body (as isMinSolution = False) but I got error because circle profile is outside of the top face,
- make a plane on top face of twisted body (offset zero) and extrude the circle to this plane but it caused error which closed the Fusion,
- get a point from the top face (face.pointOnFace) and extrude the circle to facePoint.z but it doesn't help - result the same.
Of course, if hight is a fraction I can prepare higher (height as int number) body with apropriate modified angle and later cut this body for desired size, but is there a better solution?
Thank you