Removing Surface Breaklines using AutoCAD Civil 3D API

By Partha Sarkar

AutoCAD Civil
3D COM API has IAeccSurfaceBreaklines:: Remove method to remove Surface
Breaklines. In the ‘ActiveX API Reference’ document we see this  –

IAeccSurfaceBreaklines::
Remove
Method – > Removes an item from the collection, specified by index or
object reference.

HRESULT
Remove( [in] VARIANT varIndex);

One of our
Civil 3D application developers friend recently asked me ‘how do we use object
reference
in Remove()’ ? That prompted me to dig deeper in this and I find we
can only use index in the Remove() and it doesn’t work with object reference. By
the time we update the Civil 3D ActiveX API reference document on this, I
thought it would be useful to you all if I share this information here in IM
DevBlog.

Here is the
VB.NET code snippet showing usage of COM API Remove(index) –

If(oTinSurface.Breaklines.Count > 0)
 
  ' Remove() Breakline using COM API
  oTinSurface.Breaklines.Remove(0)
  oTinSurface.Rebuild()
  ed.WriteMessage(vbCrLf + "Breakline Removed ! " )
 
End If

 

In Civil 3D .NET API we have the equivalent RemoveAt(int)
and here is C# .NET code snippet –

// Get the TIN Surface       

TinSurface tinSurface = surfaceId.GetObject(OpenMode.ForWrite) as TinSurface;
 
// Lets try to Remove Breakline using RemoveAt(int)        
  tinSurface.BreaklinesDefinition.RemoveAt(0);
 
// rebuild the surface
  tinSurface.Rebuild();

 

Hope this is useful to you!


Comments

3 responses to “Removing Surface Breaklines using AutoCAD Civil 3D API”

  1. James Maeding Avatar
    James Maeding

    this is a big deal, as I recall I could only remove groups of breaklines before.
    I have tools that make 3d plines and add to a surface. Updates need the ability to remove items and add on a pline by pline basis.
    Are you sure this does not refer to groups of breaklines, as that is not what I need. thanks

  2. Hi James –
    Which release of Civil 3D and what API (COM / .NET) you used >>> I recall I could only remove groups of breaklines before. <<<
    If you provide me these details, I can investigate it further.
    Thanks,
    Partha Sarkar
    ADN

  3. James,
    It’s being a while… but I made some testing with this: the RemoveAt will act at the operation level, not at each breakline. For instance, if you add a Std Breakline and select 3 plines, the RemoveAt will remove all 3 plines.
    Database db = Application.DocumentManager.MdiActiveDocument.Database;
    using (Transaction trans = db.TransactionManager.StartTransaction())
    {
    TinSurface tinSurface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface;
    for (int b = 0; b < tinSurface.BreaklinesDefinition.Count; b++)
    {
    SurfaceOperationAddBreakline operation = tinSurface.BreaklinesDefinition[b];
    // the RemoveAt will act at this level
    ed.WriteMessage(“\n{0}”, operation.Description);
    foreach (SurfaceBreakline breakline in operation)
    {
    // this level don’t have a Remove method…
    ed.WriteMessage(“\n\t{0}”, breakline.Description);
    }
    }
    //tinSurface.BreaklinesDefinition.RemoveAt(…);
    //tinSurface.Rebuild();
    //trans.Commit();
    }
    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