forked from mdjcad/SampleCsCommands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCsExplodeHatch.cs
70 lines (64 loc) · 2.1 KB
/
SampleCsExplodeHatch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using Rhino;
using Rhino.Commands;
namespace SampleCsCommands
{
[System.Runtime.InteropServices.Guid("17b2d51e-5bd6-457d-a43c-1c2ec3529f7c")]
public class SampleCsExplodeHatch : Command
{
public SampleCsExplodeHatch()
{
}
public override string EnglishName
{
get { return "SampleCsExplodeHatch"; }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Hatch;
Rhino.DocObjects.ObjRef objref = null;
Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select hatch to explode", false, filter, out objref);
if (rc != Rhino.Commands.Result.Success || objref == null)
return rc;
Rhino.Geometry.Hatch hatch = (Rhino.Geometry.Hatch)objref.Geometry();
if (null == hatch)
return Rhino.Commands.Result.Failure;
Rhino.Geometry.GeometryBase[] hatch_geom = hatch.Explode();
if (null != hatch_geom)
{
for (int i = 0; i < hatch_geom.Length; i++)
{
Rhino.Geometry.GeometryBase geom = hatch_geom[i];
if (null != geom)
{
switch (geom.ObjectType)
{
case Rhino.DocObjects.ObjectType.Point:
{
Rhino.Geometry.Point point = (Rhino.Geometry.Point)geom;
if (null != point)
doc.Objects.AddPoint(point.Location);
}
break;
case Rhino.DocObjects.ObjectType.Curve:
{
Rhino.Geometry.Curve curve = (Rhino.Geometry.Curve)geom;
if (null != curve)
doc.Objects.AddCurve(curve);
}
break;
case Rhino.DocObjects.ObjectType.Brep:
{
Rhino.Geometry.Brep brep = (Rhino.Geometry.Brep)geom;
if (null != brep)
doc.Objects.AddBrep(brep);
}
break;
}
}
}
}
return Rhino.Commands.Result.Success;
}
}
}