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

Gh arg names #317

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@


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

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

for obj in ref_obj:
d = {"refobj": ref_obj, "crv": None, "msg": [], "ok": None, "pln": None, "pt": None}
for obj in RefObj:
d = {"refobj": RefObj, "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 @@ -10,13 +10,12 @@
"iconDisplay": 2,
"inputParameters": [
{
"name": "RefCrv",
"name": "RefObj",
"description": "Referenced curve or line, Guid of curve or line in the active Rhino document.",
"typeHintID": "guid",
"scriptParamAccess": 1
}
],
"outputParameters": [
]
"outputParameters": []
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: is this component really used?
# flake8: noqa
from compas_timber.ghpython.ghcomponent_helpers import item_input_valid
from compas_timber.ghpython.workflow import Attribute
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, ref_obj, attribute_name, update):
if not item_input_valid(self, ref_obj, "RefObj"):
def RunScript(self, RefObj, AttributeName, update):
if not item_input_valid(self, RefObj, "RefObj"):
return

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

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


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

z_vector = []
Expand All @@ -19,7 +19,7 @@ def RunScript(self, ref_crv):
category = []
group = []

guid = ref_crv
guid = RefCrv
if guid:
# get attributes from the name string ==========================================
attr = get_obj_attributes(guid)
Expand Down Expand Up @@ -48,5 +48,10 @@ def RunScript(self, ref_crv):

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

return (z_vector, width, height, category, group)
return (ZVector, 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, ref_crv):
if not ref_crv:
def RunScript(self, RefCrv):
if not RefCrv:
self.AddRuntimeMessage(Warning, "Input parameter RefCrv failed to collect data")

AttributeName = []
AttributeValue = []

guid = ref_crv
guid = RefCrv
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, ref_obj, z_vector, width, height, category, update):
_o = list_input_valid(self, ref_obj, "RefObj")
def RunScript(self, RefObj, ZVector, Width, Height, Category, update):
_o = list_input_valid(self, RefObj, "RefObj")
if not _o:
return

# requires at least one of these inputs to be not None
if z_vector or width or height or category:
if ZVector 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(ref_obj)
n = len(RefObj)

if z_vector:
if len(z_vector) not in (0, 1, n):
if ZVector:
if len(ZVector) 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(ref_obj):
for i, ro in enumerate(RefObj):
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(z_vector, i)
z = get_item(ZVector, 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,15 +5,13 @@


class Attributes_Set_Custom(component):
def RunScript(self, ref_obj, attribute, update):
o = list_input_valid(self, ref_obj, "RefObj")
a = list_input_valid(self, attribute, "Attribute")
def RunScript(self, RefObj, Attribute, update):
o = list_input_valid(self, RefObj, "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 ref_obj:
for guid in RefObj:
if guid:
update_rhobj_attributes_name(guid, attr.name, attr.value)

return
17 changes: 9 additions & 8 deletions src/compas_timber/ghpython/components/CT_BTLx/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@


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

btlx = BTLx(model)
btlx = BTLx(Model)
btlx.history["FileName"] = Rhino.RhinoDoc.ActiveDoc.Name

if write:
if not path:
if not Path:
self.AddRuntimeMessage(Warning, "Input parameter Path failed to collect data")
return
if path[-5:] != ".btlx":
path += ".btlx"
with open(path, "w") as f:
if Path[-5:] != ".btlx":
Path += ".btlx"
with open(Path, "w") as f:
f.write(btlx.btlx_string())
return btlx.btlx_string()
BTLx = btlx.btlx_string()
return BTLx
5 changes: 2 additions & 3 deletions src/compas_timber/ghpython/components/CT_BTLx/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
"scriptParamAccess": 0
},
{
"name": "Write",
"name": "write",
"description": "Write to file.",
"typeHintID": "bool",
"scriptParamAccess": 0
}

],
"outputParameters": [
{
Expand All @@ -36,4 +35,4 @@
}
]
}
}
}
14 changes: 7 additions & 7 deletions src/compas_timber/ghpython/components/CT_Bake_BoxMap/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@


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

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

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

if not bake:
return

try:
frames = [frame_to_rhino(b.frame) for b in model.beams]
breps = [beam.geometry.native_brep for beam in model.beams]
frames = [frame_to_rhino(b.frame) for b in Model.beams]
breps = [beam.geometry.native_brep for beam in Model.beams]

if frames and breps:
rs.EnableRedraw(False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
"scriptParamAccess": 1
},
{
"name": "Bake",
"name": "bake",
"description": "Set to True to Bake. Nothing happens if None or False.",
"typeHintID": "bool",
"scriptParamAccess": 0
}
],
"outputParameters": [
]
"outputParameters": []
}
}
}
15 changes: 10 additions & 5 deletions src/compas_timber/ghpython/components/CT_BeamDecompose/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class BeamDecompose(component):
SCREEN_SIZE = 10
RELATIVE_SIZE = 0

def RunScript(self, beam, show_frame, show_faces):
self.show_faces = show_faces if show_faces is not None else False
self.show_frame = show_frame if show_frame is not None else False
def RunScript(self, Beam, ShowFrame, ShowFaces):
self.show_faces = ShowFaces if ShowFaces is not None else False
self.show_frame = ShowFrame if ShowFrame is not None else False
self.frames = []
self.rhino_frames = []
self.scales = []
Expand All @@ -29,7 +29,7 @@ def RunScript(self, beam, show_frame, show_faces):
self.centerline = []
self.shapes = []

for b in beam:
for b in Beam:
self.frames.append(b.frame)
self.rhino_frames.append(frame_to_rhino_plane(b.frame))
self.scales.append(b.width + b.height)
Expand All @@ -39,7 +39,12 @@ def RunScript(self, beam, show_frame, show_faces):
self.height.append(b.height)
self.faces.append(b.faces)

return self.rhino_frames, self.centerline, self.shapes, self.width, self.height
Frame = self.rhino_frames
Centerline = self.centerline
Shapes = self.shapes
Width = self.width
Height = self.height
return Frame, Centerline, Shapes, Width, Height

def DrawViewportWires(self, arg):
if self.Locked:
Expand Down
Loading