Get active selection in view and filter by IsTagged- Error 'object has no attribute'

Keep getting an error- not sure there should be an error- is this a dynamo BUG?

I want to get all the active selected element sin the current view so I can tag tose selected elements - easy right? Totally missing something here…

Warning: AttributeError : 'FamilyInstance' object has no attribute 'IsTagged' ['  File "<string>", line 62, in <module>\n', '  File "<string>", line 29, in get_untagged_selected_elements\n', '  File "<string>", line 29, in <listcomp>\n']
def get_untagged_selected_elements():                       ##
    # Get the selected element IDs
    selectElemId=[]                                         ##INit list
    selectElemId = uidoc.Selection.GetElementIds()          ##Get element iDs of selected objects
    elems=[doc.GetElement(x) for x in  selectElemId]        ##Get elements based on IDs?
                                                            ##Might need to filter by elements in active view?
    elems=UnwrapElement(elems)                              ##Unwrap probably unnecessary...
    untagged_ids = [x for x in elems if not x.IsTagged]     ##IsTagged  <<ERROR HERE>> should be there but isn't?

    return untagged_ids

On paper it looks good. You shouldnt need to unwrap the elements once selected as theyre returned unwrapped already. Try using expanded code vs comrepehended code for the final statement and run it through a try/except and if statement instead to see if some elements might not have the IsTagged property maybe?

I selected a piece of specialty equipment that was tagged, which was the start of this. Does specialty equipment not have the .Is tagged. ?

@GavinCrump I used the def to return the elem[0].Is tagged and looked at the methods. Would be odd if a taggable element (specialty equipment) doesn’t have .is tagged extension. Maybe I should take another look in 2023 or attempt an API to see it it is available there.

Can anyone confirm specialty equipment lacks the istaggable?

Ive cross checkes the api docs and IsTagged doesnt appear to be a valid property in the Element class. Maybe try getting all tags in active view which you can get the tagged element from, then check if your elements occur in that list instead.

1 Like

Long way round but my only option! Thanks @GavinCrump

1 Like

The other option is the GetDependentElements method with an element filter for tags.

This would return any tag dependent on the element, so additional filtering is required.

Eg. Select a wall, the wall itself is not tagged but a door hosted on the wall is. This would return at least one tag

Example of Implementing an “IsTagged” method that is reusable:

1 Like