I now have a version working with Figures, however it does not work like the built-in Add boundary function. In C3D, adding a boundary that is a Figure is no different than selecting a pline. I cannot find a way to use the Figure object in code. Instead, I've had to explode the figure (which leaves the figure in the drawing), add the resulting pline to the drawing, use the pline to add the boundary.
This method leaves an extra object in the drawing, but I'm not sure how else to do this. The user could place the new plines on a frozen layer. Or I could make the new plines invisible......Any other ideas are welcome.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AECC.Interop.Land;
using Autodesk.AECC.Interop.UiLand;
using AutocadUtilities;
using Civil3DUtilities;
namespace SincpacC3D.Create_Hide_Boundaries
{
/// <summary>
/// Create multiple Hide Boundaries for a Surface
/// </summary>
public class HideBoundaries
{
public HideBoundaries()
{
}
private AeccSurface oSurf ;
[CommandMethod("MULTIHIDE")]
public void MultiHide()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
C3DUtil c3dUtil = new C3DUtil();
AeccDocument doc = c3dUtil.AeccDoc;
Database db = Application.DocumentManager.MdiActiveDocument.Database; PromptEntityOptions ePrmpt = new PromptEntityOptions("");
ePrmpt.Message = "\nSelect surface to add hidden boundaries to: ";
PromptEntityResult eResult = ed.GetEntity(ePrmpt);
if (eResult.Status == PromptStatus.OK)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
Entity oEnt = tr.GetObject(eResult.ObjectId, OpenMode.ForRead, false) as Entity;
oSurf = oEnt.AcadObject as AeccSurface;
BlockTableRecord curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
PromptSelectionOptions sPrmpt = new PromptSelectionOptions();
sPrmpt.MessageForAdding = "\nSelect plines for Hide boundary(ies): ";
sPrmpt.MessageForRemoval = "\nPlines to remove from selection set: ";
TypedValue[] filter = new TypedValue[1];
filter[0] = new TypedValue(0, "*POLYLINE,AECC_SVFIGURE");
SelectionFilter ssFilter = new SelectionFilter(filter);
PromptSelectionResult ssResult;
ssResult = ed.GetSelection(sPrmpt, ssFilter);
if (ssResult.Status == PromptStatus.OK)
{
PromptResult strResult = ed.GetString("Prefix for boundary definitions: ");
int i = 0;
ObjectId[] objIds = ssResult.Value.GetObjectIds();
foreach (ObjectId oId in objIds)
{
Entity oPline = tr.GetObject(oId, OpenMode.ForRead, false) as Entity;
Polyline testPline1 = oPline as Polyline;
if (testPline1 == null)
{
Polyline2d testPline2 = oPline as Polyline2d;
if (testPline2 == null)
{
Polyline3d testPline3 = oPline as Polyline3d;
if (testPline3 == null)
{
DBObjectCollection oExpObjs = new DBObjectCollection();
oPline.Explode(oExpObjs);
oPline = oExpObjs[0] as Entity;
curSpace.AppendEntity(oPline);
tr.AddNewlyCreatedDBObject(oPline, true);
}
}
}
try
{
oSurf.Boundaries.Add((AcadEntity)oPline.AcadObject, strResult.StringResult + i, AeccBoundaryType.aeccBoundaryHide, true, 0.10);
i++;
}
catch
{
}
}
oSurf.Rebuild();
}
tr.Commit();
}
catch
{
}
}
}
}
}
}