Skip to content

Commit 9947037

Browse files
committed
smal l fixes and docs
1 parent 651ba07 commit 9947037

File tree

6 files changed

+272
-49
lines changed

6 files changed

+272
-49
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3737
* Added `compas_rhino.conversions.docobjects.curveobject_to_compas`.
3838
* Added `compas_rhino.conversions.docobjects.meshobject_to_compas`.
3939
* Added `compas_rhino.conversions.docobjects.pointobject_to_compas`.
40-
* Added `compas_rhino.conversions.docobjects.surfaceobject_to_compas`.
4140
* Added `compas.datastructures.HashTree` and `compas.datastructures.HashNode`.
4241

4342
### Changed

docs/userguide/cad.rhino.rst

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

96269
Remote Procedure Calls
97270
======================

src/compas_rhino/conversions/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
)
7171
from .breps import (
7272
brep_to_rhino,
73+
brep_to_compas,
7374
brep_to_compas_box,
7475
brep_to_compas_cone,
7576
brep_to_compas_cylinder,
@@ -92,7 +93,6 @@
9293
curveobject_to_compas,
9394
meshobject_to_compas,
9495
pointobject_to_compas,
95-
surfaceobject_to_compas,
9696
)
9797

9898

@@ -157,6 +157,7 @@
157157
"mesh_to_compas",
158158
# breps
159159
"brep_to_rhino",
160+
"brep_to_compas",
160161
"brep_to_compas_box",
161162
"brep_to_compas_cone",
162163
"brep_to_compas_cylinder",
@@ -174,5 +175,4 @@
174175
"curveobject_to_compas",
175176
"meshobject_to_compas",
176177
"pointobject_to_compas",
177-
"surfaceobject_to_compas",
178178
]

0 commit comments

Comments
 (0)