Пример #1
0
        public void CopyBlockTable(Database db, string filePath, Predicate <BlockTableRecord> predicate)
        {
            var aw = new AutoCadWrapper();

            using (Database sourceDb = new Database(false, true))
            {
                // Read the DWG into a side database
                sourceDb.ReadDwgFile(filePath, System.IO.FileShare.ReadWrite, true, "");

                // Start transaction to read equipment
                aw.ExecuteActionOnBlockTable(sourceDb, bt =>
                {
                    // Create a variable to store the list of block identifiers
                    ObjectIdCollection blockIds = new ObjectIdCollection();

                    foreach (var objectId in bt)
                    {
                        using (var btr = objectId.GetObject <BlockTableRecord>())
                        {
                            // Only add named & non-layout blocks to the copy list and filter for specific item
                            if (!btr.IsAnonymous && !btr.IsLayout && predicate(btr))
                            {
                                blockIds.Add(objectId);
                            }
                        }
                    }
                    // Copy blocks from source to destination database
                    IdMapping mapping = new IdMapping();
                    sourceDb.WblockCloneObjects(blockIds, db.BlockTableId, mapping, DuplicateRecordCloning.Replace, false);
                });
            }
        }
Пример #2
0
        public void LayerStatus()
        {
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            var aw = new AutoCadWrapper();

            aw.ExecuteActionOnLayerTable(db, (tr, lt) =>
            {
                var layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForWrite) as LayerTable;

                // Append the new layer to the Layer table and the transaction
                var layerTableRecord = new LayerTableRecord();

                layerTableRecord.IsOff = true;
            });
        }
Пример #3
0
        public void LayerCreatorMethod(string sLayerName, Color acColors, double lineTypeScale, bool isOff)
        {
            var db = Application.DocumentManager.MdiActiveDocument.Database;
            var aw = new AutoCadWrapper();

            // Start a transaction to create layer
            aw.ExecuteActionOnLayerTable(db, (tr, lt) =>
            {
                // Open the Layer table for read
                var layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;

                //layerName definition;
                string sLayerName1 = sLayerName.ToLower();
                string sLayerName2 = sLayerName.ToUpper();

                // Append the new layer to the Layer table and the transaction
                var layerTableRecord = new LayerTableRecord();

                if (layerTable.Has(sLayerName1) == false || layerTable.Has(sLayerName) == false || layerTable.Has(sLayerName2) == false)
                {
                    // Assign the layer a name
                    layerTableRecord.Name = sLayerName;

                    // Upgrade the Layer table for write
                    if (layerTable.IsWriteEnabled == false)
                    {
                        layerTable.UpgradeOpen();
                    }

                    // Append the new layer to the Layer table and the transaction
                    layerTable.Add(layerTableRecord);
                    tr.AddNewlyCreatedDBObject(layerTableRecord, true);
                }
                else
                {
                    // Open the layer if it already exists for write
                    layerTableRecord = tr.GetObject(layerTable[sLayerName], OpenMode.ForWrite) as LayerTableRecord;
                }
                // Set layer
                layerTableRecord.Color      = acColors;
                db.Ltscale                  = lineTypeScale;
                layerTableRecord.LineWeight = LineWeight.LineWeight025;
                layerTableRecord.IsOff      = isOff;
            });
        }