List all alignment entities

By Augusto Goncalves

An alignment is composed of entities, which can be complex, such as SpiralCurveSpiral (SCS), but in the end is basically composed by Lines, Arcs and Spirals.

For both cases we can start at the Alignment.Entities property collection, but this property only return the first level of complex entities derived from type AlignmentEntity. For the second level, corresponding to primitive entities, for each of those AlignmentEntity objects we can access as an array of AlignmentSubEntity.

  Public Sub alignmentsEntities()

    Dim ed As Editor = _

            Application.DocumentManager.MdiActiveDocument.Editor

    Dim db As Database = _

            Application.DocumentManager.MdiActiveDocument.Database

    Using trans As Transaction = _

                            db.TransactionManager.StartTransaction()

      ‘get the civil document

      Dim civilDoc As CivilDocument = CivilApplication.ActiveDocument

      ‘and the collection of alignments

      Dim alignColl As ObjectIdCollection = _

                                          civilDoc.GetAlignmentIds()

 

      For Each alignId As ObjectId In alignColl ‘for each alignment

        ‘open for read

        Dim align As Alignment = trans.GetObject( _

                                  alignId, OpenMode.ForRead)

        ‘for each entity in the alignment

        For Each alignEnt As AlignmentEntity In align.Entities

          ‘get the number of sub entities

          Dim subEntCount As Integer = alignEnt.SubEntityCount

          For i As Integer = 0 To subEntCount – 1 ‘for each subentity

            ‘get the type

            Dim alignSubEnt As AlignmentSubEntity = alignEnt(i)

            Select Case alignSubEnt.SubEntityType

              Case AlignmentSubEntityType.Arc

                ‘ARC

                Dim alignSubEntArc As AlignmentSubEntityArc = _

                  alignSubEnt

              Case AlignmentSubEntityType.Line

                ‘LINE

                Dim alignSubEntLine As AlignmentSubEntityLine = _

                  alignSubEnt

              Case AlignmentSubEntityType.Spiral

                ‘SPIRAL

                Dim alignSubEntSpiral As AlignmentSubEntitySpiral = _

                  alignSubEnt

            End Select

          Next

        Next

      Next

    End Using

  End Sub


Comments

8 responses to “List all alignment entities”

  1. petcon Avatar
    petcon

    any c# code?

  2. Hi,
    You can easily convert between VB.NET and C# using this online (and free) tool http://www.developerfusion.com/tools/convert/vb-to-csharp/
    Regards,
    Augusto Goncalves

  3. Hello.
    VS doesn´t find the next words in the code:
    “Editor”
    “Database”
    “Transaction”
    “objectIDcollection”
    I have imported(using) the next namespaces and others:
    using Autodesk.Civil.ApplicationServices;
    using Autodesk.Civil.DatabaseServices;
    using Autodesk.Civil.Runtime;
    using Autodesk.Civil.Settings;
    Which references *.dll do I have to add or import namespaces? Thank you.

  4. Hi,
    You need the following .NET references:
    AcMgd.dll
    AcDbMgd.dll
    AcCoreMgd.dll (2013 only)
    AecBaseMgd.dll
    AeccDbMgd.dll
    All references are at the Civil3D folder. Please try that and let me know.
    Regards,
    Augusto Goncalves

  5. I already have all these added assemblies. Can I contact myself with you?

  6. Hi,
    Please email me. My first name, dot, my last name, @autodesk.com
    Thanks,
    Augusto Goncalves

  7. Hello Augusto.
    I don´t understand a thing.
    In this line “foreach (AlignmentEntity alignEnt in align.Entities)” is supposed to start at the order of entities in the drawing, but using the debugger, I do not understand what order continues to go naming each entity.
    For example, if I start with a line and then I have an entity SCS, until appoints five Alignmentline, the following is not AlignmentSCS.
    What criteria is to order and how you could get a Database with sorted entities? I would like a database as if the alignment table.
    Thank you.

  8. Hi,
    You should use GetEntityByOrder instead, which requires a ‘for’ on the index.
    There are a couple samples at http://adndevblog.typepad.com/infrastructure/2012/08/replacing-alignment-entities.html and http://adndevblog.typepad.com/infrastructure/2012/08/using-overrule-with-civil-3d-entities.html
    Regards,
    Augusto Goncalves

Leave a Reply to Augusto GoncalvesCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading