Skip to content

Commit

Permalink
Adds C# samples for RibbonOffset and Silhouette draft curve (mold mak…
Browse files Browse the repository at this point in the history
…ing tools).

Fixes RH-58256 Draft Curve
Fixes RH-58255 RibbonOffset
  • Loading branch information
travisserio committed May 4, 2020
1 parent 443b70e commit 64564b6
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 4 deletions.
99 changes: 99 additions & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCSRibbonOffsetCurve.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;

namespace SampleCsCommands
{
public class SampleCSRibbonOffsetCurve : Command
{
static SampleCSRibbonOffsetCurve _instance;
public SampleCSRibbonOffsetCurve()
{
_instance = this;
}

///<summary>The only instance of the SampleCSRibbonOffsetCurve command.</summary>
public static SampleCSRibbonOffsetCurve Instance
{
get { return _instance; }
}

public override string EnglishName
{
get { return "SampleCSRibbonOffsetCurve"; }
}

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
//Get a closed curve to offset
var go = new GetObject
{
GeometryFilter = ObjectType.Curve,
GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve
};
go.SetCommandPrompt("Select curve to offset");
go.Get();

//The user did not select a curve
if (go.Result() != GetResult.Object)
return Result.Cancel;

//Get the curve from the GetObject
var crv = go.Object(0).Curve();
if (crv == null)
return Result.Cancel;

//Get the side of the curve to offset towards.
var gp = new GetPoint();
gp.SetCommandPrompt("Select curve side to offset");
gp.Get();

//The user did not select a point
if (gp.Result() != GetResult.Point)
return Result.Cancel;
//The selected Point
var pt = gp.Point();

//Try to get the plane from the curve
crv.TryGetPlane(out Plane ribbon_plane);
if (!ribbon_plane.IsValid)
ribbon_plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();

//Set the ribbon plane vector
var plane_vector = ribbon_plane.Normal;

//Create the ribbon offset, its cross sections, and its ruled surfaces
var ribbon_curve_output = crv.RibbonOffset(1, .1, pt, plane_vector, doc.ModelAbsoluteTolerance,out Curve[] cross_sections, out Surface[] ruled_surfaces);

//Add the ribbon curve to the document
if (ribbon_curve_output != null)
{
doc.Objects.AddCurve(ribbon_curve_output);
}

//Add any cross section curves to the document
if (cross_sections != null)
{
foreach (var curve in cross_sections)
{
doc.Objects.AddCurve(curve);
}
}

//Add any ruled surfaces to the document
if (ruled_surfaces != null)
{
foreach (var surface in ruled_surfaces)
{
doc.Objects.AddSurface(surface);
}
}

doc.Views.Redraw();
return Result.Success;
}
}
}
90 changes: 90 additions & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCSSilhouetteDraftCurve.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Drawing;
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;

namespace SampleCsCommands
{
public class SampleCSSilhouetteDraftCurve : Command
{
static SampleCSSilhouetteDraftCurve _instance;
public SampleCSSilhouetteDraftCurve()
{
_instance = this;
}

///<summary>The only instance of the SampleCSShilhouetteDraftCurve command.</summary>
public static SampleCSSilhouetteDraftCurve Instance
{
get { return _instance; }
}

public override string EnglishName
{
get { return "SampleCSSilhouetteDraftCurve"; }
}

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{

//Select a brep or mesh to extract some curves from
var go = new GetObject() {GeometryFilter = ObjectType.Brep | ObjectType.Mesh};
go.SetCommandPrompt("Select object for draft curve extraction");
go.Get();
if (go.Result() != GetResult.Object)
return Result.Cancel;

//The selected geometry base
var geometry = go.Object(0).Geometry();


//Min & Max angle must be specified in Radians
double min_angle = RhinoMath.ToRadians(-5.00);
double max_angle = RhinoMath.ToRadians(5.00);

//Set the vector direction of the draft computation
Vector3d direction = Vector3d.ZAxis * -1;

//Set the tolerances
double tolerance = doc.ModelAbsoluteTolerance;
double angle_tolerance = doc.ModelAngleToleranceRadians;

//Compute the minimum draft angle curves
var min_draft_silhouettes = Silhouette.ComputeDraftCurve(geometry, min_angle, direction, tolerance,angle_tolerance);

//Compute the maximum draft angle curves
var max_draft_silhouettes = Silhouette.ComputeDraftCurve(geometry, max_angle, direction, tolerance, angle_tolerance);


//Add all of the minimum draft angle silhouette curves to the doc
if (min_draft_silhouettes != null)
{
var oa = new ObjectAttributes(){ObjectColor = Color.Red,ColorSource = ObjectColorSource.ColorFromObject};
foreach (var silhouette in min_draft_silhouettes)
{
var crv = silhouette.Curve;
doc.Objects.AddCurve(crv,oa);
}
}


//Add all of the maximum draft angle silhouette curves to the doc
if (max_draft_silhouettes != null)
{
var oa = new ObjectAttributes(){ObjectColor = Color.Blue, ColorSource = ObjectColorSource.ColorFromObject };
foreach (var silhouette in max_draft_silhouettes)
{
var crv = silhouette.Curve;
doc.Objects.AddCurve(crv,oa);
}
}

doc.Views.Redraw();
return Result.Success;
}
}
}
10 changes: 6 additions & 4 deletions rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Rhino.UI">
<HintPath>..\..\..\..\..\..\..\Program Files\Rhino 7 WIP\System\Rhino.UI.dll</HintPath>
<HintPath>C:\Program Files\Rhino 7 WIP\System\Rhino.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RhinoCommon">
<HintPath>..\..\..\..\..\..\..\Program Files\Rhino 7 WIP\System\RhinoCommon.dll</HintPath>
<HintPath>C:\Program Files\Rhino 7 WIP\System\RhinoCommon.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RhinoWindows">
<HintPath>..\..\..\..\..\..\..\Program Files\Rhino 7 WIP\System\RhinoWindows.dll</HintPath>
<HintPath>C:\Program Files\Rhino 7 WIP\System\RhinoWindows.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -52,7 +52,7 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="Xfinium.Pdf.Win">
<HintPath>..\..\..\..\..\..\..\Program Files\Rhino 7 WIP\Plug-ins\Xfinium.Pdf.Win.dll</HintPath>
<HintPath>C:\Program Files\Rhino 7 WIP\Plug-ins\Xfinium.Pdf.Win.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down Expand Up @@ -184,6 +184,7 @@
<Compile Include="SampleCsRenderBackground.cs" />
<Compile Include="SampleCsRestoreLayerState.cs" />
<Compile Include="SampleCsRestoreNamedView.cs" />
<Compile Include="SampleCSRibbonOffsetCurve.cs" />
<Compile Include="SampleCsRotate.cs" />
<Compile Include="SampleCsRTree.cs" />
<Compile Include="SampleCsSave3DS.cs" />
Expand All @@ -199,6 +200,7 @@
<Compile Include="SampleCsSetPoint.cs" />
<Compile Include="SampleCsShadedBrep.cs" />
<Compile Include="SampleCsShadedView.cs" />
<Compile Include="SampleCSSilhouetteDraftCurve.cs" />
<Compile Include="SampleCsSineWaveLoft.cs" />
<Compile Include="SampleCsSketch.cs" />
<Compile Include="SampleCsSmash.cs" />
Expand Down

0 comments on commit 64564b6

Please sign in to comment.