Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SetElementIds() method does not highlight selected objects

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Anonymous
1990 Views, 2 Replies

SetElementIds() method does not highlight selected objects

Hello,

 

As the name suggests, I am trying to use the revit API to select specific elements which pass my filter. I am using the Selection.SetElementIds(ids) method to select the objects for the user to then isolate themselves or do further work.

 

The function appears to be working initially, as the elements are selected. However, there is no highlighting of the objects and if I were to click the isolate element button in the active view, they are not picked up by the command (I assume these two problems are linked). 

 

Does anyone know why this is happening? I did a quick search through the forums and the only answer I could find was quite vague and had to do with "dockable panes". I am unaware of a workaround, any help would be greatly appreciated.

 

I have tested this is in both Revit 2017 and 2018 with similar results

 

Here is the code, I am implementing this using python and pyrevit:

 

# Get Document
doc = __revit__.ActiveUIDocument.Document
active_view = doc.ActiveView
uidoc = UI.UIDocument(doc)

#Set up lists
in_place = []
ids = []

families = DB.FilteredElementCollector(doc).OfClass(DB.Family).ToElements()

for family in families:
    if family.IsInPlace == True:
        ids.append(family.Id)

#Convert list to ICollection
ele_ids = List[DB.ElementId](ids)

#Select + Isolate elements        
sel = uidoc.Selection.SetElementIds(ele_ids)
uidoc.RefreshActiveView()

 

2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Update: I have done some fiddling around on my own and have managed to get the SetElementIds() method to work with highlighting when collecting Walls instead of in place families, which is what I was originally trying to isolate. Why would in place families not work but a typical element such as walls be highlighted?

Message 3 of 3
Anonymous
in reply to: Anonymous

"""Selects all in-place models in document"""

from pyrevit import revit, DB, UI
from pyrevit import forms
from pyrevit import script
from pyrevit import clr

clr.AddReference("System")
clr.AddReference("System.Core")
from System.Collections.Generic import List
from System.Collections.Generic import HashSet


__author__ = 'Kai Zhu'
__doc__ = 'This button finds all families within the document and highlights all instances which have been modelled in place'


logger = script.get_logger()


# Get Document
doc = __revit__.ActiveUIDocument.Document
active_view = doc.ActiveView
uidoc = UI.UIDocument(doc)

#Set up lists
in_place = []
instance_symbol_ids = []
family_symbol_ids = []

#Get all families in doc
families = DB.FilteredElementCollector(doc).OfClass(DB.Family).WhereElementIsNotElementType().ToElements()

#Loop through families and test if they are in-place
for family in families:
    if family.IsInPlace == True:
        family_symbol_ids.append(family.GetFamilySymbolIds())
        in_place.append(family)



#Collect all family instances 
family_instances = DB.FilteredElementCollector(doc).OfClass(DB.FamilyInstance).ToElements()

#Set up list to select family instances
in_place_instance = []

#Loop through instances and test if their type matches in-place set
for instance in family_instances:
        instance_symbol_ids.append(instance.GetTypeId())
        for symbol_set in family_symbol_ids:
                if symbol_set.Contains(instance.GetTypeId()):
                        in_place_instance.append(instance.Id)


#Convert list to ICollection
ele_ids = List[DB.ElementId](in_place_instance)

#Select instances to isolate
sel = uidoc.Selection.SetElementIds(ele_ids)

#Create transaction
t = DB.Transaction(revit.doc, "Isolate Element")
t.Start()

#Temporarily isolate in-place family instances
active_view.IsolateElementsTemporary(ele_ids)

t.Commit()

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community