Exemplo n.º 1
0
        /// <summary>
        /// Attaches the drawings.
        /// </summary>
        public void AttachDrawings(IList <string> drawingNames)
        {
            //_logger.Info("Attaching drawings...");

            //_logger.Debug("Start AttachDrawings");
            _attachedDwgs = new List <string>();

            // loop through all the drawing in the config file
            // if the file exists, attach it
            //
            foreach (string dwg in drawingNames)
            {
                try
                {
                    if (File.Exists(dwg))
                    {
                        this.ProjectModel.DrawingSet.AttachDrawing(dwg);
                        _attachedDwgs.Add(dwg);
                    }
                    else
                    {
                        //_logger.Debug("Could not find the drawing to attach: " + dwg);
                        AcadUtilities.WriteMessage("\nCould not find the drawing to attach: " + dwg);
                    }
                }
                catch (System.Exception ex)
                {
                    //_logger.Error("Error attaching drawing: " + dwg, ex);
                    throw;
                    //AcadUtilities.WriteMessage("\nError attaching drawing: " + dwg);
                }
            }
            //_logger.Debug("End AttachDrawings");
        }
Exemplo n.º 2
0
        public static void AddStandardBoundary(ObjectId polyId, string surfacename,
                                               Autodesk.Civil.DatabaseServices.TinSurface surface)
        {
            Polyline poly = null;

            try
            {
                using (Transaction tr = CivilApplicationManager.StartTransaction())
                {
                    poly = polyId.GetObject(OpenMode.ForRead) as Polyline;

                    var points = AcadUtilities.GetPointsFromPolyline(poly);

                    Autodesk.Civil.DatabaseServices.SurfaceDefinitionBoundaries surfaceBoundaries =
                        surface.BoundariesDefinition;
                    if (points.Count == 0)
                    {
                        //throw new ArgumentException(
                        //    String.Format("Len={0} Nodes={1} Layer={2} Oid={3}",
                        //    poly.Length.ToString(),
                        //    poly.NumberOfVertices.ToString(),
                        //    poly.Layer.ToString(),
                        //    poly.ObjectId.ToString()), "AddStandardBoundary");
                    }
                    else
                    {
                        surfaceBoundaries.AddBoundaries(points, 1.0, SurfaceBoundaryType.Hide, true);
                    }
                    tr.Commit();
                }
            }
            catch { }
        }
Exemplo n.º 3
0
        //private static readonly ILog //_logger = LogManager.GetLogger(typeof(MapUtilities));

        #endregion

        #region MapBreak

        /// <summary>
        /// Maps the break.
        /// </summary>
        /// <param name="polyPoints">The poly points.</param>
        /// <param name="layerFilter">The layer filter.</param>
        /// <returns></returns>
        public static bool MapBreak(IList <GemsPoint2d> polyPoints, string layerFilter)
        {
            bool retval = false;

            //_logger.Debug("Start MapBreak");
            GemsPoint2d minPoint = CoordinateService.GetMinFromPolygon(polyPoints);
            GemsPoint2d maxPoint = CoordinateService.GetMaxFromPolygon(polyPoints);

            // This should return a selection set and check that it contains one or more objects
            // I would need to add a using to get the SelectionSet object in this class...?
            SelectionManager.GetSelectionSet(minPoint.X, minPoint.Y, maxPoint.X, maxPoint.Y, layerFilter, true);

            // The CMDDIA calls should reference SetSystemVariable
            StringBuilder acadCmd = new StringBuilder();

            acadCmd.Append("CMDDIA 0 ");
            acadCmd.Append("_MAPBREAK DEFINE ");
            foreach (GemsPoint2d onePoint in polyPoints)
            {
                acadCmd.Append(onePoint.X.ToString());
                acadCmd.Append(",");
                acadCmd.Append(onePoint.Y.ToString());
                acadCmd.Append("\r");
            }
            acadCmd.Append("\r");
            acadCmd.Append("N Y P  Y Y ");
            acadCmd.Append("CMDDIA 1 ");
            AcadUtilities.SendStringToExecute(acadCmd.ToString());
            retval = true;

            //_logger.Debug("End MapBreak");
            return(retval);
        }
Exemplo n.º 4
0
        /// <summary>
        /// References the current AutoCAD Map Project drawing and sets the AutoCAD Map coordinate system code
        /// Note that this must not be called if a query has been executed.
        /// Behavior is unknown if there are even drawings attached to the project
        /// Best to call this on a new drawing with no attached drawings or queried objects
        /// </summary>
        /// <param name="mapCsCode">The map cs code.</param>
        /// <returns></returns>
        public static bool SetMapCSCode(string mapCsCode)
        {
            bool retVal = false;

            //_logger.Debug("Start SetMapCSCode");
            try
            {
                // Note that setting the coordinate system code causes a zoom window command to be piped to the command line
                // This is getting sent in a manner that causes AutoCAD to get confused
                // Replacing with SendStringToExecute is a work around
                AcadUtilities.SendStringToExecute("ADESETCRDSYS S " + mapCsCode + " X ");
                //MapApplication AcMap;
                //Autodesk.Gis.Map.Project.ProjectModel AcMapProject;
                //AcMap = HostMapApplicationServices.Application;
                //AcMapProject = AcMap.ActiveProject;
                //AcMapProject.Projection = mapCsCode;
                retVal = true;
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error in SetMapCSCode", ex);
                throw;
            }
            //_logger.Debug("End SetMapCSCode");
            return(retVal);
        }
Exemplo n.º 5
0
 public void ExportPolylinesToCSV()
 {
     try
     {
         PolylineUtilities.ExportPolyPointsToCSV();
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 6
0
 public void GetComplexity()
 {
     try
     {
         PolylineUtilities.GetComplexity();
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 7
0
 public void AssignPolyLinesToLayers()
 {
     try
     {
         PLineToLayers.SelectPolylines();
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 8
0
 public void SaveToACAD2007Format()
 {
     try
     {
         PLineToLayers.SaveToAcad2007();
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 9
0
 public void ImportPointCloud()
 {
     try
     {
         AcadUtilities.SendStringToExecute("_.AeccCreatePointCloud \n");
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 10
0
 public void Settings()
 {
     try
     {
         Application.SetSystemVariable("FILEDIA", 1);
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 11
0
        //------------------------------------------------------------------------//
        // Convierte la entidad <Arc> de is2Graph a su tipo equivalente de ACAD.
        public static ArcEx ToAcad(ArcType Arc, Vector3d normal)
        {
            PointType Pi, Pm, Pf;
            Point3d   acPi, acPf, acPm;

            Arc.GetArc3Points(out Pi, out Pm, out Pf); AcadUtilities.AddPinToModel(is2GraphTranslator.ToAcad_DB(Pm), 34, 0.4);
            acPi = is2GraphTranslator.ToAcad_3d(Pi);
            acPm = is2GraphTranslator.ToAcad_3d(Pm);
            acPf = is2GraphTranslator.ToAcad_3d(Pf);

            return(new ArcEx(new StartPointEx(acPi), new AnyPointEx(acPm), new EndPointEx(acPf), normal));
        }
Exemplo n.º 12
0
 public void TurnOnSurfaceLayers()
 {
     try
     {
         ClosePolylines.TurnOnSurfaceLayers();
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 13
0
 public void ExportToAutoCAD2()
 {
     try
     {
         AcadUtilities.SendStringToExecute("_.EXPORTTOAUTOCAD \n\n");
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 14
0
 public void ClosePolyLines()
 {
     try
     {
         ClosePolylines.CloseSelectedPolylines();
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 15
0
            public void CheckDrawing()
            {
                try
                {
                    AcadUtilities.WriteMessage("Starting Audit \n\n");

                    AcadUtilities.SendStringToExecute("_.AUDIT Y \n\n");
                }
                catch (Exception ex)
                {
                    AcadUtilities.WriteMessage(ex.Message);
                    PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
                }
            }
Exemplo n.º 16
0
 public void LoadByComandInsertTemplate()
 {
     try
     {
         using (PGA.Database.DatabaseCommands commands = new DatabaseCommands())
         {
             PGA.Autodesk.Utils.LoadTemplate.LoadPGATemplate(commands.GetTemplatePath());
         }
     }
     catch (Exception ex)
     {
         AcadUtilities.WriteMessage(ex.Message);
         PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
     }
 }
Exemplo n.º 17
0
        public static bool IsOnLayer(string layername, ObjectId oPolyline)
        {
            bool     flag;
            Database workingDatabase = CivilApplicationManager.WorkingDatabase;

            Application.get_DocumentManager().get_MdiActiveDocument();
            ObjectIdCollection objectIdCollection = new ObjectIdCollection();
            IList <string>     strs = new List <string>()
            {
                layername
            };
            IList <string> strs1 = new List <string>()
            {
                "LWPolyline"
            };
            Transaction transaction = workingDatabase.get_TransactionManager().StartTransaction();

            try
            {
                objectIdCollection = AcadUtilities.GetObjectIdsOnLayer(workingDatabase, transaction, strs, strs1);
                transaction.Commit();
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Dispose();
                }
            }
            if (objectIdCollection.get_Count() != 0)
            {
                foreach (ObjectId objectId in objectIdCollection)
                {
                    if (objectId == oPolyline)
                    {
                        flag = true;
                        return(flag);
                    }
                }
                flag = false;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Exemplo n.º 18
0
        /// <summary>
        ///     Deletes the viewports from layout.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="layoutName">Name of the layout.</param>
        /// <returns></returns>
        public static bool DeleteViewportsFromLayout(Database db, Transaction trans, string layoutName)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start DeleteViewportsFromLayout");
            var retval = false;

            layoutName = layoutName.ToUpper();
            if (IsLayoutDefined(db, trans, layoutName))
            {
                var    layoutId  = GetLayoutId(db, trans, layoutName);
                Layout oneLayout = null;
                oneLayout = trans.GetObject(layoutId, OpenMode.ForRead) as Layout;
                if (oneLayout != null)
                {
                    using (
                        var layoutBtr =
                            trans.GetObject(oneLayout.BlockTableRecordId, OpenMode.ForWrite, false) as BlockTableRecord)
                    {
                        var oids            = new ObjectIdCollection();
                        var isFirstViewport = true;
                        foreach (var oid in layoutBtr)
                        {
                            if (oid.ObjectClass.Name == "AcDbViewport")
                            {
                                if (isFirstViewport)
                                {
                                    isFirstViewport = false;
                                }
                                else
                                {
                                    oids.Add(oid);
                                }
                            }
                        }
                        if (oids.Count > 0)
                        {
                            AcadUtilities.DeleteObjects(db, trans, oids);
                        }
                        retval = true;
                    }
                }
            }
            PGA.MessengerManager.MessengerManager.AddLog("End DeleteViewportsFromLayout");
            return(retval);
        }
Exemplo n.º 19
0
        /// <summary>
        ///     Copies the named layout from the source drawing file into the db
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="targetLayoutName">Name of the target layout.</param>
        /// <param name="sourceLayoutName">Name of the source layout.</param>
        /// <param name="sourceLayoutDrawingName">Name of the source layout drawing.</param>
        /// <returns></returns>
        public static bool WBlockCloneLayout(Database db, Transaction trans, string targetLayoutName,
                                             string sourceLayoutName, string sourceLayoutDrawingName)
        {
            PGA.MessengerManager.MessengerManager.AddLog("Start WBlockCloneLayout");
            var retval = false;

            //Verify layout is not already defined in target database (can't copy in a duplicate name)
            if (IsLayoutDefined(db, trans, targetLayoutName))
            {
                return(false);
            }

            // Load the source database as side database
            using (var sourceDb = AcadUtilities.LoadSideDatabase(sourceLayoutDrawingName, true))
            //if (sourceDb != null)
            {
                var sourceObjectIdCollection = new ObjectIdCollection();

                // Start transaction on source database
                using (var wblockTrans = sourceDb.TransactionManager.StartTransaction())
                {
                    // get the layout object from source db
                    Layout sourceLayout = null;
                    var    layoutId     = GetLayoutId(sourceDb, wblockTrans, sourceLayoutName);
                    if (layoutId != null)
                    {
                        sourceLayout = wblockTrans.GetObject(layoutId, OpenMode.ForRead) as Layout;

                        // Get id collection of all objects on layout's block table record
                        using (
                            var sourceLayoutBtr =
                                wblockTrans.GetObject(sourceLayout.BlockTableRecordId, OpenMode.ForRead) as
                                BlockTableRecord)
                        {
                            foreach (var oid in sourceLayoutBtr)
                            {
                                sourceObjectIdCollection.Add(oid);
                            }
                        }

                        // Get the block table from the target database
                        var targetBt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;

                        // Derive the paper space name for the next layout
                        var layoutPaperSpacePrefix = "*Paper_Space";
                        var layoutCount            = 1;
                        while (targetBt.Has(layoutPaperSpacePrefix + layoutCount))
                        {
                            layoutCount++;
                        }
                        var nextPaperSpaceLayoutName = layoutPaperSpacePrefix + layoutCount;

                        // Create a new layout as a copy of the source layout
                        var targetLayout = new Layout();
                        targetLayout.LayoutName = targetLayoutName;
                        targetLayout.CopyFrom(sourceLayout);

                        // Add a new block table record to the target block table with the next paper space name
                        var targetBtr = new BlockTableRecord();
                        targetBtr.Name = nextPaperSpaceLayoutName;

                        // Note that this does not work as expected -
                        // the name is redefined at .Add. No error is thrown and the layout name sorts itself out on save / close / open?
                        targetBt.Add(targetBtr);
                        trans.AddNewlyCreatedDBObject(targetBtr, true);

                        // Wblock Clone all the objects found in the source layout to the target database
                        sourceDb.WblockCloneObjects(sourceObjectIdCollection, targetBtr.ObjectId, new IdMapping(),
                                                    DuplicateRecordCloning.Ignore, false);

                        // Add the layout to the target database layout dictionary
                        targetLayout.AddToLayoutDictionary(db, targetBtr.ObjectId);

                        // Add the layout to the target database
                        trans.AddNewlyCreatedDBObject(targetLayout, true);

                        retval = true;
                    }
                }
                sourceDb.Dispose();
            }
            PGA.MessengerManager.MessengerManager.AddLog("End WBlockCloneLayout");
            return(retval);
        }
Exemplo n.º 20
0
        public static ObjectIdCollection GetAllInternalPolyLines(ObjectId oid, ObjectIdCollection oids)
        {
            var objectIdCollection = new ObjectIdCollection();
            var num = 0.1;

            try
            {
                using (var workingDatabase = WorkingDatabase)
                {
                    foreach (ObjectId oid1 in oids)
                    {
                        Polyline polyFromObjId1;
                        Polyline polyFromObjId2;
                        try
                        {
                            if (
                                !(GetPolyFromObjId(oid1) == null))
                            {
                                polyFromObjId1 = GetPolyFromObjId(oid, workingDatabase);
                                polyFromObjId2 = GetPolyFromObjId(oid1, workingDatabase);
                                if (polyFromObjId1 == null ||
                                    polyFromObjId2 == null)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                        catch (NullReferenceException ex)
                        {
                            PGA.MessengerManager.MessengerManager.LogException(ex);

                            continue;
                        }
                        if (Math.Abs(polyFromObjId1.Area - polyFromObjId2.Area) >= num)
                        {
                            var pointsFromPolyline = AcadUtilities.GetPointsFromPolyline(polyFromObjId2);
                            if (
                                PointInPolyline(AcadUtilities.GetPointsFromPolyline(polyFromObjId1),
                                                pointsFromPolyline) && oid1.IsValid)
                            {
                                objectIdCollection.Add(oid1);
                            }
                        }
                    }
                    if ((uint)objectIdCollection.Count > 0U)
                    {
                        return(objectIdCollection);
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
            catch (Exception ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
            return(null);
        }
Exemplo n.º 21
0
        public static void CreateSphere()
        {
            try
            {
                Document doc =
                    Application.DocumentManager.MdiActiveDocument;
                Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
                Editor ed = doc.Editor;

                Transaction tr =
                    doc.TransactionManager.StartTransaction();
                using (tr)
                {
                    BlockTable bt =
                        (BlockTable)tr.GetObject(
                            db.BlockTableId,
                            OpenMode.ForRead
                            );
                    BlockTableRecord btr =
                        (BlockTableRecord)tr.GetObject(
                            bt[BlockTableRecord.ModelSpace],
                            OpenMode.ForWrite
                            );
                    Solid3d sol = new Solid3d();
                    sol.CreateSphere(10.0);

                    const string matname =
                        "Sitework.Paving - Surfacing.Riverstone.Mortared";
                    DBDictionary matdict =
                        (DBDictionary)tr.GetObject(
                            db.MaterialDictionaryId,
                            OpenMode.ForRead
                            );
                    if (matdict.Contains(matname))
                    {
                        sol.Material = matname;
                    }
                    else
                    {
                        ed.WriteMessage(
                            "\nMaterial (" + matname + ") not found" +
                            " - sphere will be rendered without it.",
                            matname
                            );
                    }
                    btr.AppendEntity(sol);

                    tr.AddNewlyCreatedDBObject(sol, true);
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.AddLog(ex.Message);
            }

            using (var doc = Active.Document.LockDocument())
            {
                AcadUtilities.ZoomExtents();
            }
        }