Skip to content

Instantly share code, notes, and snippets.

@truevis
Last active December 15, 2023 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save truevis/e7263120e43b83e3ff4505483e1e6dfa to your computer and use it in GitHub Desktop.
Save truevis/e7263120e43b83e3ff4505483e1e6dfa to your computer and use it in GitHub Desktop.
A Python script for Revit, facilitating the renaming of an assembly element. It employs Revit API and Dynamo libraries, and handles transactions for renaming.
# Rename Revit Assembly
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
assy = UnwrapElement(IN[0])
new_name = IN[1]
TransactionManager.Instance.EnsureInTransaction(doc)
assy.AssemblyTypeName = new_name
TransactionManager.Instance.TransactionTaskDone()
OUT = (new_name, assy)
@truevis
Copy link
Author

truevis commented Apr 8, 2021

To use:
insert a Transaction.End Node (to Start a new Transaction)
or use
TransactionManager.Instance.ForceCloseTransaction()

Discussion at https://forum.dynamobim.com/t/rename-newly-created-assembly/62715

@truevis
Copy link
Author

truevis commented Aug 16, 2023

This script renames a Revit assembly element to a new given name.

It imports necessary RevitAPI and Dynamo libraries. Gets the active document, UI application, and UIDocument.

An assembly element (IN[0]) and new name (IN[1]) are inputs.

It starts a transaction, sets the AssemblyTypeName property to the new name input, and closes the transaction.

The renamed assembly element is output, along with its new name.

So in summary, this takes an assembly element and renames it within a Revit transaction using the RevitAPI. The renamed element is output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment