Beispiel #1
0
        /// <summary>
        /// Gets the name of the polyline.
        /// </summary>
        /// <param name="points">The points.</param>
        /// <param name="index">The index.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private static bool GetPolylineName(Point2dCollection points, int index)
        {
            DatabaseLogs.FormatLogs(String.Format("Polyline Position= {0} - Vertices= {1}",
                                                  index, points.Count));

            return(true);
        }
        }                                              // some property

        /// <summary>
        /// Handles the Click event of the cmdRepair control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private async void cmdRepair_Click(object sender, RoutedEventArgs e)
        {
            DatabaseCommands commands = new DatabaseCommands();

            try
            {
                using (SqlCeEngine engine = new SqlCeEngine(commands.GetConnectionString()))
                {
                    ConnectionStringSettings conSetting = new ConnectionStringSettings();
                    conSetting = ConfigHelper.save_new_connection(commands.GetConnectionString());

                    // engine.Repair(conSetting.ConnectionString, RepairOption.RecoverAllPossibleRows);
                    await CallEngineRepairAsync();
                }
            }
            catch (SqlCeException ex)
            {
                foreach (SqlCeError error in ex.Errors)
                {
                    DatabaseLogs.FormatLogs("SQLCeException: " + error.Message);
                }
                PGA.MessengerManager.MessengerManager.ShowMessage((ex.Message));
            }
            PGA.MessengerManager.MessengerManager.ShowMessage(("Complete!"));
        }
Beispiel #3
0
        public static void InsertPointCloudToDB(DrawingStack dwg, DateTime time, IList <Point3dCollection> pointsList, IList <Point2dCollection> boundaryList)
        {
            var UPPER = pointsList.Count;

            using (DatabaseCommands commands = new DatabaseCommands())
            {
                try
                {
                    for (int i = 0; i < UPPER; i++)
                    {
                        if (((pointsList[i].Count == 0) || boundaryList[i].Count == 0))
                        {
                            throw new ArgumentNullException(string.Format("PointsList: {0}", pointsList[i].Count));
                        }
                        //Store as Points
                        SqlBytes p = GeometryManager.SerializeSqlGeographyMultiPoint(pointsList[i]);
                        SqlBytes b = GeometryManager.SerializeSqlGeographyMultiPoint(boundaryList[i]);
                        commands.InsertNewPolylineGeometry(dwg, time, GeometryManager.ToBytes(b),
                                                           GeometryManager.ToBytes(p));
                    }
                }

                catch
                (Exception ex)
                {
                    DatabaseLogs.FormatLogs(ex.Message);
                }
            }
        }
        public static void AddLog(string str, Exception message)
        {
            var target = message.TargetSite;
            var source = message.Source;
            var stack  = message.StackTrace;

            DatabaseLogs.FormatLogs(string.Format("Alert! {0}-{1}-{2}", target, source, stack));
        }
Beispiel #5
0
        public static void SimplifyPolylinesTest()
        {
            // Get the document
            var doc = Application.DocumentManager.MdiActiveDocument;
            IList <Point2dCollection> point2DCollections = new List <Point2dCollection>();
            IList <Point2dCollection> reducedCollection  = new List <Point2dCollection>();
            Point2dCollection         sortedCollection   = new Point2dCollection();
            double tolerance = 0.001;

            try
            {
                //Select Polyline Objects
                ObjectIdCollection collection = GetIdsByTypeTypeValue("POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3D");

                if (collection == null || collection.Count == 0)
                {
                    return;
                }

                using (DocumentLock doclock = doc.LockDocument())
                {
                    //Get Point Collection of Polylines
                    foreach (ObjectId obj in collection)
                    {
                        point2DCollections.Add(GetPoint2dFromPolylines(obj));

                        //Log Original Information
                        GetPolylineName(obj, collection.IndexOf(obj));
                    }

                    foreach (Point2dCollection pnt2DCol in point2DCollections)
                    {
                        int            index = point2DCollections.IndexOf(pnt2DCol);
                        Point2d[]      reducedPoints;
                        List <Point2d> list = new List <Point2d>(pnt2DCol.ToArray());

                        //Reduce Polylines
                        reducedPoints = DouglasPeuckerImplementation.DouglasPeuckerReduction(list, tolerance);
                        reducedCollection.Add(ConvertCollections(reducedPoints));


                        sortedCollection = SortModified(list, ConvertCollections(reducedPoints));
                        // Add Reduced Polylines to Database
                        //CreateNewPolyliness(null, sortedCollection);
                        ModifyPolylineVertices(sortedCollection, collection[index]);
                        //Store Polyline Information

                        //Log Polyline Information
                        GetPolylineName(sortedCollection, point2DCollections.IndexOf(pnt2DCol));
                        index++;
                    }
                }
            }
            catch (System.Exception ex)
            {
                DatabaseLogs.FormatLogs("SimplifyPolylines: " + ex.Message);
            }
        }
        public static void ShowMessageAlert(Exception message)
        {
            var target = message.TargetSite;
            var source = message.Source;
            var stack  = message.StackTrace;

            MessageBox.Show("Alert! " + message.Message);
            DatabaseLogs.FormatLogs(string.Format("Alert! {0}-{1}-{2}", target, source, stack));
        }
 /// <summary>
 /// Handles the Click event of the cmdClearCache control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
 private async void cmdClearCache_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (DatabaseCommands commands = new DatabaseCommands())
         {
             await CallEngineClearCacheAsync();
         }
     }
     catch (Exception ex1)
     {
         DatabaseLogs.FormatLogs("cmdClear_Click: " + ex1.Message);
     }
 }
Beispiel #8
0
        public static void ChangeLayers()
        {
            // Get the document
            try
            {
                var doc = Application.DocumentManager.MdiActiveDocument;

                using (DocumentLock dlock = doc.LockDocument())
                {
                    ObjectIdCollection collection = Layers.GetIdsByTypeTypeValue("POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3D");

                    Layers.ProcessLayers(collection);
                }
            }
            catch (System.Exception ex)
            {
                DatabaseLogs.FormatLogs(string.Format("ChangesLayers: {0}", ex.Message));
            }
        }
        /// <summary>
        /// Calls the engine clear cache asynchronous.
        /// </summary>
        /// <returns>Task.</returns>
        public static Task CallEngineClearCacheAsync()
        {
            Task t = Task.Run(() =>
            {
                try
                {
                    using (DatabaseCommands commands = new DatabaseCommands())
                    {
                        commands.DeleteAllExportToCadRecords();
                    }
                }
                catch (Exception ex1)
                {
                    DatabaseLogs.FormatLogs("cmdClear_Click: " + ex1.Message);
                }
            });

            t.Wait();
            return(t);
        }
        /// <summary>
        /// Calls the engine clear asynchronous.
        /// </summary>
        /// <returns>Task.</returns>
        public static Task CallEngineClearAsync()
        {
            Task t = Task.Run(() =>
            {
                try
                {
                    using (DatabaseCommands commands = new DatabaseCommands())
                    {
                        commands.DeleteDataFromAllTables();
                    }
                }
                catch (Exception ex1)
                {
                    DatabaseLogs.FormatLogs("cmdClear_Click: " + ex1.Message);
                }
                // PGA.MessengerManager.MessengerManager.ShowMessage(("Complete!"));
            });

            t.Wait();
            return(t);
        }
 public void InitializeSettings(Settings set)
 {
     try
     {
         UseSimplify         = GetValueFromCheckBox(set.SimplifyPlines);
         UseProbing          = GetValueFromCheckBox(set.Probing);
         UseSportVision      = GetValueFromCheckBox(set.SportVision);
         UseSmoothing        = GetValueFromCheckBox(set.Smoothing);
         UsePDFReport        = GetValueFromCheckBox(set.PDFReport);
         UseAddFLtoWaterSurf = GetValueFromCheckBox(set.AddFLWaterSurf);
         UseGenErrorReport   = GetValueFromCheckBox(set.GenErrReport);
         UseOutput3DPolys    = GetValueFromCheckBox(set.Out3DPolys);
         UseReports          = GetValueFromCheckBox(set.GenReports);
         UseBreaklines       = GetValueFromCheckBox(set.CreateBreaklines);
         UseRemoveDups       = GetValueFromCheckBox(set.DuplicateSurfaces);
         UseSkipDXF          = GetValueFromCheckBox(set.SkipSDxf);
         UseGen2013DXF       = GetValueFromCheckBox(set.CreateDXF);
         SimplifyTolerance   = (double)set.SimplifyValue.GetValueOrDefault();
     }
     catch (Exception ex)
     {
         DatabaseLogs.AddLogs(ex.Message, "InitializeSettings");
     }
 }
        /// <summary>
        /// Handles the Click event of the cmdClear control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private async void cmdClear_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (DatabaseCommands commands = new DatabaseCommands())
                {
                    await CallEngineClearAsync();
                }

                // Clear Cache
                cmdClearCache_Click(sender, e);

                //Notify MainForm Controls
                if (RefreshChanged != null)
                {
                    RefreshChanged();
                }
            }
            catch (Exception ex1)
            {
                DatabaseLogs.FormatLogs("cmdClear_Click: " + ex1.Message);
            }
            PGA.MessengerManager.MessengerManager.ShowMessage(("Complete!"));
        }
Beispiel #13
0
        public static IList <Point3dCollection> ProcessLidarFileSubtractRegions(IList <Point2dCollection> boundary, DateTime time, string hole, Point3dCollection lidarpoints, ACADDB.ObjectIdCollection polylineCollection)
        {
            IList <PointsWithPolyId> processedpoints = new List <PointsWithPolyId>();

            if (boundary == null)
            {
                throw new ArgumentNullException(nameof(boundary));
            }
            if (hole == null)
            {
                throw new ArgumentNullException(nameof(hole));
            }

            DatabaseCommands command = new DatabaseCommands();
            var path = command.GetPointPathByDate(time, hole);
            var dir  = Path.GetDirectoryName(path);
            var name = Path.GetFileName(path);

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            //Point3dCollection lidarpoints = CreateAllSurface.ReadPointCloudFile.ReadFile(dir, name);
            Point2dCollection         points2D        = PGA.AcadUtilities.AcadUtilities.ConvertTo2d(lidarpoints);
            IList <Point3dCollection> parsecollection = new List <Point3dCollection>();

            try
            {
                foreach (Point2dCollection pline in boundary)
                {
                    Point3dCollection local = new Point3dCollection();
                    for (int i = 0; i < points2D.Count; i++)
                    {
                        if (PointUtilities.PointInPolyline(pline, points2D[i]))
                        {
                            local.Add(lidarpoints[i]);
                        }
                    }
                    parsecollection.Add(local);
                    //contains the points for each polyline
                    processedpoints.Add(new PointsWithPolyId(local, boundary.IndexOf(pline)));
                }

                m_PolylineChildren.Count();
                //subtract inner points
                foreach (ACADDB.ObjectId maspolyoid in polylineCollection)
                {
                    int masterregloc             = polylineCollection.IndexOf(maspolyoid);
                    PolylineChildren subChildren = m_PolylineChildren[masterregloc];

                    if (maspolyoid != subChildren.Oid)
                    {
                        throw new Exception("ProcesssLidarPoints: Subtract regions unordered!");
                    }



                    for (int i = 0; i < subChildren.Children.Count; i++)
                    {
                        ACADDB.ObjectId subregionoid = subChildren.Children[i];
                        //Filter Out == (Area,ObjectId)
                        if ((subregionoid != maspolyoid) ||
                            !(AcadUtilities.AcadUtilities.CompareAreasFromPolylines
                                  (subregionoid, maspolyoid)))
                        {
                            //var outterRegion = ACADDB.Region.FromAcadObject(maspolyoid);
                            var outterRegion = AddRegion(maspolyoid);
                            var innerRegion  = AddRegion(subregionoid);

                            if (outterRegion.Area > innerRegion.Area)

                            {
                                outterRegion.BooleanOperation(ACADDB.BooleanOperationType.BoolSubtract, innerRegion);
                                innerRegion.Dispose();
                            }
                            //Point3dCollection pointstodelete = new Point3dCollection();

                            //int subregloc = polylineCollection.IndexOf(subregionoid);
                            //if (subregloc != -1)
                            //{
                            //    ACADDB.Region.FromAcadObject(maspolyoid);
                            //    pointstodelete = parsecollection[subregloc];

                            //    for (int j = 0; j < parsecollection[subregloc].Count; j++)
                            //    {
                            //        foreach (Point3d point in pointstodelete)
                            //        {
                            //            if (parsecollection[masterregloc].Contains(point))
                            //                parsecollection[masterregloc].Remove(point);
                            //        }
                            //    }
                            //}
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DatabaseLogs.FormatLogs("ProcessLidarFileSubtractRegions" + ex.Message);
            }

            return(parsecollection);
        }
Beispiel #14
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);
                        }
                    }
                }
            }
        }
Beispiel #15
0
        private static void CreateTinForDistinctSurfaces(IList <Point3dCollection> p3D,
                                                         ACADDB.ObjectIdCollection collection)
        {
            if (p3D.Count != collection.Count)
            {
                return;
            }
            PolylineChildren children;

            try
            {
                foreach (ACADDB.ObjectId polys in collection)
                {
                    children = new PolylineChildren();

                    foreach (PolylineChildren item in m_PolylineChildren)
                    {
                        if (item.Oid.Equals(polys))
                        {
                            for (int i = 0; i < item.Children.Count; i++)
                            {
                                if (item.Children[i].Equals(polys))
                                {
                                    item.Children.RemoveAt(i);
                                }
                                else if (PGA.AcadUtilities.AcadUtilities.CompareAreasFromPolylines(polys,
                                                                                                   item.Children[i]))
                                {
                                    item.Children.RemoveAt(i);
                                }
                            }

                            children = item;
                            break;
                        }
                    }
                    var layer = PGA.SimplifyPolylines.Commands.GetPolylineName(polys);
                    var index = collection.IndexOf(polys);
                    CreateAllSurface.CreateTINSurface pTinSurface;
                    C3D.PasteSurfaces surfaces = new C3D.PasteSurfaces();

                    TinSurface theSurface;
                    if (index < p3D.Count)
                    {
                        pTinSurface = new CreateAllSurface.CreateTINSurface();
                        theSurface  = pTinSurface.CreateTINSurfaceByPointCollection(p3D[index], layer);
                        surfaces.AddBoundariesForSurfaces(PlineToPoints(children.Oid), theSurface.ObjectId);
                        // ACADDB.ObjectId materId = ACADDB.Material.FromAcadObject(theSurface.AcadObject);

                        //adds outer
                        //Adds hide polylines
                        for (int i = 0; i < children.Children.Count; i++)
                        {
                            var polyboundary = new  ACADDB.ObjectIdCollection();
                            polyboundary.Add(children.Oid);
                            SurfaceMaskCreationData mask = new SurfaceMaskCreationData
                                                               (String.Format("Hide-{0}", i), "Hide", theSurface.ObjectId, polyboundary, 3, theSurface.MaterialId, SurfaceMaskType.InSide, false);
                            if (!PGA.AcadUtilities.AcadUtilities.CompareAreasFromPolylines(polys, children.Children[i]))
                            {
                                surfaces.AddStandardBoundary(children.Children[i], theSurface.Name, theSurface);
                                //theSurface.Masks.Add(mask);
                            }
                        }
                    }
                }
            }
            catch (Exception ex1)
            {
                DatabaseLogs.FormatLogs(ex1.Message);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Gets the name of the polyline.
        /// </summary>
        /// <param name="selectedObjectId">The selected object identifier.</param>
        /// <param name="index">The index.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        static bool GetPolylineName(ObjectId selectedObjectId, int index)
        {
            var          doc      = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
            var          ed       = doc.Editor;
            var          db       = doc.Database;
            var          counter  = 0;
            var          position = 0;
            var          name     = "";
            PlanarEntity plane;

            //Get the current UCS

            CoordinateSystem3d ucs =
                ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

            plane = new Plane(ucs.Origin, ucs.Xaxis);

            using (var tr = db.TransactionManager.StartTransaction())
            {
                var obj =
                    tr.GetObject(selectedObjectId, OpenMode.ForRead);


                //"lightweight" (or optimized) polyline

                var lwp = obj as Polyline;

                if (lwp != null)
                {
                    var vn = lwp.NumberOfVertices;

                    DatabaseLogs.FormatLogs(String.Format("Polyline Name= {2}-{0} - Vertices= {1}",
                                                          lwp.Layer, lwp.NumberOfVertices, index));
                }

                else
                {
                    // If an old-style, 2D polyline

                    var p2d = obj as Polyline2d;


                    if (p2d != null)
                    {
                        foreach (ObjectId vId in p2d)
                        {
                            var v2d =
                                (Vertex2d)tr.GetObject(
                                    vId,
                                    OpenMode.ForRead
                                    );

                            name = v2d.BlockName;
                            position++;
                        }

                        DatabaseLogs.FormatLogs(String.Format("Polyline Name= {2}-{0} - Vertices= {1}",
                                                              p2d.Layer, counter, index));
                    }

                    else
                    {
                        // If an old-style, 3D polyline

                        var p3d = obj as Polyline3d;

                        if (p3d != null)
                        {
                            // Use foreach to get each contained vertex

                            foreach (ObjectId vId in p3d)
                            {
                                var v3d =
                                    (PolylineVertex3d)tr.GetObject(
                                        vId,
                                        OpenMode.ForRead
                                        );
                                name = v3d.Layer;
                            }

                            DatabaseLogs.FormatLogs(String.Format("Polyline Name= {2}-{0} - Vertices= {1}",
                                                                  name, counter, index));
                        }
                    }
                }

                // Committing is cheaper than aborting

                tr.Commit();
            }
            return(true);
        }
Beispiel #17
0
        public static void LoadandProcessPolys()
        {
            using (DatabaseCommands commands = new DatabaseCommands())
            {
                #region Get Dwgs to Process

                var dwgs = commands.LoadandProcessPolys();

                foreach (var dwg in dwgs)
                {
                    DwDrawingStacks.Add(dwg);
                }

                #endregion

                GDwgPath = commands.GetGlobalDWGPath();

                var doc =
                    Application.DocumentManager.MdiActiveDocument;
                var ed = doc.Editor;

                foreach (var dwg in DwDrawingStacks)
                {
                    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
                        {
                            // We'll just suffix the selected filename with "-purged"
                            // for the output location. This file will be overwritten
                            // if the command is called multiple times

                            //var output =
                            //    Path.GetDirectoryName(pfnr.StringResult) + "\\" +
                            //    Path.GetFileNameWithoutExtension(pfnr.StringResult) +
                            //    "-purged" +
                            //    Path.GetExtension(pfnr.StringResult);

                            // Assume a post-R12 drawing

                            using (var db = new Autodesk.AutoCAD.DatabaseServices.Database(false, true))
                            {
                                // Read the DWG file into our Database object

                                db.ReadDwgFile(
                                    path,
                                    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 = HostApplicationServices.WorkingDatabase;
                                HostApplicationServices.WorkingDatabase = db;

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

                                CopyPolylinesBetweenDatabases(db, collection);

                                // Still need to reset the working database

                                HostApplicationServices.WorkingDatabase = wdb;
                                wdb.Save();
                                string date   = dwg.DateStamp.Value.ToFileTime().ToString();
                                string output = Path.Combine(commands.GetGlobalDestinationPath(dwg.DateStamp.Value), String.Format("HOLES-{0}", date));
                                FileUtilities.CreateDirectory(output);
                                PLineToLayers.ProcessLayers(collection, wdb);
                                output = Path.Combine(output, dwg.PolylineDwgName);
                                doc.Database.SaveAs(output, DwgVersion.Current);

                                //    if (PurgeDgnLinetypesInDb(db, ed))
                                //    {
                                //        // Check the version of the drawing to save back to

                                //        var ver =
                                //            (db.LastSavedAsVersion == DwgVersion.MC0To0
                                //                ? DwgVersion.Current
                                //                : db.LastSavedAsVersion
                                //                );

                                //        // Now we can save

                                //        string output = null;
                                //        db.SaveAs(output, ver);

                                //        ed.WriteMessage(
                                //            "\nSaved purged file to \"{0}\".",
                                //            output
                                //            );
                                //    }

                                //    // Still need to reset the working database

                                //    HostApplicationServices.WorkingDatabase = wdb;
                            }
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            ed.WriteMessage("\nException: {0}", ex.Message);
                        }
                    }
                    break;
                }
            }
        }
Beispiel #18
0
        public static void ChangePolylineLayers()
        {
            using (DatabaseCommands commands = new DatabaseCommands())
            {
                #region Get Dwgs to Process

                var dwgs = commands.LoadandProcessPolys();

                foreach (var dwg in dwgs)
                {
                    DwDrawingStacks.Add(dwg);
                }

                #endregion

                GDwgPath = commands.GetGlobalDWGPath();

                var doc =
                    Application.DocumentManager.MdiActiveDocument;
                var ed = doc.Editor;

                foreach (var dwg in DwDrawingStacks)
                {
                    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
                        {
                            // We'll just suffix the selected filename with "-purged"
                            // for the output location. This file will be overwritten
                            // if the command is called multiple times

                            //var output =
                            //    Path.GetDirectoryName(pfnr.StringResult) + "\\" +
                            //    Path.GetFileNameWithoutExtension(pfnr.StringResult) +
                            //    "-purged" +
                            //    Path.GetExtension(pfnr.StringResult);

                            // Assume a post-R12 drawing

                            using (var db = doc.Database)
                            {
                                ObjectIdCollection collection = GetIdsByTypeTypeValue("POLYLINE", "LWPOLYLINE", "POLYLINE2D", "POLYLINE3d");

                                //db.Save();
                                string date   = dwg.DateStamp.Value.ToFileTime().ToString();
                                string output = Path.Combine(commands.GetGlobalDestinationPath(dwg.DateStamp.Value), String.Format("HOLES-{0}", date));
                                Pge.Common.Framework.FileUtilities.CreateDirectory(output);
                                PLineToLayers.ProcessLayers(collection, db);
                                output = Path.Combine(output, dwg.PolylineDwgName);
                                doc.Database.SaveAs(output, DwgVersion.Current);
                            }
                        }
                        catch (Autodesk.AutoCAD.Runtime.Exception ex)
                        {
                            ed.WriteMessage("\nException: {0}", ex.Message);
                        }
                    }
                    break;
                }
            }
        }
 public static void AddLog(string message)
 {
     DatabaseLogs.FormatLogs(message);
 }
 public static void ShowMessageAlert(string message)
 {
     MessageBox.Show("Alert! " + message);
     DatabaseLogs.FormatLogs("Alert! " + message);
 }
 public static void ShowMessageAndLog(string message)
 {
     MessageBox.Show(message);
     DatabaseLogs.FormatLogs(message);
 }