removeSurface(string name) { try { using (Transaction tr = BaseObjs.startTransactionDb()) { try { TinSurface surface = getTinSurface(name); if (surface != null) { surface.UpgradeOpen(); surface.Erase(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 168", ex.Message)); } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 174", ex.Message)); } }
/// <summary> /// Sets the default build options. /// Date: 2/19/2017 /// </summary> /// <param name="surface">The surface.</param> public void SetDefaultBuildOptions(TinSurface surface) { try { using (Application.DocumentManager.MdiActiveDocument.LockDocument()) { using (var tr = CivilApplicationManager.StartTransaction()) { MessengerManager.AddLog("Start Setting Build Options"); if (surface == null) { return; } surface.UpgradeOpen(); ///Todo:Handle Breaklines for Water and Bulkhead-Added 3.7.17 /// if (surface.Name.Contains("WATER")) { surface.BuildOptions.MaximumTriangleLength = 100; } else if (surface.Name.Contains("All")) { surface.BuildOptions.MaximumTriangleLength = 200; } else { surface.BuildOptions.MaximumTriangleLength = 20; } surface.BuildOptions.UseMaximumTriangleLength = true; surface.BuildOptions.NeedConvertBreaklines = true; surface.BuildOptions.ExecludeMinimumElevation = true; surface.BuildOptions.MinimumElevation = 0.1; // Possible negative elevation surface.BuildOptions.CrossingBreaklinesElevationOption = CrossingBreaklinesElevationType.UseLast; ///Todo: Changed 2/19/17 from None. surface.DowngradeOpen(); tr.Commit(); MessengerManager.AddLog("End Setting Build Options"); MessengerManager.AddLog("Surface Settings: " + surface.Name); } } } catch (System.Exception e) { MessengerManager.LogException(e); } }
//[CommandMethod("CreateFromTIN")] //public void CreateFromTin() //{ // var civildoc = AcadApplictionDocument.GetMdiDocument(); // var editor = civildoc.Editor; // using ( // Transaction ts = // Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction()) // { // // Example TIN surface from Civil Tutorials: // string tinFile = // @"C:\Program Files\Autodesk\AutoCAD Civil 3D 2013\Help\Civil Tutorials\Corridor surface.tin"; // try // { // Database db = Application.DocumentManager.MdiActiveDocument.Database; // ObjectId tinSurfaceId = TinSurface.CreateFromTin(db, tinFile); // editor.WriteMessage("Import succeeded: {0} \n {1}", tinSurfaceId.ToString(), db.Filename); // } // catch (System.Exception e) // { // // handle bad file path // editor.WriteMessage("Import failed: {0}", e.Message); // } // // commit the transaction // ts.Commit(); // } //} //[CommandMethod("CreateTINSurface")] //public void CreateTINSurfaceByPointCollection() //{ // using (Transaction ts = AcadApplictionDocument.GetTransaction()) // { // var doc = CivilApplicationManager.ActiveCivilDocument; // string surfaceName = "All"; // // Select a style to use // if (GetSurfaceStyle("pga-tour-style") == null) // SurfaceStyle(); // ObjectId surfaceStyleId = GetSurfaceStyle("pga-tour-style").ObjectId; // if (surfaceStyleId == null) return; // // Create the surface // ObjectId surfaceId = TinSurface.Create(surfaceName, surfaceStyleId); // TinSurface surface = surfaceId.GetObject(OpenMode.ForWrite) as TinSurface; // // Add some random points // Point3dCollection points = new Point3dCollection(); // points = ReadPointCloudFile.ReadFile( // @"C:\Civil 3D Projects\PGA-8.23.2016\SV", "dtm06.txt"); // surface.AddVertices(points); // // commit the create action // ts.Commit(); // } //} /// <summary> /// Creates the tin surface by point collection. /// </summary> /// <param name="points">The points.</param> /// <param name="polylinelayer">The polylinelayer.</param> /// <returns>TinSurface.</returns> //public TinSurface CreateTINSurfaceByPointCollection(Point3dCollection points, string polylinelayer) //{ // TinSurface surface; // using (Transaction ts = AcadApplictionDocument.GetTransaction()) // { // var doc = CivilApplicationManager.ActiveCivilDocument; // string surfaceName = polylinelayer; // // Select a style to use // if (GetSurfaceStyle(polylinelayer) == null) // SurfaceStyle(); // ObjectId surfaceStyleId = GetSurfaceStyle(polylinelayer).ObjectId; // // Create the surface // ObjectId surfaceId = TinSurface.Create(surfaceName, surfaceStyleId); // surface = surfaceId.GetObject(OpenMode.ForWrite) as TinSurface; // //surface.BuildOptions.MaximumTriangleLength = 20; // //surface.BuildOptions.UseMaximumTriangleLength = true; // SetDefaultBuildOptions(surface); ///Todo: 2.20.2017 // // Add some random points // //Point3dCollection points = new Point3dCollection(); // //points = ReadPointCloudFile.ReadFile(path, filename); // surface.AddVertices(points); // // commit the create action // ts.Commit(); // } // return surface; //} /// <summary> /// Creates the tin surface by point collection. /// </summary> /// <param name="path">The path.</param> /// <param name="filename">The filename.</param> public void CreateTINSurfaceByPointCollection(string path, string filename) { using (Transaction ts = AcadApplictionDocument.GetTransaction()) { var doc = CivilApplicationManager.ActiveCivilDocument; string surfaceName = "All"; // Select a style to use ObjectId surfaceStyleId = ObjectId.Null; //NO-DISPLAY //if (GetSurfaceStyle("NO-DISPLAY") != null) //{ // if (GetSurfaceStyle("NO-DISPLAY") == null) // SurfaceStyle(); // surfaceStyleId = GetSurfaceStyle("NO-DISPLAY").ObjectId; //} if (GetSurfaceStyle("Standard") != null) { if (GetSurfaceStyle("Standard") == null) { SurfaceStyle(); } surfaceStyleId = GetSurfaceStyle("Standard").ObjectId; } // Create the surface ObjectId surfaceId = TinSurface.Create(surfaceName, surfaceStyleId); TinSurface surface = surfaceId.GetObject(OpenMode.ForWrite) as TinSurface; surface.DowngradeOpen(); SetDefaultBuildOptions(surface); ///Todo: 2.20.2017 surface.UpgradeOpen(); //surface.BuildOptions.MaximumTriangleLength = 200; //surface.BuildOptions.UseMaximumTriangleLength = true; //// Add some LiDAR points Point3dCollection points = new Point3dCollection(); points = ReadPointCloudFile.ReadFile(path, filename); surface.AddVertices(points); SetSmoothing(surface, points); // commit the create action ts.Commit(); } }
RBA() { Surface surface = null; try { using (Transaction tr = BaseObjs.startTransactionDoc()) { ObjectIdCollection ids = BaseObjs._civDoc.GetSurfaceIds(); if (ids.Count == 0) { return; } foreach (ObjectId id in ids) { try { surface = (Surface)tr.GetObject(id, OpenMode.ForRead); if (surface is TinSurface) { TinSurface tinSurface = (TinSurface)surface; tinSurface.UpgradeOpen(); tinSurface.Rebuild(); tinSurface.DowngradeOpen(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " cmdRB.cs: line: 71"); } } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " cmdRB.cs: line: 79"); } }
public static ObjectId CroppingSurface5(TinSurface surface, Polyline border) { Document activeDoc = Tools.GetActiveAcadDocument(); Database sourceDb = activeDoc.Database; var points = border.GetPoints(); string surfaceName = "Cropped_" + surface.Name + "<[Next Counter(CP)]>"; using (Database destDb = new Database(true, false)) { HostApplicationServices.WorkingDatabase = destDb; ObjectId newSurfaceId = TinSurface.CreateByCropping(destDb, surfaceName, surface.Id, points); HostApplicationServices.WorkingDatabase = sourceDb; using (Transaction transDest = Tools.StartTransaction(destDb)) { TinSurface newSurface = transDest.GetObject(newSurfaceId, OpenMode.ForRead) as TinSurface; /*newSurface = newSurface.Clone() as TinSurface; * * newSurface.SetDatabaseDefaults(sourceDb); * Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = activeDoc; * Tools.AppendEntity(sourceDb, newSurface);*/ //newSurface = newSurface.Clone() as TinSurface; transDest.Commit(); newSurface = newSurface.Clone() as TinSurface; newSurface.SetDatabaseDefaults(sourceDb); newSurface.SetToStandard(sourceDb); newSurface.StyleId = surface.StyleId; IntPtr ptr = newSurface.UnmanagedObject; var obj = TinSurface.Create(ptr, false); using (Transaction srcTrans = Tools.StartTransaction(sourceDb)) { newSurfaceId = TinSurface.Create(sourceDb, "test_surface"); newSurface.SetDatabaseDefaults(sourceDb); newSurface.SetToStandard(sourceDb); newSurface.SetDefaultLayer(); newSurface.StyleId = surface.StyleId; //newSurface = srcTrans.GetObject(TinSurface.Create(sourceDb, "test_surface"), OpenMode.ForWrite) as TinSurface; //newSurface.CopyFrom(obj); newSurface.Rebuild(); srcTrans.Commit(); } using (Transaction srcTrans = Tools.StartTransaction(sourceDb)) { newSurface = srcTrans.GetObject(newSurfaceId, OpenMode.ForWrite) as TinSurface; newSurface.UpgradeOpen(); newSurface.CopyFrom(obj); //newSurface.Name = "test_surface2"; newSurface.SetDatabaseDefaults(sourceDb); newSurface.SetToStandard(sourceDb); newSurface.SetDefaultLayer(); newSurface.StyleId = surface.StyleId; newSurface.Rebuild(); srcTrans.Commit(); } using (Transaction srcTrans = Tools.StartTransaction(sourceDb)) { newSurface = srcTrans.GetObject(newSurfaceId, OpenMode.ForWrite) as TinSurface; newSurface.UpgradeOpen(); newSurface.SetDatabaseDefaults(sourceDb); newSurface.SetToStandard(sourceDb); newSurface.SetDefaultLayer(); srcTrans.Commit(); newSurface.Rebuild(); //newSurface.RebuildSnapshot(); newSurface.CreateSnapshot(); } //Tools.AppendEntity(sourceDb, obj as TinSurface); } } return(ObjectId.Null); }