Change the name of the Project location in Dynamo

Hi all member,

Please help me, How can change the name of the Project location use Dynamo.

Thank you!

Resolved :innocent:

import clr
clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)
from Autodesk.Revit.DB import *
clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference(‘RevitServices’)
from RevitServices.Persistence import DocumentManager as DM # Document manager
from RevitServices.Transactions import TransactionManager as TM # Transaction manager
NewName = IN[0]
doc = DM.Instance.CurrentDBDocument
TM.Instance.EnsureInTransaction(doc)
projloc = doc.ActiveProjectLocation
NEW = projloc.Name = NewName
TM.Instance.TransactionTaskDone()
OUT = NewName

2 Likes

Thank boss!

Hi @chuongmep,

Thanks for sharing this code. I am testing it but I get this error:

I just pasted your code on a Python node. Is it there anything else I have to do?

Thanks in advance!

Try, i thinks that is a problem with dynamo version higher " vs '
import clr
clr.AddReference(“RevitAPI”)
clr.AddReference(“RevitAPIUI”)
from Autodesk.Revit.DB import *
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference(“RevitServices”)
from RevitServices.Persistence import
DocumentManager as DM # Document manager
from RevitServices.Transactions import TransactionManager as TM # Transaction manager
NewName = IN[0]
doc = DM.Instance.CurrentDBDocument
TM.Instance.EnsureInTransaction(doc)
projloc = doc.ActiveProjectLocation
NEW = projloc.Name = NewName
TM.Instance.TransactionTaskDone()
OUT = NewName

Hi @chuongmep,
Thanks for coming back. I finally managed to make it work! It is really useful. The issue was the type of token, for some reason Dynamo 2.0.2 does not recognise ´, ’, “ or ”, but yes " or '. Maybe it is a matter of keyobard language or symbols.

By the way, now that the rename current Project Location works, I am wondering if there is a way to rename multiple Project Locations of current document. Or even better from linked documents. Sorry, I am pretty new with Python…

Thanks!

Hi @chuongmep,

I managed to change name to multiple locations. Please see below. Last step that I would like to achive is to do it from a Host model to several linked instances. If you have any idea it would be appreciated. Thanks for the support!

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Do some actions in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

ProjectLocations = UnwrapElement(IN[0])
NewCurrentLocationName = IN[1]
NewLocationNames = IN[2]

CurrentLocationElement = list()
NamedElementsList = list()
ExceptList = list()

CurrentLocationID = doc.ActiveProjectLocation.Id

for ProjectLocation, NewName in zip(ProjectLocations, NewLocationNames):
	try:
		if ProjectLocation.Id == CurrentLocationID:
			ProjectLocation.Name = NewCurrentLocationName
			CurrentLocationElement.append(ProjectLocation)		
		else:
			ProjectLocation.Name = NewName
			NamedElementsList.append(ProjectLocation)
	except:
		ExceptList.append("Error"+ProjectLocation.Id)
		
# Finish Transaction
TransactionManager.Instance.TransactionTaskDone()

# Final Output
OUT = [CurrentLocationElement, NamedElementsList, ExceptList]

Right ?


Test.dyn (13.0 KB)

1 Like

what are the package of location.byname