Hey guys I am a level 1 coder knowing barely enough to be able to create the button on the ribbon for this command. I asked chat gpt3 to create a pyrevit script for me and it spit out a script that looks legit but doesn’t work. The prompt was to create a script that creates and displays a text note for every single text style in the project. I did this on one of my companies templates yesterday and it was a real bear manually doing this by hand.
This is what I’m looking to have pyrevit do within a legend.
# Import necessary modules
from pyrevit import revit, DB
from pyrevit import script
from pyrevit import forms
# Get current document
doc = __revit__.ActiveUIDocument.Document
# Get all text styles in the document
text_styles = DB.FilteredElementCollector(doc).OfClass(DB.TextNoteType).ToElements()
# Create a text note for each text style
for text_style in text_styles:
text_note = TextNote.Create(doc, view.Id, XYZ.Zero, text_style.Id, "Sample Text")
legend.AddLabel(text_note.Id)
My question is about the second to last line, “TextNote.Create” how can I learn what this is supposed to be doing? Is this something I look in the Revit API docs for? And the last line… Is it trying to add labels? Just looking for tips on where to look for any documentation on where for instance it may have got “legend.AddLabel” on the last line.
[unrelated] To format code in the forum pick the </> icon while having your code selected, that makes it more readable for everyone
To create something in Revit, you need to wrap it in a Transaction or Open a transaction, check this page and look at the exemple + seem more examples clicking on the top right <> cign
You go here and find the TextNote Class ApiDocs.co
There you will find static method to create TextNotes, pick the one that make sense to you. The simplest one being ApiDocs.co
then you read the arguments required and you provide them.
@skyeg3
Me clicking on Erik’s link I gave you… Graphics overrides is the name of the tool
But joke aside, the best advice you will ever get:
When finding a new tool, click and try EVERYTHING.
And in the case of pyrevit code base, tools or external extensions, always look at the code and try to read it. That’s how you will learn the most (at least at the beginning)