Python Scripting to Orient Nested Tags in Revit

In my last post on nested tags I went into detail on how to connect and nest a label object within a family in such a way as to allow it to behave similarly to a tag while providing some benefits that, in my opinion, enhance usability beyond the default tagging method employed by most Revit users.

One of the chief disadvantages of this method, as I stated in the previous blog post, is that each family instance which uses this method must have its angle parameter manually updated to orient the label to the sheet view. I also said that I’d write a script that would automate this process. I’m a fan of Python coding and utilize an excellent add-in call RevitPythonShell, in my scripting.

The following script targets Revit 2015 and will require some adjustment to maintain functionality in Revit 2016:

from math import *

class OrientText(UI.IExternalCommand):
    def Execute(self):

        NestedTextElements = list(DB.FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ElectricalFixtures).WherePasses(DB.ElementParameterFilter(DB.SharedParameterApplicableRule("TEXT ANGLE"))))

        t.Start("Nested Text Orienting")

        for a in NestedTextElements:
            angleadd = float()
            X = a.FacingOrientation.X
            Y = a.FacingOrientation.Y

            if X >= 0 and Y >= 0:
                angleadd = radians(90)
            elif X = 0:
                angleadd = radians(90)
            elif X < 0 and Y = 0 and Y < 0:
                angleadd = radians(270)

            if X != 0:
                baseangle = atan(abs(Y)/abs(X))
                baseangle = radians(90)

            if a.FacingFlipped == True:
                if X < 0 and Y = 0 and Y >= 0:
                    anglesign = 1
                    anglesign = -1
                if X < 0 and Y = 0 and Y >= 0:
                    anglesign = -1
                    anglesign = 1

            textangle = a.GetParameters("TEXT ANGLE")[0]
            textangle.Set(anglesign * (baseangle - angleadd))

        return UI.Result.Succeeded

OT = OrientText()


Article Categories

Leave a Comment

Your email address will not be published.