Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internalized lines #198

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Binary file modified examples/Grasshopper/CT_NEW_UI_Example.3dm
Binary file not shown.
Binary file modified examples/Grasshopper/CT_NEW_UI_Example.gh
Binary file not shown.
34 changes: 24 additions & 10 deletions src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
{
Expand Down
Loading