yuhua 发表于 2006-7-5 10:47:00

块属性问题

<P>我把一张定义过属性的图(尚未定义成块)当作块插入进来</P>
<P>插进来之后属性都不见了。。</P>
<P>请问怎么解决?</P>

sangding 发表于 2006-7-5 11:08:00

<P>不知道</P>
<P>我只知道定义成块后插入没有问题</P>

yuhua 发表于 2006-7-5 13:27:00

<P>噢</P>
<P>那你怎么操作的啊?</P>
<P>我直接把文件读进一个database里</P>
<P>然后在当前的db里插入了一个块参照&nbsp; 你是怎么处理的呢?</P>

雪山飞狐_lzh 发表于 2006-7-5 20:46:00

<P>看看你的代码?</P>

yuhua 发表于 2006-7-7 08:48:00

<P>public static void DwgToBlock()&nbsp; //把图纸当作图块插入<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Document doc = Application.DocumentManager.MdiActiveDocument;<BR>&nbsp;&nbsp;&nbsp;Editor ed = doc.Editor;<BR>&nbsp;&nbsp;&nbsp;PromptResult res = ed.GetString("Give me a file to insert");<BR>&nbsp;&nbsp;&nbsp;if (res.Status != PromptStatus.OK)<BR>&nbsp;&nbsp;&nbsp;&nbsp;return;<BR>&nbsp;&nbsp;&nbsp;string fname = res.StringResult;<BR>&nbsp;&nbsp;&nbsp;if (!File.Exists(fname))<BR>&nbsp;&nbsp;&nbsp;&nbsp;fname = HostApplicationServices.Current.FindFile(fname, doc.Database, FindFileHint.Default);<BR>&nbsp;&nbsp;&nbsp;using (Database db = new Database(false, false))<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;//得到想插入的文档<BR>&nbsp;&nbsp;&nbsp;&nbsp;db.ReadDwgFile(fname, FileShare.Read, true, null);<BR>&nbsp;&nbsp;&nbsp;&nbsp;BlockTableRecord dwgBTR=null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;using (Transaction t = doc.TransactionManager.StartTransaction())<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BlockTable dwgBT=(BlockTable)t.GetObject(db.BlockTableId,OpenMode.ForWrite,true);<BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dwgBTR=(BlockTableRecord)t.GetObject(dwgBT["Title"],OpenMode.ForWrite,true);<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; catch(System.Exception ess)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ed.WriteMessage(ess.Message);<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp; foreach(ObjectId dwgID in&nbsp; dwgBTR)<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Entity ent = (Entity)t.GetObject(dwgID, OpenMode.ForRead, false); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //打开当前的对象! <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (ent is AttributeDefinition) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设置属性为属性索引中的属性定义 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AttributeDefinition attDef = ((AttributeDefinition)(ent)); <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ed.WriteMessage(attDef.TextString);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//创建一个块<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ObjectId idBTR = doc.Database.Insert("test", db, false);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockTable bt = (BlockTable)t.GetObject(doc.Database.BlockTableId, OpenMode.ForRead);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockTableRecord btr = (BlockTableRecord)t.GetObject(bt, OpenMode.ForWrite);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double x,y,z=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PromptPointResult resPoint = ed.GetPoint("输入插入点坐标(x,y)");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (resPoint.Status != PromptStatus.OK)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BlockReference bref = new BlockReference(resPoint.Value, dwgBTR.Id);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;btr.AppendEntity(bref);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.AddNewlyCreatedDBObject(bref, true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.Commit();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}</P>
<P>加下划线的部分是想处理属性来着</P>
页: [1]
查看完整版本: 块属性问题