From c93db4e8431127bfa507c8f6d4a2c30ee9a07d13 Mon Sep 17 00:00:00 2001 From: obucklin Date: Wed, 17 Apr 2024 09:49:20 +0200 Subject: [PATCH] component format changes --- .../components/CT_Attributes_Check/code.py | 8 +-- .../components/CT_Attributes_Delete/code.py | 14 ++--- .../components/CT_Attributes_Get/code.py | 30 +++++----- .../CT_Attributes_Get_Custom/code.py | 6 +- .../components/CT_Attributes_Set/code.py | 34 +++++------ .../CT_Attributes_Set_Custom/code.py | 10 ++-- .../ghpython/components/CT_BTLx/code.py | 12 ++-- .../components/CT_Bake_BoxMap/code.py | 16 +++--- .../components/CT_Beam_fromCurve/code.py | 56 +++++++++---------- .../ghpython/components/CT_FindByGuid/code.py | 6 +- .../CT_Joint_Rule_Topology_T/code.py | 2 +- .../components/CT_ShowBeamFaces/code.py | 6 +- .../components/CT_ShowBeamIndex/code.py | 6 +- .../components/CT_ShowJointTypes/code.py | 6 +- .../components/CT_ShowTopologyTypes/code.py | 6 +- 15 files changed, 109 insertions(+), 109 deletions(-) diff --git a/src/compas_timber/ghpython/components/CT_Attributes_Check/code.py b/src/compas_timber/ghpython/components/CT_Attributes_Check/code.py index a2fa36560..396a139e8 100644 --- a/src/compas_timber/ghpython/components/CT_Attributes_Check/code.py +++ b/src/compas_timber/ghpython/components/CT_Attributes_Check/code.py @@ -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: diff --git a/src/compas_timber/ghpython/components/CT_Attributes_Delete/code.py b/src/compas_timber/ghpython/components/CT_Attributes_Delete/code.py index ac220f731..043d1d59b 100644 --- a/src/compas_timber/ghpython/components/CT_Attributes_Delete/code.py +++ b/src/compas_timber/ghpython/components/CT_Attributes_Delete/code.py @@ -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 diff --git a/src/compas_timber/ghpython/components/CT_Attributes_Get/code.py b/src/compas_timber/ghpython/components/CT_Attributes_Get/code.py index 40cc0f98e..81b68e985 100644 --- a/src/compas_timber/ghpython/components/CT_Attributes_Get/code.py +++ b/src/compas_timber/ghpython/components/CT_Attributes_Get/code.py @@ -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 ========================================= @@ -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) diff --git a/src/compas_timber/ghpython/components/CT_Attributes_Get_Custom/code.py b/src/compas_timber/ghpython/components/CT_Attributes_Get_Custom/code.py index 25a01bf35..53895a4c8 100644 --- a/src/compas_timber/ghpython/components/CT_Attributes_Get_Custom/code.py +++ b/src/compas_timber/ghpython/components/CT_Attributes_Get_Custom/code.py @@ -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: diff --git a/src/compas_timber/ghpython/components/CT_Attributes_Set/code.py b/src/compas_timber/ghpython/components/CT_Attributes_Set/code.py index 514f9f25a..ce1a09f6c 100644 --- a/src/compas_timber/ghpython/components/CT_Attributes_Set/code.py +++ b/src/compas_timber/ghpython/components/CT_Attributes_Set/code.py @@ -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.", @@ -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)) diff --git a/src/compas_timber/ghpython/components/CT_Attributes_Set_Custom/code.py b/src/compas_timber/ghpython/components/CT_Attributes_Set_Custom/code.py index c723086a5..04d2ff530 100644 --- a/src/compas_timber/ghpython/components/CT_Attributes_Set_Custom/code.py +++ b/src/compas_timber/ghpython/components/CT_Attributes_Set_Custom/code.py @@ -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) diff --git a/src/compas_timber/ghpython/components/CT_BTLx/code.py b/src/compas_timber/ghpython/components/CT_BTLx/code.py index 2ec1cca4f..c33f599db 100644 --- a/src/compas_timber/ghpython/components/CT_BTLx/code.py +++ b/src/compas_timber/ghpython/components/CT_BTLx/code.py @@ -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() diff --git a/src/compas_timber/ghpython/components/CT_Bake_BoxMap/code.py b/src/compas_timber/ghpython/components/CT_Bake_BoxMap/code.py index d3e741950..45dbac3b6 100644 --- a/src/compas_timber/ghpython/components/CT_Bake_BoxMap/code.py +++ b/src/compas_timber/ghpython/components/CT_Bake_BoxMap/code.py @@ -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: 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 85c92b973..0852fe09f 100644 --- a/src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py +++ b/src/compas_timber/ghpython/components/CT_Beam_fromCurve/code.py @@ -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) @@ -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 diff --git a/src/compas_timber/ghpython/components/CT_FindByGuid/code.py b/src/compas_timber/ghpython/components/CT_FindByGuid/code.py index 0ad33518a..b8b4443c8 100644 --- a/src/compas_timber/ghpython/components/CT_FindByGuid/code.py +++ b/src/compas_timber/ghpython/components/CT_FindByGuid/code.py @@ -3,15 +3,15 @@ class FindBeamByRhinoGuid(component): - def RunScript(self, Beams, Guid): - if not (Beams and Guid): + def RunScript(self, beams, Guid): + if not (beams and Guid): return if not isinstance(Guid, list): Guid = [Guid] Guid = [str(g) for g in Guid] FoundBeam = [] - for beam in Beams: + for beam in beams: if beam.attributes.get("rhino_guid", None) in Guid: FoundBeam.append(beam) diff --git a/src/compas_timber/ghpython/components/CT_Joint_Rule_Topology_T/code.py b/src/compas_timber/ghpython/components/CT_Joint_Rule_Topology_T/code.py index 82b5e9fef..84f1c9827 100644 --- a/src/compas_timber/ghpython/components/CT_Joint_Rule_Topology_T/code.py +++ b/src/compas_timber/ghpython/components/CT_Joint_Rule_Topology_T/code.py @@ -19,7 +19,7 @@ def __init__(self): for cls in get_leaf_subclasses(Joint): if cls.SUPPORTED_TOPOLOGY == JointTopology.TOPO_T: self.classes[cls.__name__] = cls - if ghenv.Component.Params.Output[0].NickName == 'Rule': + if ghenv.Component.Params.Output[0].NickName == "Rule": self.joint_type = TButtJoint self.clicked = False else: diff --git a/src/compas_timber/ghpython/components/CT_ShowBeamFaces/code.py b/src/compas_timber/ghpython/components/CT_ShowBeamFaces/code.py index a182472dc..3d5eec986 100644 --- a/src/compas_timber/ghpython/components/CT_ShowBeamFaces/code.py +++ b/src/compas_timber/ghpython/components/CT_ShowBeamFaces/code.py @@ -5,13 +5,13 @@ class ShowBeamFaces(component): - def RunScript(self, Assembly): + def RunScript(self, assembly): self.pt = [] self.txt = [] - if not Assembly: + if not assembly: return None - for beam in Assembly.beams: + for beam in assembly.beams: for f_index, face in enumerate(beam.faces): self.pt.append(point_to_rhino(face.point)) self.txt.append(str(f_index)) diff --git a/src/compas_timber/ghpython/components/CT_ShowBeamIndex/code.py b/src/compas_timber/ghpython/components/CT_ShowBeamIndex/code.py index 8d63630c9..17cb83603 100644 --- a/src/compas_timber/ghpython/components/CT_ShowBeamIndex/code.py +++ b/src/compas_timber/ghpython/components/CT_ShowBeamIndex/code.py @@ -5,13 +5,13 @@ class ShowBeamIndex(component): - def RunScript(self, Assembly): + def RunScript(self, assembly): self.pt = [] self.txt = [] - if not Assembly: + if not assembly: return None - for beam in Assembly.beams: + for beam in assembly.beams: self.pt.append(point_to_rhino(beam.midpoint)) self.txt.append(str(beam.key)) diff --git a/src/compas_timber/ghpython/components/CT_ShowJointTypes/code.py b/src/compas_timber/ghpython/components/CT_ShowJointTypes/code.py index 58ce500cc..64ba695b9 100644 --- a/src/compas_timber/ghpython/components/CT_ShowJointTypes/code.py +++ b/src/compas_timber/ghpython/components/CT_ShowJointTypes/code.py @@ -7,14 +7,14 @@ class ShowJointTypes(component): - def RunScript(self, Assembly): + def RunScript(self, assembly): self.pt = [] self.txt = [] - if not Assembly: + if not assembly: return - for joint in Assembly.joints: + for joint in assembly.joints: line_a, line_b = joint.beams[0].centerline, joint.beams[1].centerline [p1, t1], [p2, t2] = intersection_line_line_3D(line_a, line_b, float("inf"), False, 1e-3) p1 = point_to_rhino(p1) diff --git a/src/compas_timber/ghpython/components/CT_ShowTopologyTypes/code.py b/src/compas_timber/ghpython/components/CT_ShowTopologyTypes/code.py index 98a0d0f8c..c38dee109 100644 --- a/src/compas_timber/ghpython/components/CT_ShowTopologyTypes/code.py +++ b/src/compas_timber/ghpython/components/CT_ShowTopologyTypes/code.py @@ -7,13 +7,13 @@ class ShowTopologyTypes(component): - def RunScript(self, Assembly): + def RunScript(self, assembly): self.pt = [] self.txt = [] - if not Assembly: + if not assembly: return - for topo in Assembly.topologies: + for topo in assembly.topologies: beam_a = topo["beam_a"] beam_b = topo["beam_b"] topology = topo.get("detected_topo")