Code:
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class MyGroup : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc);
trans.Start("Lab");
int LOOPS = 500;
#region Create 1 Topogrpahy Surface w 500 SiteSubRegions: Takes 12 minutes to execute
DateTime start = DateTime.Now;
List<XYZ> pnts = new List<XYZ>();
pnts.Add(new XYZ(0, 0, 0));
pnts.Add(new XYZ(LOOPS * 3, LOOPS * 3, 0));
pnts.Add(new XYZ(0, LOOPS * 3, 0));
pnts.Add(new XYZ(LOOPS * 3, 0, 0));
TopographySurface surface = TopographySurface.Create(doc, pnts);
// Create 500 SiteSubRegions to test efficiency
for (int i = 0; i < LOOPS; i++)
{
double x = (i * 3) + 1;
double y = 1;
double w = 2;
double h = 1998;
List<Curve> curves = new List<Curve>();
curves.Add(doc.Application.Create.NewLine(new XYZ(x, y, 0), new XYZ(x + w, y, 0), true));
curves.Add(doc.Application.Create.NewLine(new XYZ(x + w, y, 0), new XYZ(x + w, y + h, 0), true));
curves.Add(doc.Application.Create.NewLine(new XYZ(x + w, y + h, 0), new XYZ(x, y + h, 0), true));
curves.Add(doc.Application.Create.NewLine(new XYZ(x, y + h, 0), new XYZ(x, y, 0), true));
CurveLoop cLoop = CurveLoop.Create(curves);
List<CurveLoop> curveLoops = new List<CurveLoop>();
curveLoops.Add(cLoop);
SiteSubRegion reg = SiteSubRegion.Create(doc, curveLoops, surface.Id);
}
DateTime end = DateTime.Now;
TaskDialog.Show("Duration: ", "Duration 1: " + (end - start).TotalSeconds);
#endregion
//trans.RollBack();
#region Create 1 Topogrpahy Surface for every SiteSubRegion created (500 in total): Takes 3 minutes to execute
start = DateTime.Now;
for (int i = 0; i < LOOPS; i++)
{
double space = 1;
double x = (i * 5) + 1;
double y = 1;
double w = 2;
double h = 1998;
List<XYZ> pnts2 = new List<XYZ>();
pnts2.Add(new XYZ(x-space, y-space, 0));
pnts2.Add(new XYZ(x+w+space, y+h+space, 0));
pnts2.Add(new XYZ(x-space, y + h + space, 0));
pnts2.Add(new XYZ(x + w + space, y - space, 0));
TopographySurface surface2 = TopographySurface.Create(doc, pnts2);
List<Curve> curves = new List<Curve>();
curves.Add(doc.Application.Create.NewLine(new XYZ(x, y, 0), new XYZ(x + w, y, 0), true));
curves.Add(doc.Application.Create.NewLine(new XYZ(x + w, y, 0), new XYZ(x + w, y + h, 0), true));
curves.Add(doc.Application.Create.NewLine(new XYZ(x + w, y + h, 0), new XYZ(x, y + h, 0), true));
curves.Add(doc.Application.Create.NewLine(new XYZ(x, y + h, 0), new XYZ(x, y, 0), true));
CurveLoop cLoop = CurveLoop.Create(curves);
List<CurveLoop> curveLoops = new List<CurveLoop>();
curveLoops.Add(cLoop);
SiteSubRegion reg = SiteSubRegion.Create(doc, curveLoops, surface2.Id);
}
end = DateTime.Now;
TaskDialog.Show("Duration: ", "Duration 2: " + (end - start).TotalSeconds);
#endregion
trans.Commit();
return Result.Succeeded;
}
}