OK, here's the c# class:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.DatabaseServices.Styles;
using System;
namespace Civil3D_Misc_Commands.SurfaceTools
{
public class SwapEdge
{
[CommandMethod("SwapEdgeToo")]
public void swapedgetoo()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions eOpts = new PromptEntityOptions("Select Surface: ");
eOpts.SetRejectMessage("...not a Tin Surface, try again.");
eOpts.AddAllowedClass(typeof(TinSurface), true);
PromptEntityResult eRes = ed.GetEntity(eOpts);
if (eRes.Status != PromptStatus.OK)
return;
eOpts.Message = "\n..Select edge to swap: ";
var surfId = eRes.ObjectId;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
var s = (TinSurface)surfId.GetObject(OpenMode.ForRead);
var style = (SurfaceStyle)s.StyleId.GetObject(OpenMode.ForRead);
var ds = style.GetDisplayStylePlan(SurfaceDisplayStyleType.Triangles);
if (ds.Visible == false)
{
ed.WriteMessage("\n Surface is not displaying Triangles, exiting...");
return;
}
}
eRes = ed.GetEntity(eOpts);
while (eRes.Status == PromptStatus.OK)
{
if (eRes.ObjectId != surfId)
{
ed.WriteMessage("...not the same Surface!");
continue;
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
var surf = (TinSurface)eRes.ObjectId.GetObject(OpenMode.ForWrite);
var edge = surf.FindEdgeAtXY(eRes.PickedPoint.X, eRes.PickedPoint.Y);
try
{
var surfOp = surf.SwapEdge(edge);
}
catch (SurfaceException e)
{
if (e.Message == "CantSwap")
ed.WriteMessage("\n Can't swap that edge!");
}
catch(SystemException e)
{
ed.WriteMessage("...Something unexpected happened, this is the message:\n {0}", e.Message);
}
tr.Commit();
}
eRes = ed.GetEntity(eOpts);
}
}
}
}