Is it possible to adjust this code to take two input curves (not one joined curve, and output just the FILLET curves (dont need the chamfer at all)
using System;
using System.Collections;
using System.Collections.Generic;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
///
/// This class will be instantiated on demand by the Script component.
///
public class Script_Instance : GH_ScriptInstance
{
#region Utility functions
///
/// String to print.
private void Print(string text) { /* Implementation hidden. / }
///
/// String format.
/// Formatting parameters.
private void Print(string format, params object[] args) { / Implementation hidden. / }
///
/// Object instance to parse.
private void Reflect(object obj) { / Implementation hidden. / }
///
/// Object instance to parse.
private void Reflect(object obj, string method_name) { / Implementation hidden. */ }
#endregion
#region Members
///
private readonly RhinoDoc RhinoDocument;
///
private readonly GH_Document GrasshopperDocument;
///
private readonly IGH_Component Component;
///
/// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
/// Any subsequent call within the same solution will increment the Iteration count.
///
private readonly int Iteration;
#endregion
///
/// This procedure contains the user code. Input parameters are provided as regular arguments,
/// Output parameters as ref arguments. You don’t have to assign output parameters,
/// they will have a default value.
///
private void RunScript(Curve C, double R, ref object A, ref object FilletCurves, ref object ChamferCurves)
{
// ......................................................
// shorter names for tolerances and some input descriptions
// ......................................................
var model_tolerance = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
var angle_tolerance = RhinoDoc.ActiveDoc.ModelAngleToleranceRadians;
Component.Message = "RIL 0.1";
Component.Name = "Chamfer Curves";
Component.NickName = "ChamfCrv";
Component.Params.Input[0].Description = "Joined curves";
Component.Params.Input[1].Description = "\"Radius\" for chamfer (defines the chamfer between from the ends of the input curve's).";
// ......................................................
// INPUTS
// ......................................................
var curve = C.ToNurbsCurve();
var radius = R; // used to get the end points for a chamfer as well
// ......................................................
// Fillet and "explode" all joined curve segments
// ......................................................
var filleted_curve = Curve.CreateFilletCornersCurve(curve, radius, model_tolerance, angle_tolerance);
var filleted_segments = filleted_curve.DuplicateSegments();
// ......................................................
// ensure that we have at least 2 input curves
// ......................................................
if (filleted_segments.Length < 2)
{
ChamferCurves = filleted_segments;
return;
}
// ......................................................
// a new list to store fillets being replaced by chamfers
// ......................................................
var chamfer_curve = new List<Curve>();
// ......................................................
// a trick to indentify and adjust the for-loop for even
// or odd number of curve segments
// ......................................................
var index_offset = 0;
var is_odd = IsOdd(filleted_segments.Length);
if (is_odd)
{
index_offset = -1;
}
// ------------------------------------------------------
// Loop which replaces fillets with chamfers instead
// ------------------------------------------------------
for (var i = 0; i < filleted_segments.Length - 1; i += 2)
{
// add original curves (non-fillet parts)
chamfer_curve.Add(filleted_segments[i + 1 - index_offset]);
// replace fillet curves with straight chamfers
var chamfer = new Line(filleted_segments[i - index_offset].PointAtStart, filleted_segments[i - index_offset].PointAtEnd);
chamfer_curve.Add(chamfer.ToNurbsCurve());
// when odd number of input curves we need to explicitly
// add the first curve segment
if (is_odd && i == 0)
{
chamfer_curve.Add(filleted_segments[0]);
}
}
// ......................................................
// OUTPUT
// ......................................................
FilletCurves = filleted_segments;
ChamferCurves = chamfer_curve;
}
//
public static bool IsOdd(int value)
{
return value % 2 != 0;
}
// </Custom additional code>
}