Esempio n. 1
0
        public static Document CanOpenToWrite1(string path)
        {
            FileStatus fileStatus = new FileStatus(3, path);

            if (!File.Exists(path))
            {
                Console.WriteLine("CanOpenToWrite: File does not exists.");
                return(null);
            }

            if (path == Application.DocumentManager.MdiActiveDocument.Name)
            {
                return(Application.DocumentManager.MdiActiveDocument);
            }

            if (GetListOfDocumentOpening().Contains(path))
            {
                foreach (Document doc in Application.DocumentManager)
                {
                    if (doc.Name == path)
                    {
                        Application.DocumentManager.MdiActiveDocument         = doc;
                        Application.DocumentManager.DocumentActivationEnabled = true;
                        return(Application.DocumentManager.MdiActiveDocument);
                    }
                }
            }

            if (!GoodiesPath.IsFileLocked(path))
            {
                Document doc = Application.DocumentManager.Open(path, false, "");
                Application.DocumentManager.MdiActiveDocument         = doc;
                Application.DocumentManager.DocumentActivationEnabled = true;
                return(Application.DocumentManager.MdiActiveDocument);
            }

            Console.WriteLine("CanOpenToWrite: Can't open file, Problem unknown");
            return(null);
        }
Esempio n. 2
-1
 /// <summary>
 /// COPY A BLOCK (WITH BLOCK NAME) from ONE FILE TO ANOTHER.
 /// </summary>
 /// <param name="blockDrawingFile"></param>
 /// <param name="blockDestinationFile"></param>
 /// <param name="blockName"></param>
 public static void AddBlockToDrawing(string blockDrawingFile, string blockDestinationFile, string blockName)
 {
     if (!GoodiesPath.IsFileLocked(blockDestinationFile) && !GoodiesPath.IsFileReadOnly(blockDestinationFile))
     {
         using (Database db = new Database())
         {
             db.ReadDwgFile(blockDrawingFile, System.IO.FileShare.Read, true, "");
             ObjectIdCollection ids = new ObjectIdCollection();
             using (Transaction tr = db.TransactionManager.StartTransaction())
             {
                 BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                 //BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                 if (bt.Has(blockName))
                 {
                     ObjectId           id     = bt[blockName];
                     BlockTableRecord   btr    = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead);
                     ObjectIdCollection IdsCol = new ObjectIdCollection();
                     using (Database dbDest = new Database())
                     {
                         dbDest.ReadDwgFile(blockDestinationFile, System.IO.FileShare.Write, true, "");
                         IdsCol.Add(id);
                         IdMapping iMap = new IdMapping();
                         dbDest.WblockCloneObjects(IdsCol, dbDest.BlockTableId, iMap, DuplicateRecordCloning.Ignore, false);
                         dbDest.Save();
                         dbDest.Dispose();
                     }
                 }
                 tr.Commit();
             }
         }
     }
 }