Hi J.R.
You are right, the C# has a problem.
The VB has a work around if you are able to use VB.NET in this case.
See the following sample of a Grasshopper Sweep1 component done in
VB.NET:
Class Grasshopper_Custom_Script
#Region "members"
Private app As MRhinoApp
Private doc As MRhinoDoc
Public Breps As System.Object
#End Region
Sub RunScript(ByVal Rail As OnCurve, ByVal Shapes As List(Of
OnCurve))
Dim Sweep1_Breps As New List(Of OnBrep)
'Call sweep function
Sweep1(Rail, Shapes, Sweep1_Breps)
'Return Breps
Breps = Sweep1_Breps
End Sub
#Region "Additional methods and Type declarations"
Sub Sweep1( ByVal Rail As IOnCurve, ByVal sCurves As List(Of
OnCurve), ByRef Sweep1_Breps As List(Of OnBrep))
'Define a new class that contains sweep1 arguments
Dim args As New MArgsRhinoSweep1
'Set the 2 rails
Dim Edge As New MRhinoPolyEdge
Edge.Append(Rail.DuplicateCurve())
'Add rails to sweep arguments
args.m_rail_curve = Edge
args.m_bUsePivotPoint = False
Dim curves As New List(Of OnCurve)
'Loop through section curves
For Each crv As IOnCurve In sCurves
If (crv IsNot Nothing) Then
Dim dup_crv As OnCurve = crv.DuplicateCurve()
Dim t As Double = 0
edge.GetClosestPoint(dup_crv.PointAtStart(), t)
curves.Add(dup_crv)
args.m_rail_params.Append(t)
End If
Next
'Set shapes
args.m_shape_curves = curves.ToArray()
'Set the rest of parameters
args.m_bUsePoints(0) = 0
args.m_bUsePoints(1) = 0
args.m_bClosed = False
args.m_style = 0
args.m_planar_up = New On3dVector(OnUtil.On_zaxis)
args.m_simplify = 0 'Simplify method for shape curves
args.m_rebuild_count = -1 'Sample point count for rebuilding
shapes
args.m_refit_tolerance = doc.AbsoluteTolerance()
args.m_sweep_tolerance = doc.AbsoluteTolerance()
args.m_angle_tolerance = doc.AngleToleranceRadians()
args.m_miter_type = 0 '0: don't miter
Dim sBreps() As OnBrep = Nothing
If (RhUtil.RhinoSweep1(args, sBreps)) Then
For Each b As OnBrep In sBreps
Sweep1_Breps.Add(b)
Next
End If
Return
End Sub
#End Region
End Class
On Feb 24, 4:06 am, "J.R." <[email protected]> wrote:
> Hi,
> We just try to make a custom C# sweep1 component which wont work. The
> problem we tracked down lies somewhere in the MRhinoObjRef so the
> rail_curve stays invalid. If anyone has an idea it would be helpful.
> The .net example on the Rhinowebsite deals with selected objects,
> where the ObjectId is passed to MRhinoObjRef, so I just tried that too
> in GH: MRhinoObjRef rail_ref = new MRhinoObjRef(rail.ModelObjectId());
> but something doesnt work:
>
> // generate needed Objects
> MRhinoPolyEdge edge = new MRhinoPolyEdge();
> OnBrep[] srf = new OnBrep[1];
> MArgsRhinoSweep1 args = new MArgsRhinoSweep1();
>
> // convert the shapecurve into an Array (as there is only one
> here)
> OnCurve[] shapes = new OnCurve[1];
> shapes[0] = shape;
>
> // converting the rail curve
> MRhinoObjRef rail_ref = new MRhinoObjRef(rail.ModelObjectId());
> IRhinoObject rail_obj = rail_ref.Object();
> IOnCurve rail_crv = rail_ref.Curve();
>
> // filling the edge with input
> edge.Create(rail_crv, rail_obj);
>
> // filling the args with input
> args.m_shape_curves = shapes;
> args.m_rail_curve = edge;
>
> // do the sweep
> RhUtil.RhinoSweep1(ref args, out srf);
>
> // output the resulting surface
> A = srf;