I have element ids in python - I would now like to SetParameterByName

Hi all,

I am working on a script to change detail numbers of views on sheets. I’m sick of rejigging them and feels like I’m wasting my time doing a repetitive task… So perfect for a little script. I’ve been trying to learn a bit of python so would like to try do it using Pythonically (purely for practice / learning purposes)

So i’ve got to picking the objects (I intend to add a filter for views later … )
enumerate (starting at 1)

I’m now a little stuck as I have the element ids. However when I try to SetParameterByName I’m getting an exception, “Element Id has no attribute SetParameterByName” - this makes sense i have an id not an object.

I’m sure its a super easy step, but how to i get the object from the id to then change the parameter?

Also before getting the ids i was getting an Autodesk.Revit.DB.Reference , i thought getting the ids would be a good idea, should i have got something else?

Many thanks

J-P

(also i realise i’ve imported way too much - i just wrote them all down one day and copy them in to begin with - not ideal, but convenient)

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

clr.AddReference("RevitAPI")
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.DB import * 

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager 
from RevitServices.Transactions import TransactionManager
from Autodesk.Revit.UI.Selection import ObjectType

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


picked = uidoc.Selection.PickObjects(ObjectType.Element)
objects = [ el.ElementId for el in picked ]

objects = list(enumerate(objects,1))

for object in objects: 
        object[1].SetParameterByName("Detail Number", object[0])

OUT = objects

I think you can get the Element directly from the reference by doc.GetElement(el )

1 Like

Thank you Einar