|
42 | 42 | from .vertex import RhinoBrepVertex |
43 | 43 |
|
44 | 44 |
|
| 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 | + |
45 | 64 | class RhinoBrep(Brep): |
46 | 65 | """Rhino Brep backend class. |
47 | 66 |
|
@@ -276,7 +295,6 @@ def surfaces(self): |
276 | 295 | assert self._brep |
277 | 296 | return [[RhinoNurbsSurface.from_native(s.ToNurbsSurface()) for s in self._brep.Surfaces]] |
278 | 297 |
|
279 | | - |
280 | 298 | # ============================================================================== |
281 | 299 | # Constructors |
282 | 300 | # ============================================================================== |
@@ -531,7 +549,7 @@ def from_iges(cls, filepath): |
531 | 549 | """ |
532 | 550 | if not filepath.endswith(".igs"): |
533 | 551 | raise ValueError("Expected file with .igs extension") |
534 | | - return cls._import_brep_from_file(filepath) |
| 552 | + return _import_brep_from_file(filepath) |
535 | 553 |
|
536 | 554 | @classmethod |
537 | 555 | def from_loft(cls, curves): |
@@ -725,17 +743,7 @@ def from_step(cls, filepath): |
725 | 743 | """ |
726 | 744 | if not filepath.endswith(".step"): |
727 | 745 | 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) |
739 | 747 |
|
740 | 748 | @classmethod |
741 | 749 | def from_sweep(cls, profile, path, is_closed=False, tolerance=None): |
@@ -857,16 +865,7 @@ def to_meshes(self, u=16, v=16): |
857 | 865 | def to_step(self, filepath): |
858 | 866 | if not filepath.endswith(".step"): |
859 | 867 | 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) |
870 | 869 |
|
871 | 870 | def transform(self, matrix): |
872 | 871 | """Transform this Brep by given transformation matrix |
|
0 commit comments