@@ -88,10 +88,183 @@ For more information on visualisation scenes, see :doc:`/userguide/basics.visual
8888 Conversions
8989===========
9090
91+ For conversion between Rhino objects and COMPAS objects, different scenarios exist.
92+
93+ Rhino Geometry to COMPAS
94+ ------------------------
95+
96+ Conversions of geometry is straightforward and explicit.
97+
98+ .. code-block :: python
99+
100+ import Rhino.Geometry
101+ import compas_rhino.conversions
102+
103+ point = Rhino.Geometry.Point3d(... )
104+ point = compas_rhino.conversions.point_to_compas(point)
105+
106+ line = Rhino.Geometry.Line(... )
107+ line = compas_rhino.conversions.line_to_compas(line)
108+
109+ plane = Rhino.Geometry.Plane(... )
110+ plane = compas_rhino.conversions.plane_to_compas(plane)
111+
112+ box = Rhino.Geometry.Box(... )
113+ box = compas_rhino.conversions.box_to_compas(box)
114+
115+ mesh = Rhino.Geometry.Mesh(... )
116+ mesh = compas_rhino.conversions.mesh_to_compas(mesh)
117+
118+ curve = Rhino.Geometry.Curve(... )
119+ curve = compas_rhino.conversions.curve_to_compas(curve)
120+
121+ surface = Rhino.Geometry.Surface(... )
122+ surface = compas_rhino.conversions.surface_to_compas(surface)
123+
124+ brep = Rhino.Geometry.Brep(... )
125+ brep = compas_rhino.conversions.brep_to_compas(brep)
126+
127+
128+ Note that Rhino doen't distinguish between a frame and a plane.
129+ Therefore, to convert `Rhino.Geometry.Plane ` to :class: `compas.geometry.Frame `.
130+
131+ .. code-block :: python
132+
133+ plane = Rhino.Geometry.Plane(... )
134+ frame = compas_rhino.conversions.plane_to_compas_frame(plane)
135+
136+
137+ Rhino Object to COMPAS
138+ ----------------------
139+
140+ A Rhino Document contains Rhino Object instead of Rhino Geometry.
141+ The geometry of a Rhino Object is stored in the corresponding attribute (`obj.Geometry `).
142+
143+ Converting point, curve, and mesh objects is straightforward.
144+
145+ .. code-block :: python
146+
147+ import compas_rhino.objects
148+ import compas_rhino.conversions
149+
150+ guid = compas_rhino.objects.select_point()
151+ point = compas_rhino.conversions.pointobject_to_compas(guid)
152+
153+ guid = compas_rhino.objects.select_curve()
154+ curve = compas_rhino.conversions.curveobject_to_compas(guid)
155+
156+ guid = compas_rhino.objects.select_mesh()
157+ mesh = compas_rhino.conversions.meshobject_to_compas(guid)
158+
159+
160+ In the case of curve objects, note that the conversion function will return a NurbsCurve in almost all cases.
161+ If the curve has a specific geometry, it can be converted explicitly using the corresponding geomtry conversion function.
162+ For example, if the curve is a circle.
163+
164+ .. code-block :: python
165+
166+ import compas_rhino.objects
167+ import compas_rhino.conversions
168+
169+ guid = compas_rhino.objects.select_curve()
170+ obj = compas_rhino.objects.find_object(guid)
171+
172+ circle = compas_rhino.conversions.curve_to_compas_circle(obj.Geometry)
173+
174+
175+ In the case of all other objects, conversions are a bit trickier.
176+ This is because in a Rhino Document, almost all other geometries are represented by a BrepObject regardless of the actual geometry type.
177+ For example, when you add a sphere to a model, the DocObject is a BrepObject, and the geometry of the object is a Brep.
178+ Therefore, conversions of other objects have to be done more carefully.
179+
180+ .. code-block :: python
181+
182+ import compas_rhino.objects
183+ import compas_rhino.conversions
184+
185+ guid = compas_rhino.objects.select_object()
186+ brep = compas_rhino.conversions.brepobject_to_compas(guid)
187+
188+
189+ Also here, if the object is (supposed to be) a specific type of geometry,
190+ conversion can be done more explicitly using the geometry conversion functions instead.
191+ For example, if the geometry of the object is a Rhino Cylinder.
192+
193+ .. code-block :: python
194+
195+ import compas_rhino.objects
196+ import compas_rhino.conversions
197+
198+ guid = compas_rhino.objects.select_object()
199+ obj = compas_rhino.objects.find_object(guid)
200+
201+ cylinder = compas_rhino.conversions.brep_to_compas_cylinder(obj.Geometry)
202+
203+
204+ COMPAS to Rhino Geometry
205+ ------------------------
206+
207+ .. code-block :: python
208+
209+ import compas.geometry
210+ import compas_rhino.conversions
211+
212+ point = compas.geometry.Point(... )
213+ point = compas_rhino.conversions.point_to_rhino(point)
214+
215+ line = compas.geometry.Line(... )
216+ line = compas_rhino.conversions.line_to_rhino(line)
217+
218+ plane = compas.geometry.Plane(... )
219+ plane = compas_rhino.conversions.plane_to_rhino(plane)
220+
221+ box = compas.geometry.Box(... )
222+ box = compas_rhino.conversions.box_to_rhino(box)
223+
224+ curve = compas.geometry.Curve(... )
225+ curve = compas_rhino.conversions.curve_to_rhino(curve)
226+
227+ surface = compas.geometry.Surface(... )
228+ surface = compas_rhino.conversions.surface_to_rhino(surface)
229+
230+ brep = compas.geometry.Brep(... )
231+ brep = compas_rhino.conversions.brep_to_rhino(brep)
232+
233+
234+ To convert a :class: `compas.geometry.Frame `.
235+
236+ .. code-block :: python
237+
238+ frame = compas.geometry.Frame(... )
239+ plane = compas_rhino.conversions.frame_to_rhino_plane(frame)
240+
241+
242+ COMPAS to Rhino Object
243+ ----------------------
244+
245+ COMPAS objects are converted to Rhino Objects implicitly, by placing them into a visualisation scene.
246+ However, you can create a Rhino Object in a Rhino Dcocument explicitly from a COMPAS object.
247+
248+ .. code-block :: python
249+
250+ import scriptcontext as sc
251+ import compas.geometry
252+ import compas_rhino_conversions
253+
254+ point = compas.geometry.Point(... )
255+ geometry = compas_rhino.conversions.point_to_rhino(point)
256+
257+ guid = sc.doc.Objects.AddPoint(geometry)
258+
91259
92260 Data Exchange
93261=============
94262
263+ JSON
264+ ----
265+
266+ rhino3dm
267+ --------
95268
96269Remote Procedure Calls
97270======================
0 commit comments