Unhandled exception has occurred in a component in your application... Dynamo for Civil 3D 2023

I was trying to enable a Dynamo script from Civil3D 2021, where it was working perfectly, to Civil 3D 2023. The script to pull the Annotations is not working for the 2023 version. I am not sure what the problem is, I have read a bit and it may be a software issue but I have no idea what is causing this. I will attach the examples of how both scripts are the same but in one version it works but not in the other. If you have any idea what could be causing this problem I would be very grateful.

1 Like

Besides the exception what is the warning that is thrown by the script?
Are there erased dimensions?

A few comments on the code:

  • Delete all the redundant lines 37 - 50
  • You don’t need to open the BlockTable for write only ModelSpace
  • You can get model space directly with SymbolUtilityServices methods using SymbolUtilityServices.GetBlockModelSpaceId
  • doc and db can be defined as globals outside of the function as it can help with transaction nesting
  • The code is not locking the current DWG meaning other application processes may be interacting with the document database causing issues
1 Like

thank you so much for your comment, I followed your advice and the solution to my problem is the following:

def add_aligned_dimension(Annotation_List):
    # Get the current document and database
    doc = Application.DocumentManager.MdiActiveDocument
    db = doc.Database

    # Start a transaction to add the aligned dimensions
    with db.TransactionManager.StartTransaction() as tr:
        # Open the ModelSpace BlockTableRecord for write
        block_table = tr.GetObject(db.BlockTableId, OpenMode.ForWrite)
        model_space_id = SymbolUtilityServices.GetBlockModelSpaceId(db)  # Get ModelSpace BlockTableRecord ID
        model_space = tr.GetObject(model_space_id, OpenMode.ForWrite)
        # Get the IDs of entities in the ModelSpace
        model_space_ids = [e for e in model_space]

        # Add each aligned dimension to the ModelSpace if it is not already there
        for dim in Annotation_List:
            if dim.ObjectId not in model_space_ids:
                model_space.AppendEntity(dim)
                tr.AddNewlyCreatedDBObject(dim, True)
        # Commit the transaction
        tr.Commit()
add_aligned_dimension(Dim_Annotations)

Hi @Francisco.OrtizN86AJ,
I use this and it can help you too.

1 Like