Road Widening using AutoCAD Civil 3D .NET API

By Partha Sarkar

In AutoCAD Civil 3D, programmatically we can create Offset Alignment using overloaded Alignment.CreateOffsetAlignment() API. Once we have created an Offset Alignment, we can call OffsetAlignmentInfo.AddWidening() to create a road widening for a specific section of the road.

Here is a C# .NET code snippet demonstrating usage of OffsetAlignmentInfo.AddWidening() API :

 

using (Transaction trans = db.TransactionManager.StartTransaction())
{
 
  ObjectIdCollection alignmentIdColl = civilDoc.GetAlignmentIds();
  foreach (ObjectId alignmentId in alignmentIdColl)
  {
    alignment = alignmentId.GetObject(OpenMode.ForRead) asAlignment;
    if (alignment.Name.ToString() == "Centerline (1)")
      break;
 
  }
 
  if (alignment != null)
  {
 
    // Get a AlignmentStyle Object to use in OffSet Alignment creation
    ObjectId offsetAlignmentStyleId = civilDoc.Styles.AlignmentStyles["Design Style"];
 
    if (offsetAlignmentStyleId == null)
    {
      ed.WriteMessage("nOffset Alignment Style NOT found !");
      return;
    }
 
    // Now create the OffSetAlignment
    // A negative value (offset < 0) indicates the Offset Alignment is at the left of the parent alignment.
    // A positive value (offset > 0) indicates the Offset Alignment is at the right.
    ObjectId offsetAlignmentId = Alignment.CreateOffsetAlignment("Offset_Alignment", alignment.ObjectId, -30.00, offsetAlignmentStyleId);
 
    // Open the Offset Alignment object to add road widening
    Alignment offsetAlignment = offsetAlignmentId.GetObject(OpenMode.ForWrite) asAlignment;
 
    OffsetAlignmentInfo offsetInfo1 = offsetAlignment.OffsetAlignmentInfo;
 
    // Now use AddWidening( double startStation, double endStation, double offsetDistance )
    // This method will create a specific region from startStation to endStation 
    // with slim entry transition and exit transition.
    offsetInfo1.AddWidening(200.00, 533.0, 40.0);
 
  }    
 
  trans.Commit();
}

 

Following picture shows how it appears in AutoCAD Civil 3D :

Civil3D_Road_Widening_API

Hope this is useful to you!


Comments

3 responses to “Road Widening using AutoCAD Civil 3D .NET API”

  1. It was a nice Code snipe on Civil3D Offset Alignment API.
    Alignment.CreateOffsetAlignment()
    OffsetAlignmentInfo.AddWidening()
    offsetInfo1.AddWidening(200.00, 533.0, 40.0);
    (Adds a widening with two 0-length linear transitions to the Offset Alignment.)
    This tow are parity much straight forward.
    Will it be possible to add Tapper(2.5m) before or after the Offset ?
    For sample file can access the link.
    https://drive.google.com/?tab=mo&authuser=0#folders/0B6KcEUo0Z1ylTEhKcUNhUm9hek0
    If possible with sample code snipe will be great help.
    Regards
    Avijit

  2. It was a nice Code snipe on Civil3D Offset Alignment API.
    Alignment.CreateOffsetAlignment()
    OffsetAlignmentInfo.AddWidening()
    offsetInfo1.AddWidening(200.00, 533.0, 40.0);
    Adds a widening with two 0-length linear transitions to the Offset Alignment.
    This are parity much straight forward.
    Will it be possible to add Tapper(2.5m) before or after the Offset ?
    For Sample data to work on can be found on this link.
    https://drive.google.com/?tab=mo&authuser=0#folders/0B6KcEUo0Z1ylTEhKcUNhUm9hek0
    if possible with sample code snipe will be great.
    Regards
    Avijit Jana
    WS Atkins

  3. Hi Avijit,
    I did a quick check and I think to use the ‘Transition Length’ you need to create a AutoWideningInfo object and set AutoWideningInfo.TransitionLength = double value;
    And then use this AutoWideningInfo object in AddAutoWidenings (AutoWideningInfo, SweptCurveLocation)
    Hope this helps.
    Let me know if you need any further help.
    Thanks,
    Partha

Leave a Reply to Avijit JanaCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading