示例#1
0
        public ObjectId GetNewSiteId()
        {
            var    site = ObjectId.Null;
            Random rand = new Random();

            try
            {
                using (Application.DocumentManager.MdiActiveDocument.LockDocument())
                {
                    using (Transaction tr = CivilApplicationManager.StartTransaction())
                    {
                        var num = rand.Next(1000, 9999).ToString();

                        Autodesk.AutoCAD.DatabaseServices.Database db = CivilApplicationManager.WorkingDatabase;
                        var doc = CivilDocument.GetCivilDocument(db);

                        site = C3DLandDb.Site.Create(doc, "Site-" + num);

                        tr.Commit();
                    }
                }
            }
            catch (System.ArgumentException)
            {
                GetNewSiteId();
            }
            catch (System.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
            return(site);
        }
示例#2
0
        public ObjectId GetSiteId(ObjectId surfaceId)
        {
            var site = ObjectId.Null;

            using (Transaction tr = CivilApplicationManager.StartTransaction())

            {
                Autodesk.AutoCAD.DatabaseServices.Database db = CivilApplicationManager.WorkingDatabase;
                var doc = CivilDocument.GetCivilDocument(db);
                ObjectIdCollection siteIds = doc.GetSiteIds();
                if (siteIds != null && siteIds.Count != 0)
                {
                    site = (from s in siteIds.Cast <ObjectId>()
                            select s).FirstOrDefault();
                }

                if (site == ObjectId.Null)
                {
                    site = C3DLandDb.Site.Create(doc, "Site-ALL");
                }

                tr.Commit();
            }
            return(site);
        }
示例#3
0
        /// <exclude />
        public void CreateLayersInDB(Autodesk.AutoCAD.DatabaseServices.Database db, List <Polyline3d> polys)
        {
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                DatabaseCommands commands = new DatabaseCommands();
                foreach (var item in polys)
                {
                    // Need to Iterate Current Work Space

                    var layercolor = GetLayerColor(item.Layer);

                    // Iterating side database

                    var code = commands.GetFeatureIndexByName(item.Layer);
                    if (string.IsNullOrEmpty(code))
                    {
                        continue;
                    }
                    if (!BBC.Common.AutoCAD.LayerManager.IsDefined(db, item.Layer) ||
                        !BBC.Common.AutoCAD.LayerManager.IsDefined(db, code))
                    {
                        BBC.Common.AutoCAD.LayerManager.CreateLayer(db, code, layercolor);
                    }
                }

                tr.Commit();
            }
        }
示例#4
0
        public void SaveDrawing(List <Polyline3d> polyCollection)
        {
            try
            {
                //if (polyCollection == null) throw new ArgumentNullException(nameof(polyCollection));
                if (_polylines == null)
                {
                    throw new ArgumentNullException(nameof(polyCollection));
                }

                using (Transaction tr = CivilApplicationManager.StartTransaction())
                {
                    using (Autodesk.AutoCAD.DatabaseServices.Database sidedb =
                               new Autodesk.AutoCAD.DatabaseServices.Database(true, true))
                    {
                        CreateLayersInDB(sidedb, _polylines);
                        SaveDrawingV3(_polylines, sidedb);
                    }
                    tr.Commit();
                }

                ExplodeIntoACAD2000Objects(Commands._drawingName);
            }
            catch (Exception ex)
            {
                MessengerManager.MessengerManager.LogException(ex);
            }

            // ExportToCADStack(Commands._drawingName,_time);
        }
示例#5
0
        private List <ObjectId> GetPolylineEntityIDs(Autodesk.AutoCAD.DatabaseServices.Database db)

        {
            List <ObjectId> ids = null;

            try
            {
                using (var tran = db.TransactionManager.StartTransaction())

                {
                    var tbl =
                        (BlockTable)tran.GetObject(db.BlockTableId, OpenMode.ForRead);

                    var br =
                        (BlockTableRecord)tran.GetObject(tbl[BlockTableRecord.ModelSpace], OpenMode.ForRead);

                    var b = br.Cast <ObjectId>();

                    #region Other Types

                    //==============search certain entity========================//

                    //"LINE" for line

                    //"LWPOLYLINE" for polyline

                    //"CIRCLE" for circle

                    //"INSERT" for block reference

                    //...

                    //We can use "||" (or) to search for more then one entity types

                    //============================================================//


                    //Use lambda extension method

                    //ids = b.Where(id => id.ObjectClass.DxfName.ToUpper() == "LINE" ||

                    //    id.ObjectClass.DxfName.ToUpper() == "LWPOLYLINE").ToList<ObjectId>();

                    #endregion

                    ids = (from id in b
                           where id.ObjectClass.DxfName.ToUpper() == "LWPOLYLINE"
                           select id).ToList();


                    tran.Commit();
                }
            }
            catch (System.Exception ex)
            {
                COMS.MessengerManager.LogException(ex);
            }

            return(ids);
        }
        /// <summary>
        /// Adds an entity to the database and returns the id
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="databaseObject">The database object.</param>
        /// <param name="trans">The trans.</param>
        /// <returns>
        /// ObjectId of the entity after it is added to the database
        /// </returns>
        public static ObjectId AddToDatabase(Autodesk.AutoCAD.DatabaseServices.Database db, Entity databaseObject, Transaction trans)
        {
            ObjectId id = ObjectId.Null;

            //_logger.Debug("Start AddToDatabase");
            try
            {
                using (BlockTable blockTable = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead))
                {
                    using (BlockTableRecord btr = (BlockTableRecord)trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite))
                    {
                        id = btr.AppendEntity(databaseObject);
                        trans.AddNewlyCreatedDBObject(databaseObject, true);
                    }
                }
                //_logger.Debug("End AddToDatabase");
                return(id);
            }
            //catch (Autodesk.AutoCAD.Runtime.Exception arex)
            //{
            //    ////_logger.Debug("Object already in database", arex);
            //    //System.Diagnostics.Debug.WriteLine(databaseObject.GetType().Name + " already in database");
            //}

            catch (System.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.AddLog("Error adding object to the database", ex);
                throw;
            }
        }
示例#7
0
        /// <summary>
        /// Gets the layer color by layer identifier.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="layerid">The layerid.</param>
        /// <returns>Color.</returns>
        /// <exception cref="System.ArgumentNullException">trans;The argument 'trans' was null.</exception>
        public static Color GetLayerColorByLayerId(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, string layername)
        {
            //_logger.Debug("Start GetLayerNames");
            if (trans == null)
            {
                throw new ArgumentNullException("trans", "The argument 'trans' was null.");
            }

            IList <string> layerNames = new List <string>();

            using (LayerTable layerTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead, false))
            {
                foreach (ObjectId id in layerTable)
                {
                    using (LayerTableRecord record = trans.GetObject(id, OpenMode.ForRead) as LayerTableRecord)
                    {
                        if (record.Name.ToUpper() == layername.ToUpper())
                        {
                            return(record.Color);
                        }
                    }
                }
            }
            //_logger.Debug("End GetLayerNames");
            return(null);
        }
示例#8
0
        /// <summary>
        /// Freezes the layer.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="layerName">Name of the layer.</param>
        /// <param name="isFrozen">if set to <c>true</c> [is frozen].</param>
        public static void FreezeLayer(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, string layerName, bool isFrozen)
        {
            //_logger.Debug("Start FreezeLayer");
            using (LayerTable layerTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite, false))
            {
                string   cLayerName = String.Empty;
                ObjectId cLayerId   = db.Clayer;
                using (LayerTableRecord record = trans.GetObject(cLayerId, OpenMode.ForRead) as LayerTableRecord)
                {
                    cLayerName = record.Name.ToUpper();
                }
                if (layerName.ToUpper() != cLayerName)
                {
                    if (layerTable.Has(layerName) == true)
                    {
                        ObjectId id = layerTable[layerName];

                        using (LayerTableRecord record = trans.GetObject(id, OpenMode.ForWrite) as LayerTableRecord)
                        {
                            record.IsFrozen = isFrozen;
                        }
                    }
                }
            }
            //_logger.Debug("End FreezeLayer");
        }
示例#9
0
        public void SaveDrawingV3(List <Polyline3d> polyCollection, Autodesk.AutoCAD.DatabaseServices.Database sidedb)
        {
            var exfeaturelines            = Commands.GetSurfaceEntityIDs(CivilApplicationManager.WorkingDatabase);
            ObjectIdCollection exfeatures = new ObjectIdCollection(exfeaturelines.ToArray());

            using (Autodesk.AutoCAD.DatabaseServices.Database db = sidedb)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable acBlkTbl;

                    // Open the Block table for read

                    acBlkTbl = tr.GetObject(db.BlockTableId,
                                            OpenMode.ForRead) as BlockTable;

                    // Open the Block table record Model space for write
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                               OpenMode.ForWrite) as BlockTableRecord;

                    IdMapping oIdMap = new IdMapping();
                    db.WblockCloneObjects(
                        exfeatures,
                        acBlkTblRec.ObjectId,
                        oIdMap,
                        DuplicateRecordCloning.Ignore,
                        false);

                    tr.Commit();
                }
                db.SaveAs(Commands._drawingName, DwgVersion.Current);
            }
        }
示例#10
0
        /// <summary>
        /// Creates the layer.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="color">The color.</param>
        /// <returns></returns>
        public static ObjectId CreateLayer(Autodesk.AutoCAD.DatabaseServices.Database db, string layername, Color color)
        {
            //_logger.Debug("Start CreateLayer");
            if (db == null)
            {
                throw new ArgumentNullException("db", "The argument 'db' was null.");
            }

            if (string.IsNullOrEmpty(layername))
            {
                throw new ArgumentNullException("layername", "The argument 'layername' was null or empty.");
            }

            if (color == null)
            {
                throw new ArgumentNullException("color", "The argument 'color' was null.");
            }

            ObjectId id = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                id = CreateLayer(db, trans, layername, color);
                trans.Commit();
            }
            //_logger.Debug("End CreateLayer");
            return(id);
        }
示例#11
0
        public void SaveDrawing(List <Polyline3d> polyCollection, Autodesk.AutoCAD.DatabaseServices.Database sidedb)
        {
            using (Autodesk.AutoCAD.DatabaseServices.Database db = sidedb)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable acBlkTbl;
                    foreach (Polyline3d polyline in polyCollection)
                    {
                        if (polyline != null)
                        {
                            // Open the Block table for read

                            acBlkTbl = tr.GetObject(db.BlockTableId,
                                                    OpenMode.ForRead) as BlockTable;

                            // Open the Block table record Model space for write
                            BlockTableRecord acBlkTblRec;
                            acBlkTblRec = tr.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                       OpenMode.ForWrite) as BlockTableRecord;
                            // Add the new object to the block table record and the transaction
                            acBlkTblRec.AppendEntity(polyline);
                            tr.AddNewlyCreatedDBObject(polyline, true);
                        }
                    }
                    tr.Commit();
                }

                db.SaveAs(Commands._drawingName, DwgVersion.Current);
            }
        }
示例#12
0
        /// <summary>
        /// Adds the polyline.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="colorIndex">Index of the color.</param>
        /// <returns></returns>
        public static ObjectId AddPolyline(Transaction trans, Point2dCollection points, string layername, bool isClosed, int colorIndex)
        {
            //_logger.Debug("Start AddPolyline");
            ObjectId id = ObjectId.Null;

            Autodesk.AutoCAD.DatabaseServices.Database           db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Polyline pline = new Polyline())
            {
                pline.SetDatabaseDefaults();
                pline.Layer = layername;
                if ((colorIndex > 0) && (colorIndex < 256))
                {
                    pline.ColorIndex = colorIndex;
                }
                int    index  = 0;
                double buldge = 0.0;
                double width  = 0.0;

                foreach (Point2d pt in points)
                {
                    pline.AddVertexAt(index++, pt, buldge, width, width);
                }

                pline.Closed = isClosed;
                id           = AddToDatabase(db, pline, trans);
            }
            //_logger.Debug("End AddPolyline");
            return(id);
        }
示例#13
0
        /// <summary>
        /// Closests the point.
        /// </summary>
        /// <param name="point3D">The point3 d.</param>
        /// <param name="collection">The collection.</param>
        public static void ClosestPoint(Point3d point3D, Point2dCollection collection)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            Autodesk.AutoCAD.DatabaseServices.Database db = doc.Database;
            Editor ed = doc.Editor;
            //PromptPointResult ppr = ed.GetPoint("\nSpecify a point: ");
            //if (ppr.Status != PromptStatus.OK) return;
            //Point3d pt = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
            Point3d pt = point3D;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                var closest          = btr
                                       .Cast <ObjectId>()
                                       .Select(id => tr.GetObject(id, OpenMode.ForRead) as Polyline)
                                       .Where(ent => ent != null)
                                       .Select(pline => new { pLine = pline, Dist = pt.DistanceTo(pline.GetClosestPointTo(pt, false)) })
                                       .Aggregate((l1, l2) => l1.Dist < l2.Dist ? l1 : l2);
                if (closest != null)
                {
                    closest.pLine.Highlight();
                    ed.WriteMessage("\nDistance = {0}", closest.Dist);
                }
                tr.Commit();
            }
        }
示例#14
0
        /// <summary>
        /// Gets a list of layer names.
        /// </summary>
        /// <param name="db">The database to read.</param>
        /// <param name="trans">The transaction to use.</param>
        /// <returns>A list of layer names</returns>
        public static IList <string> GetLayerNames(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, string filter)
        {
            //_logger.Debug("Start GetLayerNames");
            if (trans == null)
            {
                throw new ArgumentNullException("trans", "The argument 'trans' was null.");
            }

            IList <string> layerNames = new List <string>();

            using (LayerTable layerTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead, false))
            {
                foreach (ObjectId id in layerTable)
                {
                    using (LayerTableRecord record = trans.GetObject(id, OpenMode.ForRead) as LayerTableRecord)
                    {
                        if (record.Name.ToUpper().StartsWith(filter.ToUpper().Replace("*", string.Empty)))
                        {
                            layerNames.Add(record.Name);
                        }
                    }
                }
            }
            //_logger.Debug("End GetLayerNames");
            return(layerNames);
        }
示例#15
0
        /// <summary>
        /// Adds the predefined hatch.
        /// </summary>
        /// <param name="trans">The trans.</param>
        /// <param name="points">The points.</param>
        /// <param name="layername">The layername.</param>
        /// <param name="isClosed">if set to <c>true</c> [is closed].</param>
        /// <param name="patternName">Name of the pattern.</param>
        /// <returns></returns>
        public static ObjectId AddPredefinedHatch(Transaction trans, Point2dCollection points, string layername, bool isClosed, string patternName)
        {
            //_logger.Debug("Start AddPredefinedHatch");
            ObjectId id = ObjectId.Null;

            Autodesk.AutoCAD.DatabaseServices.Database           db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Hatch hatch = new Hatch())
            {
                hatch.SetDatabaseDefaults();
                hatch.Layer = layername;

                id = AddToDatabase(db, hatch, trans);

                hatch.UpgradeOpen();
                //hatch.HatchStyle = HatchStyle.Outer;
                hatch.Associative  = true;
                hatch.PatternScale = 100.0;
                hatch.SetHatchPattern(HatchPatternType.PreDefined, patternName);

                double buldge = 0.0;

                HatchLoop loop = new HatchLoop(HatchLoopTypes.Polyline);
                foreach (Point2d pt in points)
                {
                    BulgeVertex bv = new BulgeVertex(pt, buldge);
                    loop.Polyline.Add(bv);
                }
                hatch.AppendLoop(loop);
                hatch.EvaluateHatch(true);
            }
            //_logger.Debug("End AddPredefinedHatch");
            return(id);
        }
示例#16
0
文件: Class1.cs 项目: zenwalk/giserlu
        public string ReadDWGFile(string dwgPath)
        {
            string pResult = string.Empty;

            //打开
            Autodesk.AutoCAD.DatabaseServices.Database pDwgDB = new Autodesk.AutoCAD.DatabaseServices.Database(false, true);
            pDwgDB.ReadDwgFile(dwgPath, System.IO.FileShare.ReadWrite, true, null);

            //为了让插入块的函数在多个图形文件打开的情况下起作用,你必须使用下面的函数把Dwg文件关闭
            pDwgDB.CloseInput(true);

            Autodesk.AutoCAD.DatabaseServices.Transaction pTransaction = pDwgDB.TransactionManager.StartTransaction();

            //打开源的块表
            Autodesk.AutoCAD.DatabaseServices.BlockTable pBlockTable =
                (Autodesk.AutoCAD.DatabaseServices.BlockTable)pTransaction.GetObject(
                    pDwgDB.BlockTableId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);

            //打开模型空间块表记录
            Autodesk.AutoCAD.DatabaseServices.BlockTableRecord pBlockTableRecord =
                (Autodesk.AutoCAD.DatabaseServices.BlockTableRecord)pTransaction.GetObject(
                    pBlockTable[Autodesk.AutoCAD.DatabaseServices.BlockTableRecord.ModelSpace], Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead);



            foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId pObjID in pBlockTableRecord)
            {
                Autodesk.AutoCAD.DatabaseServices.DBObject pDBObject =
                    (Autodesk.AutoCAD.DatabaseServices.DBObject)pTransaction.GetObject(pObjID, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, false, true);

                if (pDBObject.GetRXClass().DxfName.ToUpper() == "INSERT")
                {
                    Autodesk.AutoCAD.DatabaseServices.BlockReference pBlockReference = (Autodesk.AutoCAD.DatabaseServices.BlockReference)pDBObject;
                    if (pBlockReference.AttributeCollection.Count != 0)
                    {
                        System.Collections.IEnumerator pEnumerator = pBlockReference.AttributeCollection.GetEnumerator();
                        while (pEnumerator.MoveNext())
                        {
                            Autodesk.AutoCAD.DatabaseServices.ObjectId pObjectID = (Autodesk.AutoCAD.DatabaseServices.ObjectId)pEnumerator.Current;

                            Autodesk.AutoCAD.DatabaseServices.AttributeReference pAttributeReference =
                                (Autodesk.AutoCAD.DatabaseServices.AttributeReference)pTransaction.GetObject(
                                    pObjectID, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead, false, true);

                            pResult += pAttributeReference.TextString;
                        }
                    }
                }


                pTransaction.Commit();
                pBlockTableRecord.Dispose();
                pBlockTable.Dispose();
                pDwgDB.Dispose();
            }

            return(pResult);
        }
示例#17
0
        /// <summary>
        /// Creates the new polyliness.
        /// </summary>
        /// <param name="_sourcedb">The _sourcedb.</param>
        /// <param name="_collection">The _collection.</param>
        public static void CreateNewPolyliness(Autodesk.AutoCAD.DatabaseServices.Database _sourcedb, Point2dCollection _collection)
        {
            // Get the current document and database
            Document acDoc = Application.DocumentManager.MdiActiveDocument;

            Autodesk.AutoCAD.DatabaseServices.Database acCurDb = acDoc.Database;
            Editor ed = acDoc.Editor;
            // Lock the current document
            PlanarEntity plane;

            CoordinateSystem3d ucs =
                ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

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

            using (DocumentLock acLckDocCur = acDoc.LockDocument())
            {
                // Start a transaction
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    #region MyRegion

                    // Open the Block table record for read
                    BlockTable acBlkTbl;
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                 OpenMode.ForRead) as BlockTable;
                    // Open the Block table record Model space for write
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                    OpenMode.ForWrite) as BlockTableRecord;


                    DoubleCollection  bulges        = new DoubleCollection();
                    double[]          bulgelist     = new double[] {};
                    Point3dCollection p3DCollection = new Point3dCollection();
                    foreach (var point in _collection)
                    {
                        Point3d p3D = new Point3d(point.X, point.Y, 0.0);
                        p3DCollection.Add(p3D);

                        bulges.Add(0);
                    }

                    Polyline2d polyline2D = new Polyline2d(Poly2dType.SimplePoly, p3DCollection, 0, true, 0, 0, bulges);
                    polyline2D.Color = Color.FromColorIndex(ColorMethod.ByAci, 1);

                    acBlkTblRec.AppendEntity(polyline2D);
                    acTrans.AddNewlyCreatedDBObject(polyline2D, true);

                    #endregion

                    acTrans.Commit();
                }
                //    // Unlock the document
            }
        }
示例#18
0
 /// <summary>
 /// Locks the layer.
 /// </summary>
 /// <param name="db">The db.</param>
 /// <param name="layerName">Name of the layer.</param>
 /// <param name="isLocked">if set to <c>true</c> [is locked].</param>
 /// <returns></returns>
 public static void LockLayer(Autodesk.AutoCAD.DatabaseServices.Database db, string layerName, bool isLocked)
 {
     //_logger.Debug("Start IsLocked");
     using (Transaction trans = db.TransactionManager.StartTransaction())
     {
         LockLayer(db, trans, layerName, isLocked);
         trans.Commit();
     }
     //_logger.Debug("End IsLocked");
 }
示例#19
0
 /// <summary>
 /// Freezes the layer.
 /// </summary>
 /// <param name="db">The db.</param>
 /// <param name="layerName">Name of the layer.</param>
 /// <param name="isFrozen">if set to <c>true</c> [is frozen].</param>
 public static void FreezeLayer(Autodesk.AutoCAD.DatabaseServices.Database db, string layerName, bool isFrozen)
 {
     //_logger.Debug("Start FreezeLayer");
     using (Transaction trans = db.TransactionManager.StartTransaction())
     {
         FreezeLayer(db, trans, layerName, isFrozen);
         trans.Commit();
     }
     //_logger.Debug("End FreezeLayer");
 }
示例#20
0
 /// <summary>
 /// Offs all layers.
 /// </summary>
 /// <param name="db">The db.</param>
 /// <param name="isOff">if set to <c>true</c> [is off].</param>
 public static void OffAllLayers(Autodesk.AutoCAD.DatabaseServices.Database db, bool isOff)
 {
     //_logger.Debug("Start OffAllLayers");
     using (Transaction trans = db.TransactionManager.StartTransaction())
     {
         OffAllLayers(db, trans, isOff);
         trans.Commit();
     }
     //_logger.Debug("End OffAllLayers");
 }
示例#21
0
        //private static readonly ILog //_logger = LogManager.GetLogger(typeof(LayerManager));

        #endregion

        #region CreateLayer

        /// <summary>
        /// Determines whether the specified db is defined.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="layerName">Name of the layer.</param>
        /// <returns>
        ///   <c>true</c> if the specified db is defined; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsDefined(Autodesk.AutoCAD.DatabaseServices.Database db, string layerName)
        {
            //_logger.Debug("Start IsDefined");
            bool defined = false;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                defined = IsDefined(db, trans, layerName);
            }
            //_logger.Debug("End IsDefined");
            return(defined);
        }
示例#22
0
        /// <summary>
        /// Determines whether the specified db is off.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="layerId">The layer id.</param>
        /// <returns>
        ///   <c>true</c> if the specified db is off; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsOff(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, ObjectId layerId)
        {
            //_logger.Debug("Start IsOff");
            bool off = false;

            using (LayerTableRecord layerTableRecord = trans.GetObject(layerId, OpenMode.ForRead, false) as LayerTableRecord)
            {
                off = layerTableRecord.IsOff;
            }
            //_logger.Debug("End IsOff");
            return(off);
        }
示例#23
0
        /// <summary>
        /// Determines whether the specified db is off.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="layername">The layername.</param>
        /// <returns>
        ///   <c>true</c> if the specified db is off; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsOff(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, string layername)
        {
            //_logger.Debug("Start IsOff");
            bool off = false;

            using (LayerTable layerTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite, false))
            {
                ObjectId id = layerTable[layername];
                off = IsOff(db, trans, id);
            }
            //_logger.Debug("End IsOff");
            return(off);
        }
示例#24
0
        /// <summary>
        /// Determines whether the specified db is off.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="layerId">The layer id.</param>
        /// <returns>
        ///   <c>true</c> if the specified db is off; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsOff(Autodesk.AutoCAD.DatabaseServices.Database db, ObjectId layerId)
        {
            //_logger.Debug("Start IsOff");
            bool off = false;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                off = IsOff(db, trans, layerId);
                trans.Commit();
            }
            //_logger.Debug("End IsOff");
            return(off);
        }
示例#25
0
        /// <summary>
        /// Gets the layer id.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="layername">The layername.</param>
        /// <returns>The object id the layer if it exists, otherwise ObjectId.Null</returns>
        public static ObjectId GetLayerId(Autodesk.AutoCAD.DatabaseServices.Database db, string layername)
        {
            //_logger.Debug("Start GetLayerId");
            ObjectId layerId = ObjectId.Null;

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                layerId = GetLayerId(db, trans, layername);
                trans.Commit();
            }
            //_logger.Debug("End GetLayerId");
            return(layerId);
        }
示例#26
0
        /// <summary>
        /// Gets a list of layer names.
        /// </summary>
        /// <param name="db">The database to read.</param>
        /// <returns></returns>
        public static IList <string> GetLayerNames(Autodesk.AutoCAD.DatabaseServices.Database db)
        {
            //_logger.Debug("Start GetLayerNames");
            IList <string> layerNames = new List <string>();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                layerNames = GetLayerNames(db, trans);
                trans.Commit();
            }
            //_logger.Debug("End GetLayerNames");
            return(layerNames);
        }
示例#27
0
        public static void LoopSurfaces(string originalname, string filename, string coursecode, string hole, bool Is2013DXF)
        {
            string name = "";

            Autodesk.AutoCAD.DatabaseServices.Database db =
                Application.DocumentManager.MdiActiveDocument.Database;

            try
            {
                //change working database
                HostApplicationServices.WorkingDatabase = db;
                //select objects from that database
                ObjectIdCollection collection = GetAllSurfaces();

                //save objects to side database
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId surfaceId in collection)
                    {
                        TinSurface surface = trans.GetObject(surfaceId, OpenMode.ForRead) as TinSurface;
                        var        facecol = ExtractFaces(surface);
                        CreateFaces(facecol, filename, db);
                    }
                    trans.Commit();
                }

                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    db.SaveAs(filename, DwgVersion.Current);
                    trans.Commit();
                }
                if (IsZDrawing(filename))
                {
                    name     = string.Format("z_{0}_{1}.dxf", coursecode, hole);
                    filename = Path.Combine(Path.GetDirectoryName(filename), name);
                }
                if (!Is2013DXF)
                {
                    db.DxfOut(filename.Replace(".DWG", ".dxf"), 16, DwgVersion.Current);
                }
                else
                {
                    db.DxfOut(filename.Replace(".DWG", ".dxf"), 16, DwgVersion.AC1027);
                }
            }
            catch (System.Exception ex)
            {
                PGA.MessengerManager.MessengerManager.LogException(ex);
            }
        }
示例#28
0
 /// <summary>
 /// Offs all layers.
 /// </summary>
 /// <param name="db">The db.</param>
 /// <param name="trans">The trans.</param>
 /// <param name="isOff">if set to <c>true</c> [is off].</param>
 public static void OffAllLayers(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, bool isOff)
 {
     //_logger.Debug("Start OffAllLayers");
     using (LayerTable layerTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite, false))
     {
         foreach (ObjectId id in layerTable)
         {
             using (LayerTableRecord record = trans.GetObject(id, OpenMode.ForWrite) as LayerTableRecord)
             {
                 record.IsOff = isOff;
             }
         }
     }
     //_logger.Debug("End OffAllLayers");
 }
示例#29
0
        /// <summary>
        /// Gets the layer id.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="layername">The layername.</param>
        /// <returns>The object id the layer if it exists, otherwise ObjectId.Null</returns>
        public static ObjectId GetLayerId(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, string layername)
        {
            //_logger.Debug("Start GetLayerId");
            ObjectId layerId = ObjectId.Null;

            using (LayerTable layerTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite, false))
            {
                if (layerTable.Has(layername))
                {
                    layerId = layerTable[layername];
                }
            }
            //_logger.Debug("End GetLayerId");
            return(layerId);
        }
示例#30
0
        /// <summary>
        /// Determines whether the specified db is defined.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="trans">The trans.</param>
        /// <param name="layername">The layername.</param>
        /// <returns>
        ///   <c>true</c> if the specified db is defined; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsDefined(Autodesk.AutoCAD.DatabaseServices.Database db, Transaction trans, string layername)
        {
            //_logger.Debug("Start IsDefined");
            bool defined = false;

            using (LayerTable layerTable = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForWrite, false))
            {
                if (layerTable.Has(layername))
                {
                    defined = true;
                }
            }
            //_logger.Debug("End IsDefined");
            return(defined);
        }