How to get alignment style names in dynamo

Hello everyone, I hope you’re doing well.
I’m trying to retrieve all alignment style names in Dynamo as a list of strings from the current drawing. I wrote the code below, which successfully retrieves all alignment styles from the current drawing, but I can’t access their names as strings.

Does anyone have an idea how to get their names as a string?
Here is the code:

import clr
import sys

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference("AcMgd")
clr.AddReference("AcCoreMgd")
clr.AddReference("AcDbMgd")
clr.AddReference("AecBaseMgd")
clr.AddReference("AecPropDataMgd")
clr.AddReference("AeccDbMgd")

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *



adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
cdoc = CivilApplication.ActiveDocument

# Create a list to hold our output
style_objects = []

# Start Document Lock and Transaction
with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            try:
                # 1. Access the collection of Alignment Styles
                # This must be indented inside the transaction block
                styleIds = cdoc.Styles.AlignmentStyles

                # 2. Loop through every ID found in the collection
                for styleId in styleIds:
                    # Open the style object for reading
                    style = t.GetObject(styleId, OpenMode.ForRead)

                    # Add the Style Object to our list
                    style_objects.append(style)

                # 3. Commit the transaction
                t.Commit()

            except Exception as ex:
                # If something goes wrong, abort the transaction
                t.Abort()
                style_objects = ["Error: " + str(ex)]

# Assign your output to the OUT variable.
OUT = style_objects

Here’s you code in a readable format - please use the </> menu item or use triple backticks like this:
```python
Code goes here
```

import clr
import sys

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference("AcMgd")
clr.AddReference("AcCoreMgd")
clr.AddReference("AcDbMgd")
clr.AddReference("AecBaseMgd")
clr.AddReference("AecPropDataMgd")
clr.AddReference("AeccDbMgd")

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
cdoc = CivilApplication.ActiveDocument

# Create a list to hold our output
style_objects = []

# Start Document Lock and Transaction
with adoc.LockDocument():
    with adoc.Database as db:
        with db.TransactionManager.StartTransaction() as t:
            try:
                # 1. Access the collection of Alignment Styles
                # This must be indented inside the transaction block
                styleIds = cdoc.Styles.AlignmentStyles

                # 2. Loop through every ID found in the collection
                for styleId in styleIds:
                    # Open the style object for reading
                    style = t.GetObject(styleId, OpenMode.ForRead)

                    # Add the Style Object to our list
                    style_objects.append(style)

                # 3. Commit the transaction
                t.Commit()

            except Exception as ex:
                # If something goes wrong, abort the transaction
                t.Abort()
                style_objects = ["Error: " + str(ex)]

# Assign your output to the OUT variable.
OUT = style_objects

The cdoc.Styles.AlignmentStyles returns a AlignmentStyleCollection see docs here

So you can grab the AlignmentStyle objects like this (untested)
style_objects = list(cdoc.Styles.AlignmentStyles)

1 Like

Does it have to be code?
From 2025.2 onwards, you could do this very easy with OOTB-nodes:

(“Achse” = “Alignment”)

Danke. Ich darf civil 3d bis 2024 auf mein Laptop haben.Aus diesem Grund.

thank you for the replay. I upgraded the code based on your solution. I get all style IDs instead of their names. Is their a way to convert the IDs to their name.

import clr
import sys

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference("AcMgd")
clr.AddReference("AcCoreMgd")
clr.AddReference("AcDbMgd")
clr.AddReference("AecBaseMgd")
clr.AddReference("AecPropDataMgd")
clr.AddReference("AeccDbMgd")

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
cdoc = CivilApplication.ActiveDocument

# Create a list to hold our output
style_objects = list(cdoc.Styles.AlignmentStyles)


OUT = style_objects

Pretty sure you’ll have to use the ID to get the object, from there extract the name.

thank you.