Skip to content

Commit

Permalink
component format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
obucklin committed Apr 17, 2024
1 parent 0ce9af4 commit c93db4e
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@


class Attributes_Check(component):
def RunScript(self, RefObj):
def RunScript(self, ref_obj):
self.data = []

list_input_valid(self, RefObj, "RefObj")
list_input_valid(self, ref_obj, "RefObj")

for obj in RefObj:
d = {"refobj": RefObj, "crv": None, "msg": [], "ok": None, "pln": None, "pt": None}
for obj in ref_obj:
d = {"refobj": ref_obj, "crv": None, "msg": [], "ok": None, "pln": None, "pt": None}

crv = Rhino.RhinoDoc.ActiveDoc.Objects.FindId(obj).Geometry
if not crv:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@


class Attributes_Delete(component):
def RunScript(self, RefObj, AttributeName, update):
if not item_input_valid(self, RefObj, "RefObj"):
def RunScript(self, ref_obj, attribute_name, update):
if not item_input_valid(self, ref_obj, "RefObj"):
return

if update and RefObj:
if not AttributeName:
if update and ref_obj:
if not attribute_name:
# clear all attributes from the refecenced object's name
update_rhobj_attributes_name(RefObj, operation="clear")
update_rhobj_attributes_name(ref_obj, operation="clear")
else:
# remove only the indicated attributes
for attr in AttributeName:
update_rhobj_attributes_name(RefObj, attribute=attr, operation="remove")
for attr in attribute_name:
update_rhobj_attributes_name(ref_obj, attribute=attr, operation="remove")

return
30 changes: 15 additions & 15 deletions src/compas_timber/ghpython/components/CT_Attributes_Get/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@


class Attributes_Get(component):
def RunScript(self, RefCrv):
if not RefCrv:
def RunScript(self, ref_crv):
if not ref_crv:
self.AddRuntimeMessage(Warning, "Input parameter RefCrv failed to collect data")

ZVector = []
Width = []
Height = []
Category = []
Group = []
z_vector = []
width = []
height = []
category = []
group = []

guid = RefCrv
guid = ref_crv
if guid:
# get attributes from the name string ==========================================
attr = get_obj_attributes(guid)
if attr:
if "width" in attr:
Width = float(attr["width"])
width = float(attr["width"])
if "height" in attr:
Height = float(attr["height"])
height = float(attr["height"])
if "category" in attr:
Category = attr["category"]
category = attr["category"]
if "zvector" in attr:
ZVector = attr["zvector"]
z_vector = attr["zvector"]
# it's a string, but Grasshopper will automatically cast this input as Vector3d

# get the group if objects are grouped =========================================
Expand All @@ -44,9 +44,9 @@ def RunScript(self, RefCrv):
self.AddRuntimeMessage(
Remark, "Some objects belong to more than one group! (I will pick the first group I find.)"
)
Group = gl[0]
group = gl[0]

else:
Group = []
group = []

return (ZVector, Width, Height, Category, Group)
return (z_vector, width, height, category, group)
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@


class Attributes_Get_Custom(component):
def RunScript(self, RefCrv):
if not RefCrv:
def RunScript(self, ref_crv):
if not ref_crv:
self.AddRuntimeMessage(Warning, "Input parameter RefCrv failed to collect data")

AttributeName = []
AttributeValue = []

guid = RefCrv
guid = ref_crv
if guid:
attrdict = get_obj_attributes(guid)
if attrdict:
Expand Down
34 changes: 17 additions & 17 deletions src/compas_timber/ghpython/components/CT_Attributes_Set/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@


class Attributes_Set(component):
def RunScript(self, RefObj, ZVector, Width, Height, Category, update):
_o = list_input_valid(self, RefObj, "RefObj")
def RunScript(self, ref_obj, z_vector, width, height, category, update):
_o = list_input_valid(self, ref_obj, "RefObj")
if not _o:
return

# requires at least one of these inputs to be not None
if ZVector or Width or Height or Category:
if z_vector or width or height or category:
pass
else:
self.AddRuntimeMessage(
Warning, "None of the input parameters 'ZVector', 'Width', 'Height', 'Category' collected any data."
)

n = len(RefObj)
n = len(ref_obj)

if ZVector:
if len(ZVector) not in (0, 1, n):
if z_vector:
if len(z_vector) not in (0, 1, n):
self.AddRuntimeMessage(
Error,
" Input parameter 'ZVector' requires either none, one or the same number of values as in refObj.",
)
if Width:
if len(Width) not in (0, 1, n):
if width:
if len(width) not in (0, 1, n):
self.AddRuntimeMessage(
Error,
" Input parameter 'Width' requires either none, one or the same number of values as in refObj.",
)
if Height:
if len(Height) not in (0, 1, n):
if height:
if len(height) not in (0, 1, n):
self.AddRuntimeMessage(
Error,
" Input parameter 'Height' requires either none, one or the same number of values as in refObj.",
)
if Category:
if len(Category) not in (0, 1, n):
if category:
if len(category) not in (0, 1, n):
self.AddRuntimeMessage(
Error,
" Input parameter 'Category' requires either none, one or the same number of values as in refObj.",
Expand All @@ -58,23 +58,23 @@ def get_item(items, i):
return items[i]

if update:
for i, ro in enumerate(RefObj):
for i, ro in enumerate(ref_obj):
guid = ro

# note: with input type set to Vector, it accepts only a Vector3d, or a string {x,y,z} and casts it to Vector3d
z = get_item(ZVector, i)
z = get_item(z_vector, i)
if z:
update_rhobj_attributes_name(guid, "zvector", "{%s,%s,%s}" % (z.X, z.Y, z.Z))

w = get_item(Width, i)
w = get_item(width, i)
if w:
update_rhobj_attributes_name(guid, "width", str(w))

h = get_item(Height, i)
h = get_item(height, i)
if h:
update_rhobj_attributes_name(guid, "height", str(h))

c = get_item(Category, i)
c = get_item(category, i)
if c:
update_rhobj_attributes_name(guid, "category", str(c))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


class Attributes_Set_Custom(component):
def RunScript(self, RefObj, Attribute, update):
o = list_input_valid(self, RefObj, "RefObj")
a = list_input_valid(self, Attribute, "Attribute")
def RunScript(self, ref_obj, attribute, update):
o = list_input_valid(self, ref_obj, "RefObj")
a = list_input_valid(self, attribute, "Attribute")

if update and o and a:
for attr in Attribute:
for attr in attribute:
if attr:
for guid in RefObj:
for guid in ref_obj:
if guid:
update_rhobj_attributes_name(guid, attr.name, attr.value)

Expand Down
12 changes: 6 additions & 6 deletions src/compas_timber/ghpython/components/CT_BTLx/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@


class WriteBTLx(component):
def RunScript(self, Assembly, Path, Write):
if not Assembly:
def RunScript(self, assembly, path, write):
if not assembly:
self.AddRuntimeMessage(Warning, "Input parameter Assembly failed to collect data")
return

btlx = BTLx(Assembly)
btlx = BTLx(assembly)
btlx.history["FileName"] = Rhino.RhinoDoc.ActiveDoc.Name

if Write:
if not Path:
if write:
if not path:
self.AddRuntimeMessage(Warning, "Input parameter Path failed to collect data")
return
with open(Path, "w") as f:
with open(path, "w") as f:
f.write(btlx.btlx_string())
return btlx.btlx_string()
16 changes: 8 additions & 8 deletions src/compas_timber/ghpython/components/CT_Bake_BoxMap/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@


class BakeBoxMap(component):
def RunScript(self, Assembly, MapSize, Bake):
if MapSize and len(MapSize) != 3:
def RunScript(self, assembly, map_size, bake):
if map_size and len(map_size) != 3:
self.AddRuntimeMessage(
Error, "Input parameter MapSize requires exactly three float values (scale factors in x,y,z directions)"
)
return

if MapSize:
dimx, dimy, dimz = MapSize
if map_size:
dimx, dimy, dimz = map_size
else:
# for the pine 251 material bitmap, rotated
dimx = 0.2
dimy = 0.2
dimz = 1.0

if not Assembly:
if not assembly:
self.AddRuntimeMessage(Warning, "Input parameters Assembly failed to collect any Beam objects.")
return

if not Bake:
if not bake:
return

try:
geometries = BrepGeometryConsumer(Assembly).result
geometries = BrepGeometryConsumer(assembly).result

frames = [frame_to_rhino(b.frame) for b in Assembly.beams]
frames = [frame_to_rhino(b.frame) for b in assembly.beams]
breps = [g.geometry.native_brep for g in geometries]

if frames and breps:
Expand Down
56 changes: 28 additions & 28 deletions src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,56 @@


class Beam_fromCurve(component):
def RunScript(self, Centerline, ZVector, Width, Height, Category, updateRefObj):
def RunScript(self, centerline, z_vector, width, height, category, updateRefObj):
# minimum inputs required
if not Centerline:
if not centerline:
self.AddRuntimeMessage(Warning, "Input parameter 'Centerline' failed to collect data")
if not Width:
if not width:
self.AddRuntimeMessage(Warning, "Input parameter 'Width' failed to collect data")
if not Height:
if not height:
self.AddRuntimeMessage(Warning, "Input parameter 'Height' failed to collect data")

# reformat unset parameters for consistency
if not ZVector:
ZVector = [None]
if not Category:
Category = [None]
if not z_vector:
z_vector = [None]
if not category:
category = [None]

Beam = []
Blank = []
beams = []
blanks = []
scene = Scene()

if Centerline and Height and Width:
if centerline and height and width:
# check list lengths for consistency
N = len(Centerline)
if len(ZVector) not in (0, 1, N):
N = len(centerline)
if len(z_vector) not in (0, 1, N):
self.AddRuntimeMessage(
Error, " In 'ZVector' I need either none, one or the same number of inputs as the Crv parameter."
)
if len(Width) not in (1, N):
if len(width) not in (1, N):
self.AddRuntimeMessage(
Error, " In 'W' I need either one or the same number of inputs as the Crv parameter."
)
if len(Height) not in (1, N):
if len(height) not in (1, N):
self.AddRuntimeMessage(
Error, " In 'H' I need either one or the same number of inputs as the Crv parameter."
)
if len(Category) not in (0, 1, N):
if len(category) not in (0, 1, N):
self.AddRuntimeMessage(
Error, " In 'Category' I need either none, one or the same number of inputs as the Crv parameter."
)

# duplicate data if None or single value
if len(ZVector) != N:
ZVector = [ZVector[0] for _ in range(N)]
if len(Width) != N:
Width = [Width[0] for _ in range(N)]
if len(Height) != N:
Height = [Height[0] for _ in range(N)]
if len(Category) != N:
Category = [Category[0] for _ in range(N)]
if len(z_vector) != N:
z_vector = [z_vector[0] for _ in range(N)]
if len(width) != N:
width = [width[0] for _ in range(N)]
if len(height) != N:
height = [height[0] for _ in range(N)]
if len(category) != N:
category = [category[0] for _ in range(N)]

for line, z, w, h, c in zip(Centerline, ZVector, Width, Height, Category):
for line, z, w, h, c in zip(centerline, z_vector, width, height, category):
guid, geometry = self._get_guid_and_geometry(line)
rhino_line = rs.coerceline(geometry)
line = line_to_compas(rhino_line)
Expand All @@ -80,12 +80,12 @@ def RunScript(self, Centerline, ZVector, Width, Height, Category, updateRefObj):
update_rhobj_attributes_name(guid, "zvector", str(list(beam.frame.zaxis)))
update_rhobj_attributes_name(guid, "category", c)

Beam.append(beam)
beams.append(beam)
scene.add(beam.blank)

Blank = scene.draw()
blanks = scene.draw()

return Beam, Blank
return beams, blanks

def _get_guid_and_geometry(self, line):
# internalized curves and GH geometry will not have persistent GUIDs, referenced Rhino objects will
Expand Down
Loading

0 comments on commit c93db4e

Please sign in to comment.