Skip to content

Commit e532fd9

Browse files
committed
module functions instead of static functions
1 parent 7b3fac6 commit e532fd9

File tree

1 file changed

+22
-23
lines changed
  • src/compas_rhino/geometry/brep

1 file changed

+22
-23
lines changed

src/compas_rhino/geometry/brep/brep.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@
4242
from .vertex import RhinoBrepVertex
4343

4444

45+
def _export_brep_to_file(brep, filepath):
46+
objects = Rhino.RhinoDoc.ActiveDoc.Objects
47+
obj_id = objects.Add(brep)
48+
obj = objects.Find(obj_id)
49+
obj.Select(True)
50+
rs.Command('_-Export "' + filepath + '" _Enter', False)
51+
objects.Delete(obj_id, True)
52+
53+
54+
def _import_brep_from_file(filepath):
55+
# TODO: this only seems to work in ScriptEditor (AKA rhino, not GH)
56+
rs.Command('_-Import "' + filepath + '" _Enter', False)
57+
guid = rs.LastCreatedObjects()[0] # this fails, could be Rhino bug
58+
obj = compas_rhino.objects.find_object(guid)
59+
geometry = obj.Geometry.Duplicate()
60+
compas_rhino.objects.delete_object(guid)
61+
return RhinoBrep.from_native(geometry)
62+
63+
4564
class RhinoBrep(Brep):
4665
"""Rhino Brep backend class.
4766
@@ -276,7 +295,6 @@ def surfaces(self):
276295
assert self._brep
277296
return [[RhinoNurbsSurface.from_native(s.ToNurbsSurface()) for s in self._brep.Surfaces]]
278297

279-
280298
# ==============================================================================
281299
# Constructors
282300
# ==============================================================================
@@ -531,7 +549,7 @@ def from_iges(cls, filepath):
531549
"""
532550
if not filepath.endswith(".igs"):
533551
raise ValueError("Expected file with .igs extension")
534-
return cls._import_brep_from_file(filepath)
552+
return _import_brep_from_file(filepath)
535553

536554
@classmethod
537555
def from_loft(cls, curves):
@@ -725,17 +743,7 @@ def from_step(cls, filepath):
725743
"""
726744
if not filepath.endswith(".step"):
727745
raise ValueError("Expected file with .step extension")
728-
return cls._import_brep_from_file(filepath)
729-
730-
@staticmethod
731-
def _import_brep_from_file(filepath):
732-
# TODO: this only seems to work in ScriptEditor (AKA rhino, not GH)
733-
rs.Command('_-Import "' + filepath + '" _Enter', False)
734-
guid = rs.LastCreatedObjects()[0] # this fails, could be Rhino bug
735-
obj = compas_rhino.objects.find_object(guid)
736-
geometry = obj.Geometry.Duplicate()
737-
compas_rhino.objects.delete_object(guid)
738-
return RhinoBrep.from_native(geometry)
746+
return _import_brep_from_file(filepath)
739747

740748
@classmethod
741749
def from_sweep(cls, profile, path, is_closed=False, tolerance=None):
@@ -857,16 +865,7 @@ def to_meshes(self, u=16, v=16):
857865
def to_step(self, filepath):
858866
if not filepath.endswith(".step"):
859867
raise ValueError("Attempted to export STEP but file ends with {} extension".format(filepath.split(".")[-1]))
860-
self._export_brep_to_file(filepath, self._brep)
861-
862-
@staticmethod
863-
def _export_brep_to_file(filepath, brep):
864-
objects = Rhino.RhinoDoc.ActiveDoc.Objects
865-
obj_id = objects.Add(brep)
866-
obj = objects.Find(obj_id)
867-
obj.Select(True)
868-
rs.Command('_-Export "' + filepath + '" _Enter', False)
869-
objects.Delete(obj_id, True)
868+
_export_brep_to_file(self._brep, filepath)
870869

871870
def transform(self, matrix):
872871
"""Transform this Brep by given transformation matrix

0 commit comments

Comments
 (0)