Tried to get ChatGPT to write this code for freezing annotation

tried to get ChatGPT to write this code but can an error on line 24.
very new to Dynamo any help would be most appreciated.

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument

# Start a new transaction
TransactionManager.Instance.EnsureInTransaction(doc)

# Get the current view and view template
view = doc.ActiveView
view_template = view.ViewTemplate

# Check if the view has a view template assigned
if view_template:
    # Freeze the annotation categories in the view template
    frozen_annotation_categories = view_template.IsolateCategories(BuiltInCategory.OST_Annotations)
else:
    # Freeze the annotation categories in the view
    frozen_annotation_categories = view.IsolateCategories(BuiltInCategory.OST_Annotations)

# End the transaction
TransactionManager.Instance.TransactionTaskDone()

# Return the frozen annotation categories
OUT = frozen_annotation_categories
1 Like

Hi and welcome to the Dynamo forum,

I think you will be hard pressed to find anyone here willing to troubleshoot AI written code for you.

Quoting a comment that stuck with me when another user asked a similar question:

3 Likes

To add to my own feedback from the quote (thanks @MVE1112!).

If you’re new to dynamo, learn how to use Dynamo first. This is python/revit API code which isn’t usually explored until later in a programmer’s journey.

ChatGPT generally doesn’t do a good job with revit API, I wouldnt bother with it unless it improves.

At the absolute least can you please bother to say the goal of your code and put it in proper quotes for readability. Not hard to do, bare minimum.

4 Likes