Tag Walls through API

Tag Walls through API

dgoff96
Enthusiast Enthusiast
684 Views
2 Replies
Message 1 of 3

Tag Walls through API

dgoff96
Enthusiast
Enthusiast

I have been trying this over and over again, and can’t seem to get it to work. I am working on a tool that should add wall tags to certain walls, however, I’m having trouble with the IndependentTag.Create() method. Below is my code (in python). I recycled this code from another tool that tags different element types and works just fine, so I’m pretty sure the syntax is correct:

 

families = DB.FilteredElementCollector(doc).OfCategory(DB.BuiltInCategory.OST_WallTags).OfClass(DB.FamilySymbol).ToElements()
    for fam in families:
        if fam.Family.Name == "MyTagName":
            tag = fam
            break
tag = DB.IndependentTag.Create(doc, tag.Id, view.Id, DB.Reference(wall), True, DB.TagOrientation.Horizontal, mid_point)

 

I keep getting this error: 

Exception: The ElementId symId does not correspond to a FamilySymbol. I have checked that the "tag" element that is returned from my for loop is in fact a Family Symbol, so I'm not sure what I am doing wrong here. Any help would be greatly appreciated!
0 Likes
Accepted solutions (1)
685 Views
2 Replies
Replies (2)
Message 2 of 3

dgoff96
Enthusiast
Enthusiast
Accepted solution

I wound up solving this myself. Somehow, the tag.Id was getting changed somewhere along the way (not sure how as I couldn't find anywhere in my loop where it would have been changed). Anyway, I just made sure to get the Id explicitly when I search for the correct Family Symbol. Then it worked just fine.

0 Likes
Message 3 of 3

ctm_mka
Collaborator
Collaborator

my guess would be the break in your for loop was causing tag to be nullified, not sure if you can do this in python, but c# i would use continue vs break for that reason.

0 Likes