diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b45b5ed9..e5385414c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +* `BeamFromCurve` GH component accepts now referenced Rhino curves, referenced Rhino object IDs and internalized lines. + ### Removed diff --git a/examples/Grasshopper/CT_NEW_UI_Example.3dm b/examples/Grasshopper/CT_NEW_UI_Example.3dm index fc76e3bd2d..3cf8a0b780 100644 Binary files a/examples/Grasshopper/CT_NEW_UI_Example.3dm and b/examples/Grasshopper/CT_NEW_UI_Example.3dm differ diff --git a/examples/Grasshopper/CT_NEW_UI_Example.gh b/examples/Grasshopper/CT_NEW_UI_Example.gh index 4e7b0ea145..ea76e82d38 100644 Binary files a/examples/Grasshopper/CT_NEW_UI_Example.gh and b/examples/Grasshopper/CT_NEW_UI_Example.gh differ diff --git a/src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py b/src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py index 9e278b8ecb..85c92b9731 100644 --- a/src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py +++ b/src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py @@ -1,13 +1,14 @@ """Creates a Beam from a LineCurve.""" -from compas.geometry import Line -from compas.scene import Scene -from compas_rhino.conversions import curve_to_compas -from compas_rhino.conversions import vector_to_compas from ghpythonlib.componentbase import executingcomponent as component from Grasshopper.Kernel.GH_RuntimeMessageLevel import Error from Grasshopper.Kernel.GH_RuntimeMessageLevel import Warning from Rhino.RhinoDoc import ActiveDoc +import rhinoscriptsyntax as rs + +from compas.scene import Scene +from compas_rhino.conversions import line_to_compas +from compas_rhino.conversions import vector_to_compas from compas_timber.ghpython.rhino_object_name_attributes import update_rhobj_attributes_name from compas_timber.parts import Beam as CTBeam @@ -63,15 +64,17 @@ def RunScript(self, Centerline, ZVector, Width, Height, Category, updateRefObj): if len(Category) != N: Category = [Category[0] for _ in range(N)] - for guid, z, w, h, c in zip(Centerline, ZVector, Width, Height, Category): - curve = curve_to_compas(ActiveDoc.Objects.FindId(guid)) - line = Line(curve.start, curve.end) + for line, z, w, h, c in zip(Centerline, ZVector, Width, Height, Category): + guid, geometry = self._get_guid_and_geometry(line) + rhino_line = rs.coerceline(geometry) + line = line_to_compas(rhino_line) + z = vector_to_compas(z) if z else None beam = CTBeam.from_centerline(centerline=line, width=w, height=h, z_vector=z) - beam.attributes["rhino_guid"] = str(guid) + beam.attributes["rhino_guid"] = str(guid) if guid else None beam.attributes["category"] = c - - if updateRefObj: + print(guid) + if updateRefObj and guid: update_rhobj_attributes_name(guid, "width", str(w)) update_rhobj_attributes_name(guid, "height", str(h)) update_rhobj_attributes_name(guid, "zvector", str(list(beam.frame.zaxis))) @@ -83,3 +86,14 @@ def RunScript(self, Centerline, ZVector, Width, Height, Category, updateRefObj): Blank = scene.draw() return Beam, Blank + + def _get_guid_and_geometry(self, line): + # internalized curves and GH geometry will not have persistent GUIDs, referenced Rhino objects will + # type hint on the input has to be 'ghdoc' for this to work + guid = None + geometry = line + rhino_obj = ActiveDoc.Objects.FindId(line) + if rhino_obj: + guid = line + geometry = rhino_obj.Geometry + return guid, geometry diff --git a/src/compas_timber/ghpython/components/CT_Beam_fromCurve/metadata.json b/src/compas_timber/ghpython/components/CT_Beam_fromCurve/metadata.json index 45fc6be9e2..88e1b00dff 100644 --- a/src/compas_timber/ghpython/components/CT_Beam_fromCurve/metadata.json +++ b/src/compas_timber/ghpython/components/CT_Beam_fromCurve/metadata.json @@ -12,7 +12,7 @@ { "name": "Centerline", "description": "Referenced curve or line, Guid of curve or line in the active Rhino document.", - "typeHintID": "guid", + "typeHintID": "ghdoc", "scriptParamAccess": 1 }, {