Hello,
The following code yields a sweep1 style sweep no problem:
sweep = Rhino.Geometry.Brep.CreateFromSweep(path_curve, profile_curve, True, scriptcontext.doc.ModelAbsoluteTolerance)
However, when I try to use the method with the additional args to create a midered, trimmed, and solid sweep1 it consistently returns None but my args look correct from what I can tell based on the API docs here:
https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.brep/createfromsweep
Code:
def SweepFromCurve(nurbs_curve=None, width=default_width, height=default_height):
"""Given an input nurbs_curve/polyline, width number, and height number,
sweep a rectangle(curve_start_origin/plane, width, height) along the curve,
get the sweep result as a 3d brep"""
try:
if nurbs_curve is None:
print("nurbs_curve is None, returning")
return None
path_curve = nurbs_curve.ToNurbsCurve()
# Create a rectangle profile for sweeping
# First, get the start point and tangent vector
t = 0.0 # Start of curve
start_point = path_curve.PointAt(t)
tangent = path_curve.TangentAt(t)
# Create a plane perpendicular to the curve at the start point
success, perp_frame = path_curve.PerpendicularFrameAt(t)
if not success:
# If we can't get a perpendicular frame, create one manually
up_vector = Rhino.Geometry.Vector3d.ZAxis
# Make sure the up vector isn't parallel to the tangent
if abs(Rhino.Geometry.Vector3d.Multiply(up_vector, tangent)) > 0.99:
up_vector = Rhino.Geometry.Vector3d.YAxis
x_axis = tangent
y_axis = Rhino.Geometry.Vector3d.CrossProduct(up_vector, x_axis)
y_axis.Unitize()
z_axis = Rhino.Geometry.Vector3d.CrossProduct(x_axis, y_axis)
z_axis.Unitize()
perp_frame = Rhino.Geometry.Plane(start_point, y_axis, z_axis)
# Create the rectangular profile
# Center the rectangle on the curve
center = perp_frame.Origin
# Create rectangle corners
half_width = width / 2.0
rectangle = Rhino.Geometry.Rectangle3d(
perp_frame,
Rhino.Geometry.Interval(-half_width, half_width),
Rhino.Geometry.Interval(0, height)
)
# Convert the rectangle to a curve
profile_curve = rectangle.ToNurbsCurve()
# Perform the sweep
# Create a rail sweep using the profile and the curve
# sweep = Rhino.Geometry.Brep.CreateFromSweep(path_curve, profile_curve, True, scriptcontext.doc.ModelAbsoluteTolerance)
# Perform the sweep with additional arguments for mitering and solid geometry
sweep = Rhino.Geometry.Brep.CreateFromSweep(
rail=path_curve,
shapes=[profile_curve],
startPoint=path_curve.PointAtStart,
endPoint=path_curve.PointAtEnd,
frameType=Rhino.Geometry.SweepFrame.Roadlike, # Use roadlike framing for controlled orientation
roadlikeNormal=Rhino.Geometry.Vector3d.ZAxis, # Use Z axis as the normal reference
closed=True,#path_curve.IsClosed, # Handle closed paths correctly
blendType=Rhino.Geometry.SweepBlend.Local, # Linear blending between cross-sections
miterType=Rhino.Geometry.SweepMiter.Trimmed, # Use sharp mitering at corners
tolerance=scriptcontext.doc.ModelAbsoluteTolerance,
rebuildType=Rhino.Geometry.SweepRebuild.NONE, # No rebuild needed for a simple sweep
rebuildPointCount=10, # Only used if rebuildType isn't None
refitTolerance=scriptcontext.doc.ModelAbsoluteTolerance
)
"""CreateFromSweep(
Curve rail,
IEnumerable<Curve> shapes,
Point3d startPoint,
Point3d endPoint,
SweepFrame frameType,
Vector3d roadlikeNormal,
bool closed,
SweepBlend blendType,
SweepMiter miterType,
double tolerance,
SweepRebuild rebuildType,
int rebuildPointCount,
double refitTolerance
)"""
if sweep:
return sweep
print("sweep failed, returning None")
return None
except Exception as ex:
Rhino.RhinoApp.WriteLine(f"SweepFromCurve Exception: {ex}")
return None
I would appreciate any tips on what I am doing wrong here (version 8.19),
Thank you so much!