Hello. I have been trying to expand my programming knowledge by using Python nodes to access RevitAPI within Dynamo. I am currently stuck on how to access the location of the point circled in red in the picture below.
I have been looking into Revit’s API extensively and cannot find any reference to that point. I have also been trying to use the height of the total textnote and just halving it but to no avail. It has no boundingbox attribute.
The goal is to redo all the leaders on selected textnotes so that the angle at the elbow is always 135 degrees. I am almost done except that the line between the elbow and TextNote is not horizontal. The python script is messy and has unused variables but I can clean it up after it works. Any info would be greatly appreciated!
Script:
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Plumbing import *
clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import math
#The inputs to this node will be stored as a list in the IN variables.
doc = DocumentManager.Instance.CurrentDBDocument
textNote = UnwrapElement(IN[0])
textType = textNote.TextNoteType
textSize = textType.GetParameters('Text Size')
TransactionManager.Instance.EnsureInTransaction(doc)
textLoc = textNote.Coord
textW = textNote.Width
textH = textNote.Height
textX = textLoc.X
textY = textLoc.Y
leaderStart = XYZ(textX,textY,textLoc.Z)
leader = textNote.Leaders
leaderEnd = []
for i in leader:
leaderEnd = i.End
j = leaderStart.Y-leaderEnd.Y
elbowX = leaderEnd.X-j
elbowY = leaderStart.Y
leaderElbow = XYZ(elbowX,elbowY,leaderStart.Z)
textNote.RemoveLeaders()
newLeader = textNote.AddLeader(TextNoteLeaderTypes.TNLT_STRAIGHT_R)
newLeader.End = leaderEnd
newLeader.Elbow = leaderElbow
TransactionManager.Instance.TransactionTaskDone()
OUT = 0
After a little searching it seems like you can get the leader points pretty easily.
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
textNote = UnwrapElement(IN[0])
output = []
leaders = textNote.GetLeaders()
for leader in leaders:
out = []
out.append(leader.Anchor.ToPoint())
out.append(leader.Elbow.ToPoint())
out.append(leader.End.ToPoint())
output.append(out)
#Assign your output to the OUT variable.
OUT = output
EDIT: Updated code to return points as Dynamo objects.
So I tried using bounding box again using your link but have run into problems.
Even if I remove the leaders before calling the boundingbox, it still encapsulates the entire area including the previous leader.
Then I tried taking the boundingbox.Max.Y and subtracting the textnote.Height but for some reason the Height is not on the same scale as the actual text height, so it barely moves from the max point.