插入块之后为什么不能用增强属性编辑器打开?
大侠们,我在代码中将一个外部DWG图纸的块插入到当前图纸中,但是插入之后再当前图纸中双击块是打开“编辑块定义”这个对话框,如何能让我双击之后打开的是“增强属性编辑器”这个对话框呢?<br/><br/>PS:这个块是定义好属性的,打开外部DWG图纸就可以用 增强属性编辑器 打开<br/><br/>下面是我插入块的代码<br/><br/>public void AddBlockRef(double bx, double by, double bz)<br/> {<br/> Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument;<br/> Editor ed = doc.Editor;<br/><br/> Point3d point = new Point3d(bx, by, bz);<br/><br/> using (Database db = new Database(false, false))<br/> {<br/> using (Transaction trans = doc.TransactionManager.StartTransaction())<br/> {<br/> BlockTable bt = (BlockTable)trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);<br/> BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);<br/> //读取块<br/> string blockFile = @"d:\arx\bplead_title.dwg";<br/> string blockName = "BPLEAD_TITLE";<br/> db.ReadDwgFile(blockFile, System.IO.FileShare.Read, true, null);<br/> ObjectId blockId = doc.Database.Insert(blockName, db, false);<br/> using (BlockReference br = new BlockReference(point, blockId))<br/> {<br/> btr.AppendEntity(br);<br/> trans.AddNewlyCreatedDBObject(br, true);<br/> }<br/> trans.Commit();<br/> }<br/> }<br/><br/> <br/> //return blockId;//返回创建的块的对象Id<br/> }<br/> 块参照的属性集合还是要用代码生成的,不会自动加的 大侠,我看过你好多帖子,灰常有帮助,想不到你在啊,能指点一下吗 <p>看<a href="http://bbs.mjtd.com/forum.php?mod=viewthread&tid=76123">这里</a>的AppendAttribToBlock函数</p> BlockRefJig jig = new BlockRefJig(blkref, AppendAttribToBlock(blkref, atts));<br/> 674. jig.SetPromptCounter(0);<br/> 675. PromptResult res = CadHelper.Editor.Drag(jig);<br/> 676. if (res.Status == PromptStatus.OK)<br/> 677. {<br/> 678. jig.SetPromptCounter(1);<br/> 679. res = CadHelper.Editor.Drag(jig);<br/> 680. if (res.Status == PromptStatus.OK)<br/> 681. {<br/> 682. return id;<br/> 683. }<br/> 684. }<br/> 685. blkref.Erase();<br/><br/>在这里面调用你说的这个方法的? 看不太明白呀,哪个方法是实现这个的? 详细点说一下吧,嘿嘿,多谢<br/>public Dictionary<AttributeDefinition, AttributeReference> AppendAttribToBlock(BlockReference blkref, List<string> atts)
{
BlockTableRecord blkdef = (BlockTableRecord)m_Transaction.GetObject(blkref.BlockTableRecord, OpenMode.ForRead);
int i = 0;
if (blkdef.HasAttributeDefinitions)
{
Dictionary<AttributeDefinition, AttributeReference> attribs = new Dictionary<AttributeDefinition, AttributeReference>();
foreach (ObjectId id in blkdef)
{
DBObject ent = GetObject(id, OpenMode.ForRead);
if (ent is AttributeDefinition)
{
AttributeDefinition attdef = (AttributeDefinition)ent;
AttributeReference attref = new AttributeReference();
attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
if (i < atts.Count)
attref.TextString = atts;
else
attref.TextString = attdef.TextString;
i++;
blkref.AttributeCollection.AppendAttribute(attref);
m_Transaction.AddNewlyCreatedDBObject(attref, true);
attribs.Add(attdef, attref);
}
}
return attribs;
}
return null;
}
好,我去试试,多谢,有不明白的在请教您! public void AppendAttribToBlock(BlockReference blkref, List<string> atts)
{
Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument;
Transaction trans = doc.TransactionManager.StartTransaction();
BlockTableRecord blkdef = (BlockTableRecord)trans.GetObject(blkref.BlockTableRecord, OpenMode.ForRead);
int i = 0;
if (blkdef.HasAttributeDefinitions)
{
Dictionary<AttributeDefinition, AttributeReference> attribs = new Dictionary<AttributeDefinition, AttributeReference>();
foreach (ObjectId id in blkdef)
{
DBObject ent = trans.GetObject(id, OpenMode.ForRead,false);
if (ent is AttributeDefinition)
{
AttributeDefinition attdef = (AttributeDefinition)ent;
AttributeReference attref = new AttributeReference();
attref.SetAttributeFromBlock(attdef, blkref.BlockTransform);
if (i < atts.Count)
attref.TextString = atts;
else
attref.TextString = attdef.TextString;
i++;
blkref.AttributeCollection.AppendAttribute(attref);
trans.AddNewlyCreatedDBObject(attref, true);
attribs.Add(attdef, attref);
}
}
}
}
大侠,这是我修改的类,但是部署了报错~
致命错误:Unhandled Access Violation Reading 0x0004 Exception at 645ad340h
能帮忙看看吗,哪出问题了~
file:///C:/Users/Nemo/AppData/Local/Temp/moz-screenshot.png
file:///C:/Users/Nemo/AppData/Local/Temp/moz-screenshot-1.png
file:///C:/Users/Nemo/AppData/Local/Temp/moz-screenshot-2.png
页:
[1]