public void Create(string m_Name, string m_Stylename, string m_Description) { Editor ed = acadDoc.Editor; ObjectId m_SurfaceId = ObjectId.Null; using (Transaction tr = acadDoc.Database.TransactionManager.StartTransaction()) { try { CivilDocument civDoc = CivilApplication.ActiveDocument; ObjectId objStyl = civDoc.Styles.SurfaceStyles[m_Stylename]; m_SurfaceId = TinSurface.Create(m_Name, objStyl); ts = m_SurfaceId.GetObject(OpenMode.ForRead) as TinSurface; ts.Description = m_Description; } catch (System.Exception ex) { ed.WriteMessage("\nError: Missing Surfacestyle!"); } finally { tr.Commit(); } } }
/// <summary> /// Create the suface /// </summary> /// <param name="solidSurfaceName">Name of the surface</param> /// <param name="simplifySurface">Apply simplify /// operation</param> private static void CreateSolidSurface( string solidSurfaceName, bool simplifySurface) { // open or create the new surface TinSurface newSurface = null; ObjectId newSurfaceId = Util.GetSurfaceId(solidSurfaceName); if (!newSurfaceId.IsNull) { // open, remove all points and operations newSurface = _trans.GetObject(newSurfaceId, OpenMode.ForWrite) as TinSurface; newSurface.DeleteVertices(newSurface.Vertices); } else { // create and open newSurfaceId = TinSurface.Create(_db, solidSurfaceName); newSurface = _trans.GetObject(newSurfaceId, OpenMode.ForWrite) as TinSurface; } // add the newly created points newSurface.AddVertices(_newPoints); // simplify surface if (simplifySurface) { SurfaceSimplifyOptions simplifyOptions = new SurfaceSimplifyOptions(SurfaceSimplifyType.PointRemoval); simplifyOptions.MaximumChangeInElevation = 0.0001; simplifyOptions.UseMaximumChangeInElevation = true; newSurface.SimplifySurface(simplifyOptions); } }
private void CreateSurface() { ObjectId styleId = Active.CivilDocument.Styles.SurfaceStyles[_styleName]; ObjectId surfaceId = TinSurface.Create(Active.Database, _surfaceName); _surface = (TinSurface)_trans.GetObject(surfaceId, OpenMode.ForWrite); _surface.StyleId = styleId; _surface.BuildOptions.UseMaximumTriangleLength = true; _surface.BuildOptions.MaximumTriangleLength = 41; _surface.Layer = _layername; }
//[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(); } }
getTinSurface(string nameSurf, out bool exists) { TinSurface objSurface = null; ObjectId idStyle = ObjectId.Null; exists = false; try { using (Transaction tr = BaseObjs.startTransactionDoc()) { ObjectIdCollection surfaceIDs = BaseObjs._civDoc.GetSurfaceIds(); foreach (ObjectId surfaceID in surfaceIDs) { Autodesk.Civil.DatabaseServices.TinSurface objTinSurface = (TinSurface)surfaceID.GetObject(OpenMode.ForRead); if (objTinSurface.Name == nameSurf) { objSurface = objTinSurface; exists = true; tr.Commit(); return(objSurface); } } foreach (ObjectId idSty in BaseObjs._civDoc.Styles.SurfaceStyles) { SurfaceStyle style = (SurfaceStyle)tr.GetObject(idSty, OpenMode.ForRead); if (style.Name == nameSurf) { idStyle = idSty; break; } } if (idStyle == ObjectId.Null) { idStyle = BaseObjs._civDoc.Styles.SurfaceStyles[0]; } ObjectId idSurf = TinSurface.Create(nameSurf, idStyle); objSurface = (TinSurface)tr.GetObject(idSurf, OpenMode.ForWrite); Layer.manageLayers(string.Format("{0}_SURFACE", nameSurf)); objSurface.Layer = string.Format("{0}_SURFACE", nameSurf); tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 143", ex.Message)); } return(objSurface); }
/// <summary> /// Create surfaces by PlanFeatures' names (as empty structures) /// </summary> public static void CreateSurfaces() { //Document doc = doc_dyn.AcDocument; var CivilApp = CivilApplication.ActiveDocument; Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction ts = db.TransactionManager.StartTransaction()) { foreach (ObjectId OneSiteItem in CivilApp.GetSiteIds()) { Site OneSite = ts.GetObject(OneSiteItem, OpenMode.ForRead) as Site; string Site_Name = OneSite.Name; bool IsSurfaceInDrawing = false; foreach (ObjectId SurfaceId in CivilApp.GetSurfaceIds()) { TinSurface OneSurf = ts.GetObject(SurfaceId, OpenMode.ForRead) as TinSurface; if (OneSurf.Name == Site_Name) { IsSurfaceInDrawing = true; break; } } if (IsSurfaceInDrawing == true) { continue; } try { ObjectId SurfaceStyle = CivilApp.Styles.SurfaceStyles[0]; ObjectId tinSurfaceId = TinSurface.Create(Site_Name, SurfaceStyle); } catch (System.Exception e) { ed.WriteMessage(e.Message); } } ts.Commit(); } }
addTinSurface(string nameSurf, out bool exists) { TinSurface surfTin = null; Surface surf = null; exists = false; try { using (Transaction tr = BaseObjs.startTransactionDoc()) { ObjectIdCollection ids = BaseObjs._civDoc.GetSurfaceIds(); foreach (ObjectId id in ids) { surf = (Surface)tr.GetObject(id, OpenMode.ForRead); if (surf is TinSurface) { surfTin = (TinSurface)surf; if (surfTin.Name == nameSurf) { exists = true; break; } } } if (!exists) { ObjectId idSurf = TinSurface.Create(BaseObjs._db, nameSurf); surfTin = (TinSurface)tr.GetObject(idSurf, OpenMode.ForWrite); surfTin.Layer = string.Format("{0}-SURFACE", nameSurf); } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(string.Format("{0} Surf.cs: line: 32", ex.Message)); } return(surfTin); }
getSurfaceFromXRef(string nameSurf, string strSource) { string nameXRef = ""; if (nameSurf == "CPNT-ON") { nameXRef = "GCAL"; } if (nameSurf == "EXIST") { nameXRef = "CONT"; } ResultBuffer rb = xRef.getXRefsContainingTargetDwgName(nameXRef); TypedValue[] tvs = rb.AsArray(); switch (tvs.Length) { case 0: Application.ShowAlertDialog(string.Format("{0} not attached", nameXRef = (nameSurf == "CPNT-ON") ? "GCAL" : "CONT")); break; case 2: foreach (TypedValue tv in tvs) { if (tv.TypeCode == 1001) { nameXRef = tv.Value.ToString(); } } break; default: string prompt = string.Format("Multible {0} are attached. Select one to use for staking: ", nameXRef = (nameSurf == "CPNT-ON") ? "GCAL" : "CONT"); Application.ShowAlertDialog(prompt); fPickXref = Forms.Stake_Forms.sForms.fPickXref; foreach (TypedValue tv in tvs) { if (tv.TypeCode == 1001) { fPickXref.lboxSelectXref.Items.Add(tv.Value.ToString()); } } fPickXref.Text = string.Format("Multible {0} are attached. Select one to use for staking: ", nameXRef = (nameSurf == "CPNT-ON") ? "GCAL" : "CONT"); Application.ShowModalDialog(null, fPickXref, false); nameXRef = fPickXref.nameXRef; if (nameXRef == "") { return; } break; } Surf.removeSurface(nameSurf); BlockReference br = xRef.getXRefBlockReference(nameXRef); TinSurface s = xRef.getXRefTinSurface(br.Id, nameSurf); if (s == null) { return; } string nameLayer = string.Format("{0}-SURFACE", nameSurf); if (nameSurf == "CPNT-ON") { nameLayer = "CPNT-SURFACE"; } Layer.manageLayers(nameLayer); TinSurface surf = null; string nameStyle = "CPNT-ON"; using (Transaction tr = BaseObjs.startTransactionDb()) { if (nameSurf == "CONT") { nameStyle = "EXIST"; } ObjectId idStyle = Surf_Styles.getSurfaceStyle(nameStyle); ObjectId idSurf = TinSurface.Create(nameSurf, idStyle); surf = (TinSurface)idSurf.GetObject(OpenMode.ForWrite); surf.Layer = nameLayer; surf.Description = string.Format("COPIED FROM {0} - {1}", nameXRef, DateTime.Now); tr.Commit(); } surf.PasteSurface(s.ObjectId); Layer.manageLayer(nameLayer, layerFrozen: true); if (nameSurf == "CPNT-ON") { if (strSource == "STAKE") { sFrms.sForms.fStake.SurfaceCPNT = surf; } } }
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); }