arx 在不打开文件的情况下添加带属性的块的问题

arx 在不打开文件的情况下添加带属性的块,块的对齐方式总是左对齐, 只有在打开文件的情况下是正确的,需要加如下语句:

            HostApplicationServices.WorkingDatabase = db;

//完整的函数如下

 /// <summary>
        
/// 批量处理图纸 自已选择得到文件路径列表的
        
/// </summary>
        
/// <param name="cationOpenDlg">打开窗口的cation</param>
        
/// <param name="cationWait">等待窗口的cation</param>
        
/// <param name="DwgOp">处理函数,使用委托</param>
        public static void SetDwgsData(string cationOpenDlg, string cationWait, string msgFinish, DelegateSet Op)
        {
            System.Windows.Forms.FolderBrowserDialog dlg 
= new System.Windows.Forms.FolderBrowserDialog();
            
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
            
string dicPath = dlg.SelectedPath;
            
if (dicPath == ""return;

            List
<string> files = new List<string>(); //路径字符串列表
            GetFileList(dicPath, files);

            
using (frmWaiting frm = new frmWaiting())
            {
                frm.Count 
= files.Count;
                frm.Fun 
= cationWait;
                Application.ShowModelessDialog(frm);
                System.Windows.Forms.Application.DoEvents(); 
//释放CPU控制权;

                
if (Application.DocumentManager.Count == 0) Application.DocumentManager.Add("acadiso.dwt");
                Document doc 
= Application.DocumentManager.MdiActiveDocument;
                DocumentLock lockDoc 
= doc.LockDocument();
                
using (lockDoc)
                {
                    
//打开图形数据库db 多张图纸时使用
                    int i = 0;
                    
foreach (string fileName in files)
                    {
                        frm.Index 
= ++i;
                        frm.FileName 
= fileName;
                        System.Windows.Forms.Application.DoEvents();
                        frm.Update();
                        Database db 
= ArxHlb.CADEntAdd.Getdb(fileName, System.IO.FileShare.ReadWrite, false);
                        HostApplicationServices.WorkingDatabase 
= db; //需要置为当前数据库
                        using (Transaction tr = db.TransactionManager.StartTransaction())
                        {
                            BlockTable bt 
= tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                            BlockTableRecord btr 
= tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                            Op(db, tr, bt, btr);
//委托的函数
                            tr.Commit();
                        }
                        db.SaveAs(db.Filename, DwgVersion.Current);
                    }
                }
                HostApplicationServices.WorkingDatabase 
= doc.Database;//需要还原,否则打开出错
            }
            SWF.MessageBox.Show(msgFinish);
        }

 

 

posted @ 2010-03-10 16:09  houlinbo  阅读(942)  评论(0编辑  收藏  举报