# BIM Era / native Revit API teaching excerpts # These snippets are NOT a standalone project generator. # Run only in a supported Revit Python host with a valid API context. # Resolve doc, levels, active symbols, types, profiles and route collections first. # Coordinates/dimensions are internal units; convert metres explicitly. # Use project-specific validation, exception handling and model backups. # Doors, glazing, foundations, terminals and plumbing fixtures shown in the # browser scene need additional family preparation and placement operations. # Engineering sizing, connectors, fittings and system validation are omitted. from Autodesk.Revit.DB import ( Transaction, Floor, Wall, BuiltInParameter ) from Autodesk.Revit.DB.Structure import StructuralType from Autodesk.Revit.DB.Mechanical import Duct from Autodesk.Revit.DB.Electrical import CableTray from Autodesk.Revit.DB.Plumbing import Pipe # 01 / ARCHITECTURE — prepared model context # All coordinates and dimensions are internal units. with Transaction(doc, "Create architecture") as tx: tx.Start() for level in levels: Floor.Create(doc, profiles[level.Id], floor_type.Id, level.Id) for baseline in wall_lines[level.Id]: Wall.Create(doc, baseline, wall_type.Id, level.Id, storey_height, 0.0, False, False) tx.Commit() # 02 / STRUCTURE — loaded, active symbols with Transaction(doc, "Place structural grid") as tx: tx.Start() for level in levels: for point in column_points[level.Id]: doc.Create.NewFamilyInstance( point, column_symbol, level, StructuralType.Column) for axis in beam_lines[level.Id]: doc.Create.NewFamilyInstance( axis, beam_symbol, level, StructuralType.Beam) tx.Commit() # 03 / MECHANICAL — validated HVAC types with Transaction(doc, "Route supply air") as tx: tx.Start() for level in levels: for start, end in duct_routes[level.Id]: duct = Duct.Create( doc, hvac_system.Id, duct_type.Id, level.Id, start, end) duct.get_Parameter( BuiltInParameter.RBS_CURVE_WIDTH_PARAM ).Set(duct_width) tx.Commit() # 04 / ELECTRICAL — tray routes and lights with Transaction(doc, "Place electrical routes") as tx: tx.Start() for level in levels: for start, end in tray_routes[level.Id]: CableTray.Create(doc, tray_type.Id, start, end, level.Id) for point in lighting_points[level.Id]: doc.Create.NewFamilyInstance( point, light_symbol, level, StructuralType.NonStructural) tx.Commit() # 05 / PLUMBING — validated piping types with Transaction(doc, "Route plumbing") as tx: tx.Start() for level in levels: for start, end in pipe_routes[level.Id]: Pipe.Create( doc, piping_system.Id, pipe_type.Id, level.Id, start, end) tx.Commit() # Review model geometry, connectors and systems. # Fittings and engineering checks are separate steps.