Last active
December 15, 2023 09:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
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
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