Hello, I have another API question. I am using Revit 2015 and Dynamo 0.9.2. How do I call a selected TextNote’s Leader’s TextNoteLeaderStyle to check if it is TextNoteLeaderStyles.LCS_TWO_SEG_LINE ? So far my script selects all TextNotes and applies the function but I want to only apply the function on TextNotes with a leader that has 2 segments.
My python script so far:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import math
# -------------------- Functions ------------------------
def vUnwrap(x): #Unwraps elements
elements = []
if hasattr(x, '__iter__'):
for i in x:
elements.append(UnwrapElement(i))
else:
return UnwrapElement(x)
return elements
def vLeaders(textNote):
textLoc = textNote.Coord
leaderArray = textNote.Leaders #Returns LeaderArray var
for leader in leaderArray: #Accesses Leader var
leaderEnd = leader.End
oldElbow = leader.Elbow
textNote.RemoveLeaders()
leaderStart = XYZ(textLoc.X,oldElbow.Y,textLoc.Z)
yDist = leaderStart.Y - leaderEnd.Y
if leaderStart.Y >= leaderEnd.Y and leaderStart.X <= leaderEnd.X:
elbowX = leaderEnd.X - yDist
elif leaderStart.Y > leaderEnd.Y and leaderStart.X > leaderEnd.X:
elbowX = leaderEnd.X + yDist
elif leaderStart.Y < leaderEnd.Y and leaderStart.X > leaderEnd.X:
elbowX = leaderEnd.X - yDist
else:
elbowX = leaderEnd.X + yDist
elbowY = leaderStart.Y
leaderElbow = XYZ(elbowX,elbowY,leaderStart.Z)
newLeader = textNote.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R)
newLeader.End = leaderEnd
newLeader.Elbow = leaderElbow
return textNote
"""def getViews(textNote, doc):
Id = textNote.OwnerViewId
view = doc.GetElement(Id)
return view"""
# --------------------- Main ---------------------------
doc = DocumentManager.Instance.CurrentDBDocument
textNotes = IN[0]
#textType = textNote.TextNoteType
#textSize = textType.GetParameters('Text Size')
tnArray = []
for j in textNotes:
TransactionManager.Instance.EnsureInTransaction(doc)
textNote = vUnwrap(j)
newText = vLeaders(textNote)
TransactionManager.Instance.TransactionTaskDone()
tnArray.append(newText.ToDSType(False))
OUT = tnArray
Also if anyone could point me in the right direction on why when I apply this script on multiple TextNotes, only the final textnote in the list shows the updates in the model, but when re-opening or moving the rest of the textnotes, they show the correct update. I am thinking maybe it has to do with transactions?