forked from mdjcad/SampleCsCommands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCsMeshOutline.cs
100 lines (89 loc) · 2.74 KB
/
SampleCsMeshOutline.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using Rhino;
using Rhino.Commands;
using Rhino.Display;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
namespace SampleCsCommands
{
[System.Runtime.InteropServices.Guid("35b38130-0a2f-4577-bd3a-f5e4ee132daa")]
public class SampleCsMeshOutline : Command
{
public SampleCsMeshOutline()
{
}
public override string EnglishName
{
get { return "SampleCsMeshOutline"; }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
GetObject go = new GetObject();
go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes");
go.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh;
go.GroupSelect = true;
go.SubObjectSelect = false;
go.GetMultiple(1, 0);
if (go.CommandResult() != Result.Success)
return go.CommandResult();
List<Mesh> InMeshes = new List<Mesh>(go.ObjectCount);
List<RhinoObject> InMeshObjects = new List<RhinoObject>(go.ObjectCount);
List<RhinoObject> InObjects = new List<RhinoObject>(go.ObjectCount);
for (int i = 0; i < go.ObjectCount; i++)
{
ObjRef objRef = go.Object(i);
Mesh mesh = objRef.Mesh();
if (null == mesh)
InObjects.Add(objRef.Object());
else
{
InMeshes.Add(mesh);
InMeshObjects.Add(objRef.Object());
}
}
ObjRef[] meshRefs = null;
if (InObjects.Count > 0)
{
meshRefs = RhinoObject.GetRenderMeshes(InObjects, true, false);
if (null != meshRefs)
{
for (int i = 0; i < meshRefs.Length; i++)
{
Mesh mesh = meshRefs[i].Mesh();
if (null != mesh)
InMeshes.Add(mesh);
}
}
}
RhinoViewport vp = doc.Views.ActiveView.ActiveViewport;
for (int i = 0; i < InMeshes.Count; i++)
{
Polyline[] plines = InMeshes[i].GetOutlines(vp);
if (null != plines)
{
for (int j = 0; j < plines.Length; j++)
{
Rhino.Geometry.PolylineCurve plineCrv = new PolylineCurve(plines[j]);
plineCrv.RemoveShortSegments(RhinoMath.SqrtEpsilon);
if (plineCrv.IsValid)
{
Guid objId = doc.Objects.AddCurve(plineCrv);
RhinoObject obj = doc.Objects.Find(objId);
if (null != obj)
obj.Select(true);
}
}
}
}
for (int i = 0; i < InObjects.Count; i++)
InObjects[i].Select(false);
for (int i = 0; i < InMeshObjects.Count; i++)
InMeshObjects[i].Select(false);
doc.Views.Redraw();
return Result.Success;
}
}
}