Example #1
0
        /// <summary>
        /// 获得数据库中的所有外部参照,无论加载与否。
        /// </summary>
        /// <returns>id, 路径</returns>
        public static Dictionary <ObjectId, string> GetAllXref(Database db, GetXrefType xrefType)
        {
            Dictionary <ObjectId, string> xrefArr = new Dictionary <ObjectId, string>();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                foreach (ObjectId btrId in bt)
                {
                    BlockTableRecord btr = trans.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
                    if (btr.IsFromExternalReference)
                    {
                        if (btr.IsFromOverlayReference)
                        {
                            if (xrefType == GetXrefType.Overlay || xrefType == GetXrefType.All)
                            {
                                xrefArr.Add(btrId, btr.PathName);
                            }
                        }
                        else
                        {
                            if (xrefType == GetXrefType.Attach || xrefType == GetXrefType.All)
                            {
                                xrefArr.Add(btrId, btr.PathName);
                            }
                        }
                    }
                }
            }
            return(xrefArr);
        }
Example #2
0
        public static Dictionary <string, ObjectId> GetAllXrefExt(Database db, GetXrefType xrefType)
        {
            Dictionary <string, ObjectId> xrefArr = new Dictionary <string, ObjectId>();

            using (Transaction trans = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                foreach (ObjectId btrId in bt)
                {
                    BlockTableRecord btr = trans.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
                    if (btr.IsFromExternalReference)
                    {
                        if (btr.IsFromOverlayReference)
                        {
                            if (xrefType == GetXrefType.Overlay || xrefType == GetXrefType.All)
                            {
                                xrefArr.Add(btr.PathName.ToLower(), btrId);
                            }
                        }
                        else
                        {
                            if (xrefType == GetXrefType.Attach || xrefType == GetXrefType.All)
                            {
                                xrefArr.Add(btr.PathName.ToLower(), btrId);
                            }
                        }
                    }

                    foreach (ObjectId id in btr)
                    {
                        Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                        if (ent is RasterImage)
                        {
                            RasterImage image = ent as RasterImage;
                            xrefArr.Add(image.Path.ToLower(), id);
                        }
#if !ACAD2008
                        if (ent is PdfReference)
                        {
                            PdfReference pdf = ent as PdfReference;
                            xrefArr.Add(pdf.Path.ToLower(), id);
                        }
#endif
                    }
                }
            }
            return(xrefArr);
        }