Fabrication - Changing Sheet Metal Material Thickness to Gauge

Hey guys, I am new to Dynamo and trying to get a script that will change Fabrication Part Material Thickness to it Gauge equivalent for our BOM’s. I have created the Project Parameter for “FP_Gauge” I want to use in the report. I have the script started and I am able to pull the Part Material into a list. I am trying to use the replace by condition node to change the values with an if and == node. The issue is that it wants to replace all values in the list with 24 not just the 0.0276 values. eventually I will be adding the other values in the 2 code blocks.

If value in list 1 = 0.0276 then replace that value with 24 and output 24 to “FP_Gauge” for those elements.

Hi and welcome to the forum!

Try this script instead.

W Number.ToString is IN[0]
“0.027” is IN[1]
“24” is IN[2]
The output is used for the "Element.SetParameterByName.

Script.dyn (7.6 KB)

Turning the values into a dictionary would likely be faster here as there would always be one test instead of up to N tests.

The keys would be the material thickness, the values would be the gauges. Build a list of each (wrap your code block entries in square brackets and replace the semi colons with commas) and use a Dictionary.ByKeysValues node accordingly.

Jacob, thanks for the help. I have changed to using a Dictionary as you suggested. I am having an issue with the results. Some of them are changing but most come out with a null value.

Its recognizing 0 & 0.0336 and replacing them with 0 & 22.
Its not recognizing any of the other entries.
0.0276 should be 24
0.0217 should be 26
0.1084 should be 12

Use the default nodes for this - https://dictionary.dynamobim.com/2/#/Dictionary/Create/ByKeysValues

I stepped back and tried looking at one element that was not getting the correct result from the dictionary. When I look at the Part Material Thickness of the element using the Element.Parameter node its show a value of 0.052 for Part Material Thickness. However when I use the GetParameterValuebyName node its showing a value of 0.0516.

Could this be the cause of my issue with the Dictionary Results? I am not sure why Revit is round this value when reading it in the Element.Parameters node.

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