Reset Label Location for COGO Point

Hi guys, I was trying to use ResetLabel for a group of COGO points with labels that were moved away. To achieve this, I created this Python node, where the input consists of the points’ handles as strings.

# Load the Python Standard and DesignScript Libraries
import sys
import clr

clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AeccDbMgd')

# Importar referencias
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.Civil.DatabaseServices import *

# Entrada: Lista de handles (strings) de los puntos COGO
handles = IN[0]
result = []

adoc = Application.DocumentManager.MdiActiveDocument

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            try:
                for handle_str in handles:
                    # Convertir el string a un objeto Handle
                    handle = Handle(handle_str)
                    
                    # Obtener el ObjectId usando el Handle
                    obj_id = db.GetObjectId(False, handle, 0)
                    
                    if not obj_id.IsNull:
                        cogo_point = t.GetObject(obj_id, OpenMode.ForWrite)
                        
                        if isinstance(cogo_point, CogoPoint):
                            cogo_point.ResetLabelLocation()
                            result.append(f"Handle {handle_str}: Éxito")
                        else:
                            result.append(f"Handle {handle_str}: No es un COGO Point")
                    else:
                        result.append(f"Handle {handle_str}: No encontrado")
                
                t.Commit()
                
            except Exception as e:
                result.append(f"Error: {str(e)}")
                t.Abort()

OUT = result

Could someone help me with this?

BTW, I was trying to use the ResetLabel node from the Camber package, but I couldn’t figure out what the input for that node was. I tried many things, but nothing worked.

Thanks, guys!

Can you attached example drawing

Hi @hbajana,

I don’t know if upgrading to Civil 3D 2025 is an option for you, but if so then you can use this node:

Hi @zachri.jensen, thanks! But the company is going to use the 2024 version for a few more years before switching to the 2025 version.

@hosneyalaa, there’s a video that shows what I want to achieve.

Thank you guys!

@hbajana
try

# Load the Python Standard and DesignScript Libraries
import sys
import clr

clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AeccDbMgd')

# Importar referencias
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.Civil.DatabaseServices import *

# Entrada: Lista de handles (strings) de los puntos COGO
handles = IN[0]
result = []

adoc = Application.DocumentManager.MdiActiveDocument

with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            try:
                for handle_str in handles:
                    # Convertir el string a un objeto Handle
                    #handle = Handle(handle_str)
                    
                    # Obtener el ObjectId usando el Handle
                    obj_id = handle_str.InternalObjectId
                    
                    if not obj_id.IsNull:
                        cogo_point = t.GetObject(obj_id, OpenMode.ForWrite)
                        
                        if isinstance(cogo_point, CogoPoint):
                            cogo_point.ResetLabelLocation()
                            
                        else:
                            result.append(f"Handle {handle_str}: No es un COGO Point")
                    else:
                        result.append(f"Handle {handle_str}: No encontrado")
                
                t.Commit()
                
            except Exception as e:
                result.append(f"Error: {str(e)}")
                t.Abort()

OUT = result

3

Thanks @hosneyalaa, It works very well.