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
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
import Autodesk
from Autodesk.Revit.DB import *

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

# Start a new transaction

# 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)
    # Freeze the annotation categories in the view
    frozen_annotation_categories = view.IsolateCategories(BuiltInCategory.OST_Annotations)

# End the transaction

# 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:


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.