Jig时原点总是有显示,jig后再添加进btr, jig前不能处理属性添加到块,所以要先添加进btr,再clone(),再删除原来的,再将clone的添加进btr OK 解决问题

        //记录修改为不同的颜色
        private static Document doc = Application.DocumentManager.MdiActiveDocument;
        
private static Editor ed = doc.Editor;
        
private static Database db = doc.Database;
        
private static Dictionary<shortstring> dicIColorValue = new Dictionary<shortstring>();
        
public void DeColorGroup(DataView dvAllData, System.Windows.Forms.TreeNode node)
        {
            doc 
= Application.DocumentManager.MdiActiveDocument;
            ed 
= doc.Editor;
            db 
= doc.Database;
            dicIColorValue 
= new Dictionary<shortstring>();

            
string strFile = dvAllData.RowFilter;
            
using (DocumentLock docLock = doc.LockDocument())
            {
                SetEntColor(doc, ed, db, node, dvAllData, dicIColorValue);
                dvAllData.RowFilter 
= strFile;

                
string strEsc = string.Format("{0}{1}", (char)3, (char)3);
                doc.SendStringToExecute(strEsc 
+ "cmdAddLabel\n"truefalsefalse);
                
//AddLabel(db, doc, ed, dicIColorValue);
            }
        }

        [CommandMethod(
"cmdAddLabel")]
        
public void AddLabel()
        {
            
string strPath = Info.appPath + @"\Acad\Blocks\Label\ColorLabel.dwg";
            
using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                BlockTable bt; BlockTableRecord btr;
                ArxHlb.CADEntAdd.GetBtBtr(db, tr, 
out bt, out btr, OpenMode.ForWrite);

                Point3d pt 
= new Point3d();
                Point3d ptBase 
= pt;
                List
<Entity> lstEnt = new List<Entity>();
                DBObjectCollection objs 
= new DBObjectCollection();

                
foreach (short iColor in dicIColorValue.Keys)
                {
                    BlockReference refEnt 
= ArxHlb.CADEntAdd.AddBlockDwgEasy(db, tr,
                        strPath, 
"*U", pt, 0);

                    
//得到实体高
                    refEnt.Explode(objs);
                    
double H = 0;
                    
foreach (DBObject obj in objs)
                    {
                        
if (obj is Polyline)
                        {
                            H 
= ((Polyline)obj).ConstantWidth;
                            
break;
                        }
                    }

                    Dictionary
<stringstring> dicAtt = new Dictionary<stringstring>();
                    dicAtt.Add(
"LABEL", dicIColorValue[iColor]);
                    ArxHlb.CADAtt.SetAttValue(tr, refEnt, dicAtt);

                    ArxHlb.CADEntEdit.ChangeEntAndBlockColor(db, tr,
                        refEnt, Color.FromColorIndex(ColorMethod.ByLayer, iColor));

                    lstEnt.Add(refEnt.Clone() 
as BlockReference);
                    refEnt.Erase();

                    pt 
= new Point3d(pt.X, pt.Y + H * 1.50);
                }

                
if (!ArxHlb.CADJig.Jig(ed, lstEnt, ptBase, "\n请选择颜色标签插入点")) return;

                
for (int i = 0; i < lstEnt.Count; i++)
                {
                    btr.AppendEntity(lstEnt[i]);
                    tr.AddNewlyCreatedDBObject(lstEnt[i], 
true);
                }

                tr.Commit();
            }
        }
posted @ 2011-07-16 11:08  houlinbo  阅读(660)  评论(0编辑  收藏  举报