How to creat offset alignment that has widening at curve

How to creat offset alignment that has widening at curve

quangpt.tric
Advocate Advocate
2,296 Views
5 Replies
Message 1 of 6

How to creat offset alignment that has widening at curve

quangpt.tric
Advocate
Advocate

Hi everyone,

I want to creat offset alignment and it has widening at curve segment as image below.

Can anybody help me to sloved my issue? I want to code with C#. Thank you so much!Capture.PNG

0 Likes
Accepted solutions (1)
2,297 Views
5 Replies
Replies (5)
Message 2 of 6

hippe013
Advisor
Advisor
Accepted solution

I am using vb.NET, but this should be easy enough to convert over to C#. I am not sure if this is the best or most efficient way to do this, but it seems to work.

 

 

 Using tr As Transaction = db.TransactionManager.StartTransaction
            'Open Main Alignment for Read
            Dim align As Alignment = tr.GetObject(res.ObjectId, OpenMode.ForRead)

            'Build List of Alignment Arcs
            For Each alignEnt As AlignmentEntity In align.Entities
                Dim subEntCount As Integer = alignEnt.SubEntityCount
                For i As Integer = 0 To subEntCount - 1
                    Dim alignSubEnt As AlignmentSubEntity = alignEnt(i)

                    If alignSubEnt.SubEntityType = AlignmentSubEntityType.Arc Then
                        alignmentSubEntityArcList.Add(alignSubEnt)

                    End If

                Next
            Next

            'Convert List of Arcs to Array
            Dim arcs() As AlignmentSubEntityArc = alignmentSubEntityArcList.ToArray

            'Create Left and Right Offset Alignments
            Dim offsetAlignRightId As ObjectId = Alignment.CreateOffsetAlignment(db, "MyOffsetAlignmentRight", align.Name, 30, "Standard")
            Dim offsetAlignLeftId As ObjectId = Alignment.CreateOffsetAlignment(db, "MyOffsetAlignmentLeft", align.Name, -30, "Standard")

            'Get Left and Right Offset Alignments
            Dim offsetAlignRight As Alignment = offsetAlignRightId.GetObject(OpenMode.ForWrite)
            Dim offsetAlignLeft As Alignment = offsetAlignLeftId.GetObject(OpenMode.ForWrite)

            'Get Left andd Right Offset Info
            Dim offsetInfoRight As OffsetAlignmentInfo = offsetAlignRight.OffsetAlignmentInfo
            Dim offsetInfoLeft As OffsetAlignmentInfo = offsetAlignLeft.OffsetAlignmentInfo

            'Create AutoWidening Info
            Dim widenInfo As New AutoWideningInfo With {.IncreasedWidth = 50, .Side = Autodesk.Civil.WideningSide.Both, .TransitionLength = 100}

            'Add the Left and Right AutoWidening Info
            offsetInfoRight.AddAutoWidenings(widenInfo, arcs)
            offsetInfoLeft.AddAutoWidenings(widenInfo, arcs)

            'Commit Transaction
            tr.Commit()
        End Using

 

Message 3 of 6

quangpt.tric
Advocate
Advocate

Thank you so much @hippe013 . I can solved my issue with your code. But another question, I want to specify the starting point and the end point of the IncreasedWidth. Can you tell me how I can do it?

0 Likes
Message 4 of 6

Norman_Yuan
Mentor
Mentor

Well, @hippe013 's code showed how to create the widening of the OffsetAlignment automatically, with AddAutoWidenings() method by passing it an AutoWideningInfo object. Therefore, the widening is automatically calculated (where it starts and ends...).

 

If you want to start and end the widening at the point of your choice, you would use OffsetAlignmentInfo.AddWidening() method, where you input the StartStaion and EndStation. Since you only want to widening along the arc portion of the offset alignment, you still need to first find all arc portion, as @hippe013 's code shows. Then based on each arc's start/end station, you decide the widening's start/end station as you wish.

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 6

quangpt.tric
Advocate
Advocate

Hi @Norman_Yuan , I try to use AddWidening() method but it not available. You can see in picture below. My aim is that for each arc with different radius the widening will be different and also, the startpoint and endpoint of IncreasedWidth will be different too. Can you give me some sample code to solved it.

Thank you so much again, my teacher!

 

 

0 Likes
Message 6 of 6

hippe013
Advisor
Advisor

@quangpt.tric 

 

As @Norman_Yuan  points out, you may want to use the AddWidening Method. Here is a quick snippet of code that adds a manual widening and then edits the beginning of that widening to add a transition to that manual widening. Please note that I am selecting and editing the offset alignment and not the parent alignment. 

 

 

Dim startSta As Double = resStartSta.Value
Dim endSta As Double = resEndSta.Value
Dim offset As Double = resOffset.Value
Dim transitionLength As Double = resTransition1.Value

Using tr As Transaction = db.TransactionManager.StartTransaction
            Try
                'Open the Offset Alignment for Write
                Dim offsetAlign As Alignment = tr.GetObject(res.ObjectId, OpenMode.ForWrite)

                'Get the Offset Alignment Info
                Dim offsetAlignInfo As OffsetAlignmentInfo = offsetAlign.OffsetAlignmentInfo

                'Add Manual Widening Given a Start Station, End Station, and Offset
                offsetAlignInfo.AddWidening(startSta, endSta, offset)

                'If you want to add a transition to the offset you need to get the AlignmentTransitionCollection
                Dim transitions As AlignmentTransitionCollection = offsetAlignInfo.Transitions

                'I happen to know that the transition I want is the first in the Collection
                Dim transition1 As AlignmentTransition = transitions(0)

                'You can edit the slim transition that is given by the AddWidening Method
                transition1.TransitionDescription.Length = transitionLength

                'And of course, commit your transaction
                tr.Commit()

                'A common exception thrown is the System.ArgumentException
            Catch exArg As System.ArgumentException
                MsgBox(exArg.Message)
     End Try
End Using

 

 

0 Likes