예제 #1
0
파일: _SETUP.cs 프로젝트: 15831944/habile
        private bool getBlockFromMaster(ref List <string> missingBlocks)
        {
            _Db.Database sourceDb       = new _Db.Database(false, true);
            string       sourceFileName = @"C:\Brics_pealeehitus\master.dwg";

            if (!File.Exists(sourceFileName))
            {
                sourceFileName = @"C:\Users\aleksandr.ess\Dropbox\DMT\Brics_testimine\master.dwg";
                if (!File.Exists(sourceFileName))
                {
                    sourceFileName = @"C:\Users\Alex\Dropbox\DMT\Brics_testimine\master.dwg";
                }
            }

            sourceDb.ReadDwgFile(sourceFileName, System.IO.FileShare.Read, true, "");
            _Db.ObjectIdCollection blockIds = new _Db.ObjectIdCollection();


            using (_Db.Transaction sourceTrans = sourceDb.TransactionManager.StartTransaction())
            {
                _Db.BlockTable sourceBlockTable = sourceTrans.GetObject(sourceDb.BlockTableId, _Db.OpenMode.ForRead, false) as _Db.BlockTable;

                foreach (_Db.ObjectId sourceObject in sourceBlockTable)
                {
                    _Db.BlockTableRecord btr = sourceTrans.GetObject(sourceObject, _Db.OpenMode.ForRead, false) as _Db.BlockTableRecord;

                    if (!btr.IsAnonymous && !btr.IsLayout)
                    {
                        if (missingBlocks.Contains(btr.Name))
                        {
                            blockIds.Add(sourceObject);
                            missingBlocks.Remove(btr.Name);
                            write("[SETUP] " + btr.Name); // TODO REMOVE
                        }
                    }

                    btr.Dispose();
                }
            }

            if (missingBlocks.Count > 0)
            {
                return(false);
            }

            _Db.IdMapping mapping = new _Db.IdMapping();
            sourceDb.WblockCloneObjects(blockIds, _c.blockTable.Id, mapping, _Db.DuplicateRecordCloning.Replace, false);
            sourceDb.Dispose();

            write("[SETUP] Kõik puuduvad blockid on lisatud 'master' failist");
            return(true);
        }
예제 #2
0
        public static AcDb.ObjectIdCollection ImportSymbolTableRecords <T>(
            /*this Database db,*/
            string sourceFile,
            params string[] recordNames)
            where T : AcDb.SymbolTable
        {
            using (AcDb.Database sourceDb = new AcDb.Database())
            {
                sourceDb.ReadDwgFile(sourceFile, System.IO.FileShare.Read, false, "");

                AcDb.ObjectId sourceTableId;
                AcDb.ObjectId targetTableId;

                switch (typeof(T).Name)
                {
                case "BlockTable":
                    sourceTableId = sourceDb.BlockTableId;
                    targetTableId = db.BlockTableId;
                    break;

                case "DimStyleTable":
                    sourceTableId = sourceDb.DimStyleTableId;
                    targetTableId = db.DimStyleTableId;
                    break;

                case "LayerTable":
                    sourceTableId = sourceDb.LayerTableId;
                    targetTableId = db.LayerTableId;
                    break;

                case "LinetypeTable":
                    sourceTableId = sourceDb.LinetypeTableId;
                    targetTableId = db.LinetypeTableId;
                    break;

                case "RegAppTable":
                    sourceTableId = sourceDb.RegAppTableId;
                    targetTableId = db.RegAppTableId;
                    break;

                case "TextStyleTable":
                    sourceTableId = sourceDb.TextStyleTableId;
                    targetTableId = db.TextStyleTableId;
                    break;

                case "UcsTable":
                    sourceTableId = sourceDb.UcsTableId;
                    targetTableId = db.UcsTableId;
                    break;

                case "ViewTable":
                    sourceTableId = sourceDb.ViewportTableId;
                    targetTableId = db.ViewportTableId;
                    break;

                case "ViewportTable":
                    sourceTableId = sourceDb.ViewportTableId;
                    targetTableId = db.ViewportTableId;
                    break;

                default:
                    throw new ArgumentException("\nImportSymbolTableRecords > Потрібен конкретний тип, похідний від SymbolTable");
                }

                using (AcDb.Transaction tr = sourceDb.TransactionManager.StartTransaction())
                {
                    T sourceTable = (T)tr.GetObject(sourceTableId, AcDb.OpenMode.ForRead);
                    AcDb.ObjectIdCollection idObjects = new AcDb.ObjectIdCollection();
                    foreach (string name in recordNames)
                    {
                        if (sourceTable.Has(name))
                        {
                            idObjects.Add(sourceTable[name]);
                        }
                    }
                    if (idObjects.Count == 0)
                    {
                        return(null);
                    }
                    AcDb.IdMapping idMap = new AcDb.IdMapping();
                    sourceDb.WblockCloneObjects(idObjects, targetTableId, idMap, AcDb.DuplicateRecordCloning.Replace, false);
                    tr.Commit();
                    AcDb.ObjectIdCollection retVal = new AcDb.ObjectIdCollection();
                    foreach (AcDb.ObjectId id in idObjects)
                    {
                        if (idMap[id].IsCloned)
                        {
                            retVal.Add(idMap[id].Value);
                        }
                    }
                    return(retVal.Count == 0 ? null : retVal);
                }
            }
        }
예제 #3
0
        private static void ImportNestedFilters(

            _AcLm.LayerFilter srcFilter,
            _AcLm.LayerFilter destFilter,
            _AcDb.Database srcDb,
            _AcDb.Database destDb,
            bool copyLayer,
            _AcEd.Editor ed)
        {
            using (_AcDb.Transaction tr = srcDb.TransactionManager.StartTransaction())
            {
                _AcDb.LayerTable lt = tr.GetObject(srcDb.LayerTableId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTable;

                foreach (_AcLm.LayerFilter sf in srcFilter.NestedFilters)
                {
                    _AcDb.IdMapping idmap = new _AcDb.IdMapping();
                    if (copyLayer)
                    {
                        // Get the layers to be cloned to the dest db.
                        // Only those that are pass the filter
                        _AcDb.ObjectIdCollection layerIds = new _AcDb.ObjectIdCollection();
                        foreach (_AcDb.ObjectId layerId in lt)
                        {
                            _AcDb.LayerTableRecord ltr = tr.GetObject(layerId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTableRecord;
                            if (sf.Filter(ltr))
                            {
                                layerIds.Add(layerId);
                            }
                        }

                        // clone the layers to the dest db
                        if (layerIds.Count > 0)
                        {
                            srcDb.WblockCloneObjects(
                                layerIds,
                                destDb.LayerTableId,
                                idmap,
                                _AcDb.DuplicateRecordCloning.Replace,
                                false);
                        }
                    }

                    // Find if a destination database already
                    // has a layer filter with the same name
                    _AcLm.LayerFilter df = null;
                    foreach (_AcLm.LayerFilter f in destFilter.NestedFilters)
                    {
                        if (f.Name.Equals(sf.Name))
                        {
                            df = f;
                            break;
                        }
                    }

                    if (df == null)
                    {
                        if (sf is _AcLm.LayerGroup)
                        {
                            // create a new layer filter group
                            // if nothing found
                            _AcLm.LayerGroup sfgroup = sf as _AcLm.LayerGroup;
                            _AcLm.LayerGroup dfgroup = new _AcLm.LayerGroup();
                            ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter-Gruppe {0}.", sf.Name));
                            dfgroup.Name = sf.Name;
                            df           = dfgroup;
                            if (copyLayer)
                            {
                                _AcLm.LayerCollection lyrs = sfgroup.LayerIds;
                                foreach (_AcDb.ObjectId lid in lyrs)
                                {
                                    if (idmap.Contains(lid))
                                    {
                                        _AcDb.IdPair idp = idmap[lid];

                                        dfgroup.LayerIds.Add(idp.Value);
                                    }
                                }
                            }
                            destFilter.NestedFilters.Add(df);
                        }
                        else
                        {
                            // create a new layer filter
                            // if nothing found
                            ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter {0}.", sf.Name));
                            df                  = new _AcLm.LayerFilter();
                            df.Name             = sf.Name;
                            df.FilterExpression = sf.FilterExpression;
                            destFilter.NestedFilters.Add(df);
                        }
                    }
                    // Import other filters
                    ImportNestedFilters(sf, df, srcDb, destDb, copyLayer, ed);
                }
                tr.Commit();
            }
        }