Adding Lining & Insulation to Fabrication Duct Parts

Hello

I am trying to apply lining and or insulation to fabrication duct parts (straight/oval/round). I have zero experience with coding. I tried to search online and copilot suggested a few different codes. I figured I’d start out with AI generated codes. I tried all of them and, as I figured, they did not work. The main problem with Revit is I cannot add the lining/insulation to fab duct parts. My settings I create in Fabrication CADMEP does not get carried over to Revit. I have spent much time but no viable solution.

I tried Dynamo, but there were no topics on fabrication ductwork insulation. And when I found something close, it would not work. I don’t normally post anything and just joined pyRevit forums a few minutes ago. I don’t know if I should paste the “copilot generated code” here or if there is an attach option somewhere.

On top of that I have also spent many hours that turned into days trying to create tags for radius and throats of ducts. I tried parameters, and Dynamo, but no luck with that either. I have turned to pyRevit in hopes to achieve all my goals with a proper functioning Revit setup for Fabrication Duct.

I should mention that I would really need the option to add acoustical lining of any thickness, and insulation of any thickness both together and individually on selected ducts.

Can someone please help me?

Here is the code form AI below

-- coding: utf-8 --

“”"
Interactive Apply Lining to Selected Fabrication Ducts in Revit
Author: Your Name
Description:
Prompts the user to select a lining material and thickness,
then applies them to selected fabrication duct elements.
“”"

from Autodesk.Revit.DB import (
FilteredElementCollector,
Transaction,
BuiltInCategory
)
from Autodesk.Revit.DB.Fabrication import FabricationPart
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.Exceptions import InvalidOperationException

from pyrevit import revit, forms

doc = revit.doc

---------------- HELPER FUNCTIONS ----------------

def get_selected_fabrication_ducts():
“”“Return selected fabrication ducts, or prompt user if none selected.”“”
selection_ids = revit.get_selection_ids()
if not selection_ids:
forms.alert(“Please select one or more fabrication ducts.”, exitscript=True)
ducts =
for el_id in selection_ids:
el = doc.GetElement(el_id)
if isinstance(el, FabricationPart) and el.Category.Id.IntegerValue == int(BuiltInCategory.OST_FabricationDuctwork):
ducts.append(el)
if not ducts:
forms.alert(“No fabrication ducts found in selection.”, exitscript=True)
return ducts

def get_all_material_names():
“”“Return a sorted list of all material names in the project.”“”
mats = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Materials).ToElements()
return sorted([m.Name for m in mats])

def get_material_by_name(name):
“”“Find a material by name in the project.”“”
mats = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Materials).ToElements()
for mat in mats:
if mat.Name.lower() == name.lower():
return mat
return None

def apply_lining(ducts, material, thickness_mm):
“”“Apply lining material and thickness to ducts.”“”
with Transaction(doc, “Apply Lining to Fabrication Ducts”) as t:
t.Start()
for duct in ducts:
try:
mat_param = duct.LookupParameter(“Lining Material”)
thick_param = duct.LookupParameter(“Lining Thickness”)
if mat_param and material:
mat_param.Set(material.Id)
if thick_param:

Convert mm to feet (Revit internal units)

thickness_ft = thickness_mm / 304.8
thick_param.Set(thickness_ft)
except Exception as e:
print(“Error applying lining to {}: {}”.format(duct.Id, e))
t.Commit()

---------------- MAIN SCRIPT ----------------

try:
ducts = get_selected_fabrication_ducts()

# Prompt user for material
material_names = get_all_material_names()
chosen_material_name = forms.select_from_list(
    material_names,
    title="Select Lining Material",
    multiselect=False
)
if not chosen_material_name:
    forms.alert("No material selected. Script cancelled.", exitscript=True)

material = get_material_by_name(chosen_material_name)
if not material:
    forms.alert("Material '{}' not found in project.".format(chosen_material_name), exitscript=True)

# Prompt user for thickness
thickness_mm = forms.ask_for_number(
    prompt="Enter lining thickness (mm):",
    default=25,
    min=0
)
if thickness_mm is None:
    forms.alert("No thickness entered. Script cancelled.", exitscript=True)

# Apply lining
apply_lining(ducts, material, thickness_mm)

TaskDialog.Show("pyRevit", "Lining applied successfully to {} ducts.".format(len(ducts)))

except InvalidOperationException:
forms.alert(“This command must be run in a valid Revit project view.”)