Skip to content

Commit

Permalink
format lint test... undefined name 'ghenv'
Browse files Browse the repository at this point in the history
  • Loading branch information
obucklin committed Feb 15, 2024
1 parent ec928cc commit c06206d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class BeamDecompose(component):

RED = Color.FromArgb(255, 255, 100, 100)
GREEN = Color.FromArgb(200, 50, 220, 100)
BLUE = Color.FromArgb(200, 50, 150, 255)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def RunScript(self, Cutoff):
args = {}
if Cutoff:
args["cutoff"] = Cutoff
options = JointOptions(FrenchRidgeLapJoint, ['top_beam','bottom_beam'] **args)
options = JointOptions(FrenchRidgeLapJoint, ["top_beam", "bottom_beam"] ** args)

return options
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def RunScript(self, flip_lap_side, cut_plane_bias):
if cut_plane_bias:
args["cut_plane_bias"] = cut_plane_bias

options = JointOptions(LHalfLapJoint, ["top_beam", "bottom_beam"],**args)
options = JointOptions(LHalfLapJoint, ["top_beam", "bottom_beam"], **args)

return options
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def RunScript(self, Cutoff):
args = {}
if Cutoff:
args["cutoff"] = Cutoff
options = JointOptions(LMiterJoint, ["first_beam", "second_beam"],**args)
options = JointOptions(LMiterJoint, ["first_beam", "second_beam"], **args)

return options
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@

class NullJointComponent(component):
def RunScript(self):

options = JointOptions(NullJoint, ["first_beam", "second_beam"], **{})
return options
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def RunScript(self, flip_lap_side, cut_plane_bias):
args["flip_lap_side"] = flip_lap_side
if cut_plane_bias:
args["cut_plane_bias"] = cut_plane_bias
options = JointOptions(THalfLapJoint, ["top_beam", "bottom_beam"],**args)
options = JointOptions(THalfLapJoint, ["top_beam", "bottom_beam"], **args)

return options
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from compas_timber.ghpython import CategoryRule


def AddParam(name, IO, list = True):
assert IO in ('Output', 'Input')
params = [param.NickName for param in getattr(ghenv.Component.Params,IO)]
def AddParam(name, IO, list=True):
assert IO in ("Output", "Input")
params = [param.NickName for param in getattr(ghenv.Component.Params, IO)]
if name not in params:
param = Grasshopper.Kernel.Parameters.Param_GenericObject()
param.NickName = name + " category"
Expand All @@ -17,40 +17,40 @@ def AddParam(name, IO, list = True):
param.Access = Grasshopper.Kernel.GH_ParamAccess.item
param.Optional = True
index = getattr(ghenv.Component.Params, IO).Count
registers = dict(Input = 'RegisterInputParam'
,Output = 'RegisterOutputParam'
)
getattr(ghenv.Component.Params,registers[IO])(param, index)
registers = dict(Input="RegisterInputParam", Output="RegisterOutputParam")
getattr(ghenv.Component.Params, registers[IO])(param, index)
ghenv.Component.Params.OnParametersChanged()
return param


class DirectJointRule(component):
def __init__(self):
self.joint_type = None

def ClearParams(self):
while len(ghenv.Component.Params.Input)>1:
ghenv.Component.Params.UnregisterInputParameter(ghenv.Component.Params.Input[len(ghenv.Component.Params.Input)-1])
while len(ghenv.Component.Params.Input) > 1:
ghenv.Component.Params.UnregisterInputParameter(
ghenv.Component.Params.Input[len(ghenv.Component.Params.Input) - 1]
)
ghenv.Component.Params.OnParametersChanged()
ghenv.Component.ExpireSolution(True)


def RunScript(self, JointOptions, *args):
if not JointOptions: #if no JointOptions is input
if not JointOptions: # if no JointOptions is input
print("no joint")
self.ClearParams()
self.joint_type = None
return

if JointOptions.type != self.joint_type: # if JointOptions changes
if JointOptions.type != self.joint_type: # if JointOptions changes
if len(JointOptions.beam_names) != 2:
self.AddRuntimeMessage(Error, "Component currently only supports joint types with 2 beams.")
self.ClearParams()
self.joint_type = JointOptions.type
for name in JointOptions.beam_names:
AddParam(name, "Input")

if len(ghenv.Component.Params.Input) != 3: # something went wrong and the number of input parameters is wrong
if len(ghenv.Component.Params.Input) != 3: # something went wrong and the number of input parameters is wrong
self.AddRuntimeMessage(Warning, "Input parameter error.")
return

Expand All @@ -59,12 +59,15 @@ def RunScript(self, JointOptions, *args):
return
categories = []
create_rule = True
for i in range(len(ghenv.Component.Params.Input)-1):
for i in range(len(ghenv.Component.Params.Input) - 1):
if not args[i]:
self.AddRuntimeMessage(Warning, "Input parameter {} {} failed to collect data.".format(JointOptions.beam_names[i], 'categories'))
self.AddRuntimeMessage(
Warning,
"Input parameter {} {} failed to collect data.".format(JointOptions.beam_names[i], "categories"),
)
create_rule = False
else:
categories.append(args[i])
categories.append(args[i])

if create_rule:
return CategoryRule(JointOptions.type, categories[0], categories[1], **JointOptions.kwargs)
48 changes: 26 additions & 22 deletions src/compas_timber/ghpython/components/CT_Joint_Rule_Direct/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from compas_timber.ghpython import DirectRule


def AddParam(name, IO, list = True):
assert IO in ('Output', 'Input')
params = [param.NickName for param in getattr(ghenv.Component.Params,IO)]
def AddParam(name, IO, list=True):
assert IO in ("Output", "Input")
params = [param.NickName for param in getattr(ghenv.Component.Params, IO)]
if name not in params:
param = Grasshopper.Kernel.Parameters.Param_GenericObject()
param.NickName = name
Expand All @@ -19,33 +19,30 @@ def AddParam(name, IO, list = True):
param.Access = Grasshopper.Kernel.GH_ParamAccess.list
param.Optional = True
index = getattr(ghenv.Component.Params, IO).Count
registers = dict(Input = 'RegisterInputParam'
,Output = 'RegisterOutputParam'
)
getattr(ghenv.Component.Params,registers[IO])(param, index)
registers = dict(Input="RegisterInputParam", Output="RegisterOutputParam")
getattr(ghenv.Component.Params, registers[IO])(param, index)
ghenv.Component.Params.OnParametersChanged()
return param




class DirectJointRule(component):
def __init__(self):
self.joint_type = None

def ClearParams(self):
while len(ghenv.Component.Params.Input)>1:
ghenv.Component.Params.UnregisterInputParameter(ghenv.Component.Params.Input[len(ghenv.Component.Params.Input)-1])
while len(ghenv.Component.Params.Input) > 1:
ghenv.Component.Params.UnregisterInputParameter(
ghenv.Component.Params.Input[len(ghenv.Component.Params.Input) - 1]
)
ghenv.Component.Params.OnParametersChanged()


def RunScript(self, JointOptions, *args):
if not JointOptions: #if no JointOptions is input
def RunScript(self, JointOptions, *args):
if not JointOptions: # if no JointOptions is input
self.ClearParams()
self.joint_type = None
return

if JointOptions.type != self.joint_type: # if JointOptions changes
if JointOptions.type != self.joint_type: # if JointOptions changes
if len(JointOptions.beam_names) != 2:
self.AddRuntimeMessage(Error, "Component currently only supports joint types with 2 beams.")
self.ClearParams()
Expand All @@ -63,19 +60,26 @@ def RunScript(self, JointOptions, *args):

beams = []
create_rule = True
for i in range(len(ghenv.Component.Params.Input)-1):
for i in range(len(ghenv.Component.Params.Input) - 1):
if not args[i]:
self.AddRuntimeMessage(Warning, "Input parameter {} failed to collect data.".format(JointOptions.beam_names[i]))
self.AddRuntimeMessage(
Warning, "Input parameter {} failed to collect data.".format(JointOptions.beam_names[i])
)
create_rule = False
else:
arg_beams= args[i]
if not isinstance(arg_beams, list):
arg_beams = [arg_beams]
beams.append(arg_beams)
arg_beams = args[i]
if not isinstance(arg_beams, list):
arg_beams = [arg_beams]
beams.append(arg_beams)

if create_rule:
if len(beams[0]) != len(beams[1]):
self.AddRuntimeMessage(Error, "Number of items in {} and {} must match!".format(JointOptions.beam_names[0], JointOptions.beam_names[1]))
self.AddRuntimeMessage(
Error,
"Number of items in {} and {} must match!".format(
JointOptions.beam_names[0], JointOptions.beam_names[1]
),
)
return
Rules = []
for main, secondary in zip(beams[0], beams[1]):
Expand Down

0 comments on commit c06206d

Please sign in to comment.