Help creating simple script that lists text styles as text notes

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.

Here is the script I got from ChatGPT3:

# 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")

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.

Thank you in advance for your help.

You should have asked chatGPT ;p

  1. [unrelated] To format code in the forum pick the </> icon while having your code selected, that makes it more readable for everyone

  2. 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

  3. You go here and find the TextNote Class

  4. There you will find static method to create TextNotes, pick the one that make sense to you. The simplest one being

  5. then you read the arguments required and you provide them.

@ErikFrits did something similar but a bit more advanced for you perhaps here EF-Tools/ at main · ErikFrits/EF-Tools · GitHub

AddLabel does not serve any purpose for what you have in mind. And, does not exist in the Revit API context :laughing:

Well good to know chatgpt still has faults and our jobs are safe today anyway.

You know - I had the same thought this morning! I will and see what it says.

Awesome! Thank you I will definitely do that next time.

Perfect will check this out thank you.

Do you remember what his tool is called? I have his plugin but don’t see anything like this.

Haha I had a feeling that may be the case :slight_smile: funny. If it includes it again I’ll ask it why.


Me clicking on Erik’s link I gave you… :wink:
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)

Ah its ‘Graphic Overviews’ and its amazing wow. Seriously impressive stuff.

600 lines of code! And that UI on the dialog box is awesome too.

I will take your advice about learning from the pros. I’ll give chat gpt a rest for a while haha. I think its drunk.

Thank you.

1 Like