public static CivilTinSurface FindSurfaceIdForPolylineV2(ObjectId oid) { try { foreach (KeyValuePair <ObjectId, string> id in m_polylinesonly) { if (id.Key == null) { continue; } if (oid == id.Key) { Debug.WriteLine("Match iod" + oid + "and" + id.Key); return(CivilTinSurface.CreateFromExisting(id.Value)); } Debug.WriteLine("NO match iod" + oid + "and" + id.Key); } } catch (System.Exception e) { ACADLogging.LogMyExceptions("FindSurfaceIdForPolylineV2" + e.Message); } return(null); }
public CivilTinSurface CreateSelectedSurface(Autodesk.AutoCAD.DatabaseServices.ObjectId oid) { try { ACADLogging.LogMyExceptions("Start CreateSelectedSurface Method"); string surfaceName = GetPolyLayerFromOid((oid)); string surfaceStyleName = GetPolyLayerFromOid((oid)); //layer and style name are the same name. // m_polylinesurfaces = new Dictionary<ObjectId, string>(); int i = 0; //string tempSurface = "s-" + surfaceName.ToLower(); string tempSurface = surfaceName.ToUpper(); while (CivilTinSurface.FindCivilTinSurfaceByName(tempSurface, "")) { tempSurface = string.Format("{0}-{1}", surfaceName, i++); } surfaceName = tempSurface; if (!SurfaceStyleManager.Exists(surfaceStyleName)) { string msg = String.Format("\nSurface Style '{0}' doesn't exist. Creating it with default values.", surfaceStyleName); //EditorUtils.Write(msg); SurfaceStyleManager.CreateDefault(surfaceStyleName); } CivilTinSurface surface = new CivilTinSurface(surfaceName, surfaceStyleName); m_polylinesurfaces.Add(CivilTinSurface.FindCivilTinSurfaceByName(surface.Name), surfaceName); m_polylinesonly.Add(oid, surfaceName); return(surface); } catch (System.Exception ex) { ACADLogging.LogMyExceptions("CreateSelectedSurface" + ex.Message); } return(null); }
public bool CreateSurfaceForPolylines(ObjectIdCollection polylines) { try { foreach (ObjectId polyline in polylines) { try { ACADLogging.LogMyExceptions("Starting CreateSurfaceForPolylines"); CreateSelectedSurface(polyline); ACADLogging.LogMyExceptions("End CreateSurfaceForPolylines"); } catch (System.Exception e) { ACADLogging.LogMyExceptions(e.Source, e); } } return(true); } catch (System.Exception e) { ACADLogging.LogMyExceptions(e.Source, e); } return(false); }
public static void ExportSurfaceObjects() { PasteSurfaces surfaceManager = new PasteSurfaces(); Database db = Application.DocumentManager.MdiActiveDocument.Database; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; try { ObjectIdCollection surfaces = surfaceManager.GetAllSurfaces(); foreach (ObjectId surfaceId in surfaces) { using (Transaction trans = db.TransactionManager.StartTransaction()) { TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForWrite) as TinSurface; surface.GetTriangles(true); trans.Commit(); } } } catch (Exception e) { ACADLogging.LogMyExceptions(e.Message); } }
public static bool ProcessLineWork() { bool flag; IList <string> strs = new List <string>(); Database workingDatabase = CivilApplicationManager.WorkingDatabase; Application.get_DocumentManager().get_MdiActiveDocument(); ObjectIdCollection objectIdCollection = new ObjectIdCollection(); ObjectIdCollection list = new ObjectIdCollection(); PGA.MapClean.MapClean mapClean = new PGA.MapClean.MapClean(); try { strs = LayerManager.GetLayerNames(workingDatabase); objectIdCollection = PGA.MapClean.MapClean.GetSelection(); if (objectIdCollection.get_Count() == 0) { flag = false; } else if (strs.Count != 0) { foreach (string str in strs) { list = PGA.MapClean.MapClean.AddToList(objectIdCollection); ACADLogging.LogMyExceptions(string.Format("MapClean:{0} {1}", "Starting layer: ", str)); try { list = PGA.MapClean.MapClean.FilterResults(str, list); if (list.get_Count() == 0) { continue; } } catch { continue; } if ((!str.StartsWith("S") ? false : str.Length > 3)) { mapClean.DrawingCleanUp(str, list); } ACADLogging.LogMyExceptions(string.Format("MapClean:{0} {1}", "Ending layer: ", str)); } flag = true; } else { flag = false; } } catch (Exception exception1) { Exception exception = exception1; ACADLogging.LogMyExceptions(string.Format("MapClean:{0} {1}", exception.Message, exception.InnerException)); flag = false; return(flag); } return(flag); }
public void LogTextTraceWriterTest() { var message = "Test My Values"; // TODO: Initialize to an appropriate value var expected = 0; // TODO: Initialize to an appropriate value int actual; actual = ACADLogging.LogTextTraceWriter(message); Assert.AreEqual(expected, actual); }
public static void DrawingCleanUp(string layername, ObjectIdCollection polys) { if (String.IsNullOrEmpty(layername)) { throw new ArgumentNullException(layername); } try { Autodesk.Gis.Map.Topology.Variable cadAction = new Autodesk.Gis.Map.Topology.Variable(); string appfolder = PGA.Autodesk.Settings.AcadSettings.AppFolderScriptPath; string filepath = System.IO.Path.Combine(appfolder, "MapClean", layername + ".dpf"); if (!System.IO.File.Exists(filepath)) { throw new FileNotFoundException(filepath); } cadAction.LoadProfile(filepath); using (Autodesk.Gis.Map.Topology.TopologyClean cadCleanobj = new Autodesk.Gis.Map.Topology.TopologyClean()) { cadCleanobj.Init(cadAction, null); cadCleanobj.Start(); cadCleanobj.GroupNext(); while (!cadCleanobj.Completed) { if (cadCleanobj.GroupErrorCount > 0) { try { cadCleanobj.GroupFix(); } catch { //No Need to Log// } } cadCleanobj.GroupNext(); } cadCleanobj.End(); } } catch (System.Exception ex) { ACADLogging.LogMyExceptions(String.Format("MapClean:{0}:{1}", layername, ex.Message)); } }
public static void MapClean() { try { PGA.MapClean.MapClean.ProcessLineWork(); } catch (Exception exception) { ACADLogging.LogMyExceptions(string.Concat("MapClean", exception.Message)); } }
public static void MapClean() { try { C3DSurfacesDemo.MapClean.ProcessLineWork(); } catch (Exception ex) { ACADLogging.LogMyExceptions("MapClean" + ex.Message); } }
internal static void ListInternalPolylines(Dictionary <ObjectId, ObjectIdCollection> m_dict) { foreach (var obj in m_dict.Keys) { ACADLogging.LogMyExceptions(obj + "******Key ********" + obj); foreach (ObjectIdCollection collection in m_dict.Values) { ACADLogging.LogMyExceptions("******Collection********"); foreach (ObjectId polylines in collection) { ACADLogging.LogMyExceptions(polylines.Handle.ToString()); } } } }
public static bool ProcessLineWork() { IList <string> layernames = new List <string>(); Database db = CivilApplicationManager.WorkingDatabase; Document doc = Application.DocumentManager.MdiActiveDocument; ObjectIdCollection polys = new ObjectIdCollection(); try { layernames = BBC.Common.AutoCAD.LayerManager.GetLayerNames(db); polys = GetSelection(); if (layernames.Count == 0) { return(false); } foreach (string layer in layernames) { if (layer.Length <= 3) { continue; } else if (layer.StartsWith("S")) { DrawingCleanUp(layer, polys); } } return(true); } catch (Exception ex) { ACADLogging.LogMyExceptions(string.Format( "MapClean:{0} {1}", ex.Message , ex.InnerException) ); } return(false); }
public bool AddBoundariesForSurfaces(ObjectIdCollection polylines) { try { foreach (KeyValuePair <ObjectId, string> pair in m_polylinesonly) { try { //Test for Complexity if (PolylineUtils.ExcludePolyBasedOnComplexity(pair.Key)) { continue; } #region Create Outer Boundary PGA.Civil.Logging.ACADLogging.LogMyExceptions("Start AddBoundariesForSurfaces"); using (Transaction tr = CivilApplicationManager.StartTransaction()) { ObjectId lObjectId = new ObjectId(); lObjectId = CivilTinSurface.FindCivilTinSurfaceByName(pair.Value); //1. Create new surface if no existing surface passed in TinSurface surface = lObjectId.GetObject(OpenMode.ForRead) as TinSurface; //2. Store boundary ObjectIdCollection boundaryEntities = new ObjectIdCollection(); boundaryEntities = GetObjectIdCollectionFromEntity(pair.Key); //3. Access the BoundariesDefinition object from the surface object SurfaceDefinitionBoundaries surfaceBoundaries = surface.BoundariesDefinition; //4. now add the boundary to the surface (for non-destructive set true) try { surfaceBoundaries.AddBoundaries(boundaryEntities, 1.0, SurfaceBoundaryType.Outer, true); } catch (System.Exception) { PGA.Civil.Logging.ACADLogging.LogMyExceptions("Error AddBoundariesForSurfaces"); } PGA.Civil.Logging.ACADLogging.LogMyExceptions("End AddBoundariesForSurfaces"); tr.Commit(); } #endregion } catch (System.Exception ex) { ACADLogging.LogMyExceptions("Error in loop AddBoundariesForSurfaces" + ex.Message); } } return(true); } catch (System.Exception ex) { ACADLogging.LogMyExceptions("Error in AddBoundariesForSurfaces" + ex.Message); } return(false); }
public void DrawingCleanUp(string layername, ObjectIdCollection polys) { Exception exception; try { if (string.IsNullOrEmpty(layername)) { throw new ArgumentNullException(layername); } Variable variable = new Variable(); string appFolderScriptPath = AcadSettings.get_AppFolderScriptPath(); string str = Path.Combine(appFolderScriptPath, "MapClean", string.Concat(layername, ".dpf")); if (!File.Exists(str)) { throw new FileNotFoundException(str); } variable.LoadProfile(str); TopologyClean topologyClean = new TopologyClean(); try { try { topologyClean.Init(variable, polys); } catch (MapTopologyException mapTopologyException1) { MapTopologyException mapTopologyException = mapTopologyException1; ACADLogging.LogMyExceptions(string.Format("MapClean:{0}:{1}", layername, string.Concat("Initialization Error ", mapTopologyException.Message))); return; } topologyClean.Start(); topologyClean.GroupNext(); while (!topologyClean.get_Completed()) { ACADLogging.LogMyExceptions(string.Format("MapClean:{0}:{1}", (int)topologyClean.get_GroupErrorCount(), "cadCleanobj.GroupErrorCount")); if (topologyClean.get_GroupErrorCount() > 0) { try { topologyClean.GroupFix(); } catch (Exception exception1) { exception = exception1; ACADLogging.LogMyExceptions(string.Format("MapClean:{0}:{1}", layername, "Group Fix")); } } topologyClean.GroupNext(); } topologyClean.End(); } finally { if (topologyClean != null) { topologyClean.Dispose(); } } } catch (Exception exception2) { exception = exception2; ACADLogging.LogMyExceptions(string.Format("MapClean:{0}:{1}", layername, exception.Message)); } }
public void RebuildAllSurfaces() { try { var polylines = new ObjectIdCollection(); Dictionary <ObjectId, ObjectIdCollection> m_dict; var surfaceManager = new PasteSurfaces(); m_dict = new Dictionary <ObjectId, ObjectIdCollection>(); if (CivilTinSurface.FindCivilTinSurface("All")) { #region get polylines and generate surfaces and boundaries polylines = surfaceManager.GetAllPolyLines(); #endregion ObjectIdCollection internalPLines = null; foreach (ObjectId baseObj in polylines) { #region store the internal boundaries for the selected base object in dict if (GetPolyFromObjId(baseObj) == null) { continue; } internalPLines = surfaceManager.GetAllInternalPolyLinesToSelected(baseObj, polylines, minpolyseparation); m_dict.Add(baseObj, internalPLines); #endregion } #region Iterate through inner boundaries CivilTinSurface lsurface = null; foreach (KeyValuePair <ObjectId, ObjectIdCollection> innerbdy in m_dict) { #region Removed //#region Create Surface for that Base Polyline and Add outer boundary //if ((lsurface = (surfaceManager.CreateSelectedSurface(baseObj))) == null) // throw new Exception("CreateSelectedSurface Failed!"); //lsurface.AddStandardBoundary(baseObj, "OuterBoundary"); //#endregion #endregion if (innerbdy.Value == null) { continue; } ObjectId outerPline = innerbdy.Key; ObjectIdCollection innerIdCollection = innerbdy.Value; lsurface = PasteSurfaces.FindSurfaceIdForPolylineV2(outerPline); if (lsurface == null) { continue; } #region Interate Internal Polylines to add breaklines and boundaries if (innerIdCollection != null) { foreach (ObjectId pLines in innerIdCollection) { try { #region Breaklines Deprecated //Breaklines removed due to overlapping //lsurface.AddStandardBreakline // (PasteSurfaces.GetPolyPointsByObjectId(pLines), "Breakline-"); #endregion lsurface.AddStandardInnerBoundary(pLines, "Boundary-"); } catch (NullReferenceException e) { ACADLogging.LogMyExceptions("AddAsInnerBoundary Failed: " + e.Message); //throw new Exception(e.Message); } internalPLines = null; } } #endregion #region Rebuild Surfaces if (lsurface != null) { CivilTinSurface.RebuildSurfaceBySurfaceName(lsurface.Name); } #endregion #region Regenerate Graphics EditorUtils.Regen(); #endregion } #endregion internalPLines = null; } else { throw new FileNotFoundException( "Did not find the surface ALL!"); } EditorUtils.Write("\nRebuild Surfaces Complete!\n"); } catch (NullReferenceException e) { EditorUtils.Write(e.StackTrace); ACADLogging.LogMyExceptions(e.Message); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ACADLogging.LogMyExceptions(e.Message); } catch (Exception e) { ACADLogging.LogMyExceptions(e.Message); } }
public void CreateAllSurfaces() { try { var polylines = new ObjectIdCollection(); Dictionary <ObjectId, ObjectIdCollection> m_dict; var surfaceManager = new PasteSurfaces(); m_dict = new Dictionary <ObjectId, ObjectIdCollection>(); #region Steps //1 Create Overall Surface //2 Create new Surface with Defaults //3 Open new Surface to Paste Overall Surface //4 Select Surface to Paste Overall Surface Into //5 Add Boundary to New Surface //1 Select All Polylines //2 Determine if boundaries are needed to be type inner or outer //3 Filter Polylines based on layer name. May be able to know the type. #endregion try { sminpolyseparation = EditorUtils.PromptForString("\nEnter polyline separation distance (0.05'): "); if (String.IsNullOrEmpty(sminpolyseparation)) { minpolyseparation = 0.05; } else { minpolyseparation = Convert.ToDouble(sminpolyseparation); } } catch (Exception) { minpolyseparation = 0.05; //set default } if (CivilTinSurface.FindCivilTinSurface("All")) { #region Insert Point Cloud into Overall Surface #endregion #region get polylines and generate surfaces and boundaries polylines = surfaceManager.GetAllPolyLines(); //Create a surface hive to generate a TIN surface if (!surfaceManager.CreateSurfaceForPolylines(polylines)) { throw new SystemException("Create surface for polylines failed!"); } if (!surfaceManager.PasteAllSurfaces(CivilTinSurface.GetCivilSurfaceBySurfaceName("All"))) { throw new SystemException("Pasting Surfaces failed!"); } if (!surfaceManager.AddBoundariesForSurfaces(polylines)) { throw new SystemException("Add overall Boundaries for surfaces failed!"); } #endregion ACADLogging.LogMyExceptions("Store boundaries to Object Dictionary"); ObjectIdCollection internalPLines = null; foreach (ObjectId baseObj in polylines) { #region store the internal boundaries for the selected base object in dict if (GetPolyFromObjId(baseObj) == null) { continue; } internalPLines = surfaceManager.GetAllInternalPolyLinesToSelected(baseObj, polylines, minpolyseparation); m_dict.Add(baseObj, internalPLines); //if (internalPLines == null) continue; #endregion } #region Iterate through inner boundaries ACADLogging.LogMyExceptions("Start Iterate through inner boundaries"); CivilTinSurface lsurface = null; foreach (KeyValuePair <ObjectId, ObjectIdCollection> innerbdy in m_dict) { #region Removed //#region Create Surface for that Base Polyline and Add outer boundary //if ((lsurface = (surfaceManager.CreateSelectedSurface(baseObj))) == null) // throw new Exception("CreateSelectedSurface Failed!"); //lsurface.AddStandardBoundary(baseObj, "OuterBoundary"); //#endregion #endregion if (innerbdy.Value == null) { continue; } ObjectId outerPline = innerbdy.Key; ObjectIdCollection innerIdCollection = innerbdy.Value; lsurface = PasteSurfaces.FindSurfaceIdForPolylineV2(outerPline); if (lsurface == null) { continue; } #region Interate Internal Polylines to add breaklines and boundaries ACADLogging.LogMyExceptions("Start AddStandardInnerBoundary"); if (innerIdCollection != null) { foreach (ObjectId pLines in innerIdCollection) { if (pLines == null) { continue; } try { #region Breaklines Deprecated //Breaklines removed due to overlapping //lsurface.AddStandardBreakline // (PasteSurfaces.GetPolyPointsByObjectId(pLines), "Breakline-"); #endregion lsurface.AddStandardInnerBoundary(pLines, "Boundary-"); } catch (NullReferenceException e) { ACADLogging.LogMyExceptions("AddAsInnerBoundary Failed: " + e.Message); } catch (Exception e) { ACADLogging.LogMyExceptions("AddAsInnerBoundary Failed: " + e.Message); } internalPLines = null; } } ACADLogging.LogMyExceptions("End AddStandardInnerBoundary"); #endregion #region Rebuild Surfaces ACADLogging.LogMyExceptions("Start RebuildSurfaceBySurfaceName"); if (lsurface != null) { CivilTinSurface.RebuildSurfaceBySurfaceName(lsurface.Name); } #endregion } #endregion internalPLines = null; ACADLogging.LogMyExceptions("End Iterate through inner boundaries"); } else { EditorUtils.Write("Missing 'All' Surface. Create Surfaces Incomplete!"); throw new FileNotFoundException( "Did not find the surface ALL!"); } EditorUtils.Write("Create Surfaces Complete!\n"); } catch (NullReferenceException e) { Console.WriteLine(e.StackTrace); ACADLogging.LogMyExceptions(e.Message); } catch (Autodesk.AutoCAD.Runtime.Exception e) { ACADLogging.LogMyExceptions(e.Message); } catch (Exception e) { ACADLogging.LogMyExceptions(e.Message); } }
public static bool ExcludePolyBasedOnComplexity(ObjectId oid) { if (oid == null) { return(true); } bool result = false; //include by default Database db = HostApplicationServices.WorkingDatabase; Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; using (Transaction tr = db.TransactionManager.StartTransaction()) { try { DBObject ent = (DBObject)tr.GetObject(oid, OpenMode.ForRead); if (ent == null) { return(false); } //Polyline poly = (Polyline)ent as Polyline; Curve curv = ent as Curve; DBObjectCollection pcurves = new DBObjectCollection(); curv.Explode(pcurves); TypedValue[] values = new TypedValue[] { new TypedValue(0, "lwpolyline") }; SelectionFilter filter = new SelectionFilter(values); Point3dCollection fence = new Point3dCollection(); double leng = curv.GetDistanceAtParameter(curv.EndParam) - curv.GetDistanceAtParameter(curv.StartParam); // number of divisions along polyline to create fence selection //double step = leng / 256;// set number of steps to your suit double step = leng / pcurves.Count; if ((leng > 1000 || pcurves.Count > 3000) && (step < 1.0)) { result = true; // too complex } if (pcurves.Count > 10000) { result = true; } if (result) { ACADLogging.LogMyExceptions( String.Format("\nExcluded Polyline: {0}\nComplexity: {1}\nLayer: {2}\n", pcurves.Count, step.ToString("n3"), curv.Layer)); } tr.Commit(); } catch (System.Exception ex) { ACADLogging.LogMyExceptions(String.Format("\n{0}\n{1}", ex.Message, ex.StackTrace)); } return(result); } }