块属性问题
<P>我把一张定义过属性的图(尚未定义成块)当作块插入进来</P><P>插进来之后属性都不见了。。</P>
<P>请问怎么解决?</P> <P>不知道</P>
<P>我只知道定义成块后插入没有问题</P> <P>噢</P>
<P>那你怎么操作的啊?</P>
<P>我直接把文件读进一个database里</P>
<P>然后在当前的db里插入了一个块参照 你是怎么处理的呢?</P> <P>看看你的代码?</P> <P>public static void DwgToBlock() //把图纸当作图块插入<BR> {<BR> Document doc = Application.DocumentManager.MdiActiveDocument;<BR> Editor ed = doc.Editor;<BR> PromptResult res = ed.GetString("Give me a file to insert");<BR> if (res.Status != PromptStatus.OK)<BR> return;<BR> string fname = res.StringResult;<BR> if (!File.Exists(fname))<BR> fname = HostApplicationServices.Current.FindFile(fname, doc.Database, FindFileHint.Default);<BR> using (Database db = new Database(false, false))<BR> {<BR> //得到想插入的文档<BR> db.ReadDwgFile(fname, FileShare.Read, true, null);<BR> BlockTableRecord dwgBTR=null;<BR> using (Transaction t = doc.TransactionManager.StartTransaction())<BR> {<BR> try<BR> {<BR> BlockTable dwgBT=(BlockTable)t.GetObject(db.BlockTableId,OpenMode.ForWrite,true);<BR> <BR> dwgBTR=(BlockTableRecord)t.GetObject(dwgBT["Title"],OpenMode.ForWrite,true);<BR> }<BR> catch(System.Exception ess)<BR> {<BR> ed.WriteMessage(ess.Message);<BR> }<BR> foreach(ObjectId dwgID in dwgBTR)<BR> {<BR> Entity ent = (Entity)t.GetObject(dwgID, OpenMode.ForRead, false); <BR> //打开当前的对象! <BR> if (ent is AttributeDefinition) <BR> { <BR> //设置属性为属性索引中的属性定义 <BR> AttributeDefinition attDef = ((AttributeDefinition)(ent)); <BR> ed.WriteMessage(attDef.TextString);<BR> } <BR> }</P>
<P> //创建一个块<BR> ObjectId idBTR = doc.Database.Insert("test", db, false);<BR> BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);<BR> BlockTableRecord btr = (BlockTableRecord)t.GetObject(bt, OpenMode.ForWrite);<BR> double x,y,z=0;<BR> PromptPointResult resPoint = ed.GetPoint("输入插入点坐标(x,y)");<BR> if (resPoint.Status != PromptStatus.OK)<BR> return;<BR> BlockReference bref = new BlockReference(resPoint.Value, dwgBTR.Id);<BR> btr.AppendEntity(bref);<BR> t.AddNewlyCreatedDBObject(bref, true);<BR> t.Commit();<BR> }<BR> }<BR> }</P>
<P>加下划线的部分是想处理属性来着</P>
页:
[1]