コード例 #1
0
        static public void transferObjs(string option)
        {
            string defExt = ".dwg";
            string title  = string.Format("Transfer {0}", option);
            string filter = "All Drawings (*.dwg)|*.dwg";
            string dir    = Path.GetDirectoryName(BaseObjs.docFullName);

            string[] files = FileManager.getFiles(defExt, title, filter, dir);

            if (files == null || files.Length == 0)
            {
                return;
            }

            Document docTar = BaseObjs._acadDoc;
            Database dbTar  = docTar.Database;

            Document docSrc = null;
            Database dbSrc  = null;

            string nameFile = files[0];
            string nameUser = "";
            int    status   = FileManager.getFileStatus(nameFile, out nameUser);

            switch (status)
            {
            case (int)filestatus.isOpenLocalReadOnly:
            case (int)filestatus.isOpenLocal:
                //connect to db and make transfer
                foreach (Document doc in BaseObjs._acadDocs)
                {
                    if (doc.Name == nameFile)
                    {
                        docSrc = doc;
                        dbSrc  = docSrc.Database;
                    }
                }
                break;

            case (int)filestatus.isAvailable:
                //open and make transfer
                docSrc = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameFile, true);
                dbSrc  = docSrc.Database;
                break;

            case (int)filestatus.isLocked:
                //open readonly
                docSrc = DocumentCollectionExtension.Open(BaseObjs._acadDocs, nameFile, true);
                dbSrc  = docSrc.Database;
                break;
            }

            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = docSrc;

            TypedValue[] tvs = null;
            switch (option)
            {
            case "AREAS":
                tvs = new TypedValue[5] {
                    new TypedValue((int)DxfCode.Start, RXClass.GetClass(typeof(Polyline)).DxfName),
                    new TypedValue((int)DxfCode.Operator, "<OR"),
                    new TypedValue((int)DxfCode.LayerName, "_XX-*"),
                    new TypedValue((int)DxfCode.LayerName, "YY-*"),
                    new TypedValue((int)DxfCode.Operator, "OR>")
                };
                SelectionSet ss  = Select.buildSSet(tvs);
                ObjectId[]   ids = ss.GetObjectIds();

                FileManager.transferObjects(ids, dbSrc, dbTar);
                break;

            case "TABLE":
                transferTableData(docSrc, docTar, dbSrc, dbTar);
                break;
            }

            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = docTar;

            switch (status)
            {
            case (int)filestatus.isAvailable:
            case (int)filestatus.isLocked:
                BaseObjs._closeDoc(docSrc, false);
                break;

            default:
                break;
            }
        }