BruteForceFindReferences(AcDb.Database database) { //App.Document mdiActiveDocument = App.Application.DocumentManager.MdiActiveDocument; //if (mdiActiveDocument == null) return; //AcDb.Database database = mdiActiveDocument.Database; using (var trHelp = database.TransactionManager.StartTransaction()) { m_count = 0; m_skipped = 0; // since we aren't calculating this in the destructor, we have to re-init every time they // do the drill-down. m_hardPointerIds.Clear(); AcDb.Database db = m_val.Database; // pass in all the root objects ProcessObject(trHelp, m_val, db.NamedObjectsDictionaryId); ProcessObject(trHelp, m_val, db.BlockTableId); ProcessObject(trHelp, m_val, db.DimStyleTableId); ProcessObject(trHelp, m_val, db.LayerTableId); ProcessObject(trHelp, m_val, db.LinetypeTableId); ProcessObject(trHelp, m_val, db.RegAppTableId); ProcessObject(trHelp, m_val, db.TextStyleTableId); ProcessObject(trHelp, m_val, db.UcsTableId); ProcessObject(trHelp, m_val, db.ViewportTableId); ProcessObject(trHelp, m_val, db.ViewTableId); trHelp.Commit(); } }
BruteForceFindReferences(TransactionHelper trHelp) { m_count = 0; m_skipped = 0; // since we aren't calculating this in the destructor, we have to re-init every time they // do the drill-down. m_hardPointerIds.Clear(); m_softPointerIds.Clear(); m_hardOwnershipIds.Clear(); m_softOwnershipIds.Clear(); AcDb.Database db = m_val.Database; // pass in all the root objects ProcessObject(trHelp, m_val, db.NamedObjectsDictionaryId); ProcessObject(trHelp, m_val, db.BlockTableId); ProcessObject(trHelp, m_val, db.DimStyleTableId); ProcessObject(trHelp, m_val, db.LayerTableId); ProcessObject(trHelp, m_val, db.LinetypeTableId); ProcessObject(trHelp, m_val, db.RegAppTableId); ProcessObject(trHelp, m_val, db.TextStyleTableId); ProcessObject(trHelp, m_val, db.UcsTableId); ProcessObject(trHelp, m_val, db.ViewportTableId); ProcessObject(trHelp, m_val, db.ViewTableId); //string str = string.Format("Visited: {0:d}, Skipped: {1:d}, DB Approx: {2:d}", m_count, m_skipped, db.ApproxNumObjects); //MessageBox.Show(str); }
private static ACADDB.ObjectIdCollection RefreshSelectionOfPolylines(ACADDB.ObjectIdCollection collection) { if (collection != null) { collection.Clear(); } return(Process.GetIdsByTypeTypeValue( "POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3d")); }
public static void LoadandProcessPolys() { using (DatabaseCommands commands = new DatabaseCommands()) { var TemplatePath = commands.GetTemplatePath(); #region Get Dwgs to Process var dwgs = commands.LoadandProcessPolys(); if (dwgs == null) { throw new ArgumentNullException(nameof(dwgs)); } IList <DrawingStack> DwDrawingStacks = new List <DrawingStack>(); foreach (var dwg in dwgs) { if (DwDrawingStacks != null) { DwDrawingStacks.Add(dwg); } } #endregion GDwgPath = commands.GetGlobalDWGPath(); GCloudPath = commands.GetGlobalPointCloudPath(); foreach (DrawingStack dwg in DwDrawingStacks) { m_PolylineChildren.Clear(); var acDocMgr = ACAD.Application.DocumentManager; Document acNewDoc = null; Document acDoc = ACAD.Application.DocumentManager.MdiActiveDocument; if (acDocMgr.Count == 1) { acNewDoc = acDocMgr.Add(TemplatePath); using (acDocMgr.MdiActiveDocument.LockDocument()) { acDocMgr.MdiActiveDocument = acDoc; acDocMgr.CurrentDocument.CloseAndDiscard(); acDocMgr.MdiActiveDocument = acNewDoc; } } using (acDocMgr.MdiActiveDocument.LockDocument()) { if (acDoc != null) { ACADDB.Database acDbNewDoc = acNewDoc.Database; //var ed = doc.Editor; string gpath = Convert.ToString(GDwgPath); if (gpath != null) { string path = Path.Combine(gpath, dwg.PolylineDwgName); if (path == null) { throw new ArgumentNullException(nameof(path)); } if (!File.Exists(path)) { DatabaseLogs.FormatLogs("File Not Found", path); return; } try { using (ACADDB.Database db = new ACADDB.Database(false, true)) { // Read the DWG file into our Database object db.ReadDwgFile( path, ACADDB.FileOpenMode.OpenForReadAndReadShare, false, "" ); // No graphical changes, so we can keep the preview // bitmap db.RetainOriginalThumbnailBitmap = true; // We'll store the current working database, to reset // after the purge operation var wdb = ACADDB.HostApplicationServices.WorkingDatabase; ACADDB.HostApplicationServices.WorkingDatabase = db; // Purge unused DGN linestyles from the drawing // (returns false if nothing is erased) collection = Process.GetIdsByTypeTypeValue( "POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3d"); NumberofPolylines = collection.Count; Process.CopyPolylinesBetweenDatabases(db, collection); // Still need to reset the working database datetime = (DateTime)dwg.DateStamp; ACADDB.HostApplicationServices.WorkingDatabase = wdb; string output = SetOutPutFolder(dwg, commands); // PLineToLayers.ProcessLayers(collection, wdb); string fileName = System.IO.Path.GetFileNameWithoutExtension(dwg.PolylineDwgName); outdxf = Path.Combine(output, String.Format("{0}{1}", fileName, ".dxf")); outdwg = Path.Combine(output, dwg.PolylineDwgName); collection.Clear(); //Before Simplification Create Breakline Data OriginalCollection = RefreshSelectionOfPolylines(collection); m_PolylineChildren = CreatePolylineChildren(OriginalCollection); } } catch (Exception e) { DatabaseLogs.FormatLogs("Exception: {0}", e.Message); } } } } PGA.SimplifyPolylines.Commands.SimplifyPolylines(); using (acDocMgr.MdiActiveDocument.LockDocument()) { try { Document acDocument = ACAD.Core.Application.DocumentManager.MdiActiveDocument; ACADDB.Database acDbNewDoc = acDocument.Database; // if (collection != null) collection.Clear(); //collection = RefreshSelectionOfPolylines(collection); collection = OriginalCollection; NumberofPolylines = collection.Count; //Check Polyline Count //Change Layer Names AssignNames.ChangeLayers(); // collection.Clear(); // get the copied collection of this drawing ///collection = RefreshSelectionOfPolylines(collection); //NumberofPolylines = collection.Count; //Get the Distinct LIDAR Points //var p3d = ProcessLidarFile( // PlineToPoints(collection), datetime, dwg.Hole.ToString()); var lidarFile = RetrieveLidarFile(datetime, dwg.Hole.ToString()); //Get the Nearest Neighbor to add to Point Set var neighbors = IncludeIntersectingNeighbor(lidarFile, OriginalCollection); Point3dCollection totalpoints = MergePoint3DCollections(lidarFile, neighbors); var p5d = ProcessLidarFile( PlineToPoints(collection), datetime, dwg.Hole.ToString(), totalpoints); //var p5d = ProcessLidarFileSubtractRegions( // PlineToPoints(collection), datetime, dwg.Hole.ToString(), totalpoints,collection); //Insert into DB InsertPointCloudToDB(dwg, datetime, p5d, PlineToPoints(collection)); //Create all the Distinct surfaces CreateTinForDistinctSurfaces(p5d, collection); acDbNewDoc.SaveAs(outdwg, ACADDB.DwgVersion.Current); acDbNewDoc.DxfOut(outdxf, 16, ACADDB.DwgVersion.Current); } catch (ACADRT.Exception ex) { DatabaseLogs.FormatLogs("Exception: {0}", ex.Message); } } } } }