I am trying to create a text note, get the bounding box of it to determine its minimum extents, and then place another text note at those extents.
Im struggling with this API… It is not clear
textType = FilteredElementCollector(doc).OfClass(TextNoteType).ToElements() #get textTypes
temp = TextNote.Create(doc, viewID, XYZ(0,0,0), dwgNotes, textType[0].Id) #make 1st text
y = temp.Boundingbox.min
temp = TextNote.Create(doc, viewID, XYZ(0,y,0), equipNotes, textType[0].Id) #make 2nd text below 1st
Im not even clear on the what TextNote.Create returns. Does it return the ID? Doesnt seem like it. Seems like its returning “indexer#” based off the error messages.
What does bounding box return? An obj of type BoundingBoxXYZ?
Please and thank you
So I kinda sorta got it to work. Full Code will be posted at the bottom. For testing you will need to insert the BoilerPlate.py at the top.
'–
So I had the issue where el.get_BoundingBox(view)
would always return Null.
I read a post from here that documented the issues with text properties not working correctly until a regen was done. I had to do a doc.refresh
and start a new transaction between each textNote creation… Kinda ridiculous.
The code below does work.
However its inconsistent in deleting the TextNotes already within the drafting view.
I’ve never experienced such inconsistent execution of code…
'------------
#---Init INPUTS----
noteString = IN[0] #list of string seperated by header
noteDwg = IN[1]
enable = IN[2]
#---Init VAR----
viewExists = False
offset = -3
#t = Transaction(doc, 'Name')
#TransactionManager.Instance.EnsureInTransaction(doc)
#---Application
if enable and noteString and noteDwg:
with Autodesk.Revit.DB.Transaction(doc, 'Add Sheets') as t :
t.Start()
#breakout string headers
dwgNotes = noteString[0]
equipNotes = noteString[1]
generalNotes = noteString[2]
#print(dwgNotes)
#Get all Drafting Views
views =FilteredElementCollector(doc).OfClass(ViewDrafting).WhereElementIsNotElementType().ToElements()
for obj in views:
if obj.Name == noteDwg:
viewExists = True
view = obj
viewID = obj.Id
if viewExists: #view exists
entlist = FilteredElementCollector(doc, viewID).OfClass(TextNote).ToElements() #get all of type TextNote in the view
for obj in entlist:
doc.Delete(obj.Id) #delete all TextNotes
else:
#create the view
drafting_type_id = get_drafting_type_id()
view = ViewDrafting.Create(doc, drafting_type_id)
view.Name = noteDwg
viewID = view.Id
doc.Regenerate
t.Commit()
t.Start()
#Insert the note text and headers
textType = FilteredElementCollector(doc).OfClass(TextNoteType).ToElements()
TextNote.Create(doc, viewID, XYZ(0,0,0), "DRAWING NOTES", textType[0].Id)
el = TextNote.Create(doc, viewID, XYZ(0,-2,0), dwgNotes, textType[0].Id)
doc.Regenerate
t.Commit()
t.Start()
el_bbY = el.get_BoundingBox(view).Min.Y
TextNote.Create(doc, viewID, XYZ(0, el_bbY -2, 0), "EQUIPMENT NOTES", textType[0].Id)
el = TextNote.Create(doc, viewID, XYZ(0, el_bbY + offset, 0), equipNotes, textType[0].Id)
doc.Regenerate
t.Commit()