I’d like to change level names to uppercase in python.
I can do in dynamo like this:
In python I can get the list of Levels in uppercase (string):
Lvls=UnwrapElement(IN[0])
uppername=[i.Name.upper() for i in Lvls]
But I can’t find an equivalent method to Element.SetParameterByName if there’s one.
I looked below but I’m stuck! Any help is much appreciated.
http://www.revitapidocs.com/2016/090eeff2-3336-846d-d1da-a477090ccfb8.htm
A level is a finite horizontal plane that acts as a reference for level-hosted elements, such as walls, roofs, floors, and ceilings.
Get the parameter with
nameParam = lvls.get_Parameter(BuiltinParameter.... )
And then set the value with
nameParam.Set(... )
You can look up the built-in parameter enum here: http://www.revitapidocs.com/2017/fb011c91-be7e-f737-28c7-3f1e1917a0e0.htm
@Einar_Raknes . Thank you for your reply.
I tried :
nameParam=lvls.get_Parameter(BuiltInParameter.LEVEL_NAME.AsElementId())
and I get this error:
I also tried:
nameParam=[i.get_Parameter(BuiltInParameter.LEVEL_NAME) for i in lvls]
but I get a list of null
Can you post the complete code? Mark it and press </>
to get a nice formatting.
You should try to get it work with one level first, and then use list compreshension or for loops to handle a list of levels later.
Thanks @Einar_Raknes . I also tried with one Level.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
lvls=UnwrapElement(IN[0])
nameParam=[i.get_Parameter(BuiltInParameter.LEVEL_NAME) for i in lvls]
justonelevel=lvls[0].get_Parameter(BuiltInParameter.LEVEL_NAME)
OUT = nameParam,justonelevel
Hi, try this one:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
lvls=UnwrapElement(IN[0])
#lvls=IN[0]
nameParam=[i.Name for i in lvls]
upperName = [i.upper() for i in nameParam]
TransactionManager.Instance.EnsureInTransaction(doc)
set = [i.get_Parameter("Name").Set(j) for i,j in zip(lvls,upperName)]
TransactionManager.Instance.TransactionTaskDone()
OUT = "Success"
2 Likes
Looks like the Name paramter is writable, so the following will also work for names. But for other parameters use the method above.
for i in lvls:
i.Name = i.Name.upper()
The whole code:
import clr
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
lvls=UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
OUT = []
for i in lvls:
i.Name = i.Name.upper()
OUT.append(i.Name)
TransactionManager.Instance.TransactionTaskDone()
2 Likes
I got an error on line 28
Could you post whole graph?
Are you using a English version of Revit? If not you should use the BultInPrameter.
wow! Thanks! That worked.
I’d tried that with list comprehension but I must have done something wrong.
If I change the for loop with the following:
OUT =[i.Name=i.Name.upper() for i in lvls]
I get this error:
Can it be done with List comprehension?
Short answer is no, but it’s probalby possible somehow. You can for instance create a function and call it in the list comprehension. I recommend you to stick with the for loop.
1 Like