Example #1
0
 public static ObjectIdCollection GetAllPolylines()
 {
     return(Process.GetIdsByTypeTypeValue(
                "POLYLINE",
                "LWPOLYLINE",
                "POLYLINE2D"));
 }
Example #2
0
        private static ACADDB.ObjectIdCollection RefreshSelectionOfPolylines(ACADDB.ObjectIdCollection collection)
        {
            if (collection != null)
            {
                collection.Clear();
            }

            return(Process.GetIdsByTypeTypeValue(
                       "POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3d"));
        }
Example #3
0
        //[CommandMethod("DWG_Open")]
        public static void OpenDwgForReadWrite(string fileName)
        {
            Document doc =
                Application.DocumentManager.MdiActiveDocument;


            if (!System.IO.File.Exists(fileName))
            {
                throw new FileNotFoundException(fileName);
            }

            // Create a database and try to load the file
            ACADDB.Database db = new ACADDB.Database(false, true);
            using (db)
            {
                try
                {
                    db.ReadDwgFile(
                        fileName,
                        System.IO.FileShare.ReadWrite,
                        false,
                        ""
                        );

                    var wdb = ACADDB.HostApplicationServices.WorkingDatabase;
                    ACADDB.HostApplicationServices.WorkingDatabase = db;

                    // Purge unused DGN linestyles from the drawing
                    // (returns false if nothing is erased)
                    ACADDB.ObjectIdCollection collection = Process.GetIdsByTypeTypeValue(
                        "POLYLINE", "LWPOLYLINE", "POLYLINE2D");

                    Process.CopyPolylinesBetweenDatabases(db, collection);


                    // Still need to reset the working database

                    ACADDB.HostApplicationServices.WorkingDatabase = wdb;
                }
                catch (System.Exception)
                {
                    COMS.MessengerManager.AddLog(String.Format(
                                                     "Unable to read drawing file.",
                                                     db.FingerprintGuid.ToString())
                                                 );
                    return;
                }
            }

            Application.DocumentManager.MdiActiveDocument = doc;
        }
Example #4
0
        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);
                        }
                    }
                }
            }
        }