Hi Valfar, I have created a graph with similar functionality which you may also find useful. It is admittedly messy as I only used it for testing and implemented only a small part of it in a different project.
The way I have implemented the matching of decimal inches to corresponding gauge is that it identifies the closest match, so it should still match 0.052 to 16 ga. I can’t remember exactly where I got the values for each gauge and associated decimal inch value, so you may have to change them but it shouldn’t be too difficult. Just remember to have an equal number of values in gauges_galv_keys
and gauges_galv_vals
.
MEP Fabrication Ductwork Gauge.dyn (14.2 KB)
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
def get_gauge(thk, mat):
# Thickness thk in decimal inches
# Material name mat (aluminum or galv steel)
mat_lower = mat.lower()
if 'galv' in mat_lower:
gauges_dict = gauges_galv
keys = gauges_galv_keys
elif 'alum' in mat_lower:
gauges_dict = gauges_alum
keys = gauges_alum_keys
else:
return ''
for i in range(1, len(keys)):
key_previous = keys[i-1]
key_current = keys[i]
float_previous = float(key_previous)
float_current = float(key_current)
score_previous = abs(float_previous - thk)
score_current = abs(float_current - thk)
# If thickness does not match current float better
# than previous float, return previous gauge
if score_current > score_previous:
return gauges_dict[key_previous]
return '' # TODO: Will not account for last item in dict
doc = DocumentManager.Instance.CurrentDBDocument
config = FabricationConfiguration.GetFabricationConfiguration(doc)
elements_in = IN[0]
if not isinstance(elements_in, list):
elements = [UnwrapElement(elements_in)]
else:
elements = UnwrapElement(elements_in)
# Galvanized steel sheet metal
# Material thickness in inches
gauges_galv_keys = ['0.1681',
'0.1532',
'0.1382',
'0.1233',
'0.1084',
'0.0785',
'0.0635',
'0.0516',
'0.0396',
'0.0336',
'0.0276',
'0.0217',
'0.0187',
'0.0157']
# Corresponding gauge
gauges_galv_vals = ['8 ga',
'9 ga',
'10 ga',
'11 ga',
'12 ga',
'14 ga',
'16 ga',
'18 ga',
'20 ga',
'22 ga',
'24 ga',
'26 ga',
'28 ga',
'30 ga']
gauges_galv = dict(zip(gauges_galv_keys, gauges_galv_vals))
# Aluminum sheet metal
gauges_alum_keys = ['0.1443',
'0.1285',
'0.1144',
'0.1019',
'0.09074',
'0.08081',
'0.06408',
'0.05082',
'0.04030',
'0.03196',
'0.02535',
'0.02010',
'0.01594',
'0.01264',
'0.01003']
gauges_alum_vals = ['7 ga',
'8 ga',
'9 ga',
'10 ga',
'11 ga',
'12 ga',
'14 ga',
'16 ga',
'18 ga',
'20 ga',
'22 ga',
'24 ga',
'26 ga',
'28 ga',
'30 ga']
gauges_alum = dict(zip(gauges_alum_keys, gauges_alum_vals))
gauges = []
dut_in = DisplayUnitType.DUT_FRACTIONAL_INCHES
ops = FormatOptions(dut_in)
ops.UseDefault = False # Enable custom formatting
ops.SuppressLeadingZeros = False
val_ops = FormatValueOptions()
val_ops.SetFormatOptions(ops)
for element in elements:
material = config.GetMaterialName(element.Material)
thk_ft = element.MaterialThickness
thk_in = UnitUtils.ConvertFromInternalUnits(thk_ft, dut_in)
thickness_format = UnitFormatUtils.Format(Units(UnitSystem.Imperial),
UnitType.UT_Length,
thk_ft,
True,
False,
val_ops)
gauges.append(get_gauge(thk_in, material))
OUT = elements, gauges