马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
网上搜到的例子都是有属性的 BlockDef 插入,这个是已有的 BlockRef 追加属性,正常 Explode 这个块属性会消失
- [CommandMethod("MyGroup", "addattribute", CommandFlags.Session)]
- public void AddAttributeToBlockRef()
- {
- var doc = Application.DocumentManager.MdiActiveDocument;
- var ed = doc.Editor;
- var db = doc.Database;
- using (doc.LockDocument())
- {
- var peo = new PromptEntityOptions("\nPick Insert");
- peo.SetRejectMessage("\nMust be a BlockReference!");
- peo.AddAllowedClass(typeof(BlockReference),false);
- var per = ed.GetEntity(peo);
- if (per.Status != PromptStatus.OK) return;
-
- using (var tr = db.TransactionManager.StartTransaction())
- {
- var id = per.ObjectId;
- var bf = (BlockReference) tr.GetObject(id, OpenMode.ForWrite);
- var box = bf.GeometricExtents;
- var up = box.MaxPoint + new Vector3d(10,10,0);
- var acAttRef = new AttributeReference
- {
- Position = up ,
- Tag = "Add",
- TextString = "Test"
- };
- bf.AttributeCollection.AppendAttribute(acAttRef);
- tr.AddNewlyCreatedDBObject(acAttRef, true);
- tr.Commit();
- }
- }
- }
|