Selection elements with Python

Hello everyone , i have an issue with python script to select obgect from projet
in the line code

selEls = uidoc.Selection.Elements

it work for Revit 2014 but don’t for 2016
some one can help me to replace this line with the new APi
Thx

Try this :slight_smile:

hey thanks for your asnwer , it dosent work , may be i do something wrong
can you took a look for this script , i download it from : http://dp-stuff.org/
it work for Revit 2014 but not for 2016 ,

http://dp-stuff.org/downloads/dpstuff/free/revitpython/createRoomPlanViews2014.txt

thx :slight_smile:

The code you have shown won’t work for several reasons and it would take time to debug which unfortunately I don’t have, however, it seems you are trying to create Views with a room or rooms. Have you looked at arch+lab’s website. @Konrad_Sobon has detailed quite thoroughly including code. This should point you in the right direction.

However, if you are trying to get object from document like you asked, the code above should work. Just be sure to add all the references to the “RevitAPI” and “RevitAPIUI”. These are essential. :slight_smile:

Hey Daniel
Thank you for your prompt answer , i’ll check @Konrad_Sobon post :wink:

@Daniel_Woodcock1
I am trying this pyton code and get an error on line 18

File “”, line 18, in
AttributeError: ‘UIDocument’ object has no attribute ‘GetElement’"

Any idea what my issue is? Below is a copy of the code I have.

import clr

clr.AddReference(“RevitAPIUI”)
from Autodesk.Revit.UI import *

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

sel = doc.Selection
obType = Selection.ObjectType.Element
ref = sel.PickObject(obType, “Select Element.”)
element = doc.GetElement(ref.ElementId)

Out = element

@Travis.Biddle

Yup, you have set doc = …ActiveUIDocument. Have a look above at how I have named my variables…

You can see that I am setting uidoc as active UI Document and doc as current DB Document. These are two different things within the API and variables are typically named as I have named them so the variable’s use is clear that one is for the UIDocument and one is for the DB Document (uidoc and doc respectively).

As for the error, GetElement(…) method belongs to the Document class, not the UIDocument class.

Hope this helps!