写扩展数据的问题
<p align="left"> AddXData(lwPolyLine, i + 1, "polyId");<br/> //写扩展数据<br/> public Entity AddXData(Entity ent, Object obj, string regapptablename)<br/> {<br/> ObjectId objId = ent.ObjectId;<br/> Database db = HostApplicationServices.WorkingDatabase;<br/> Entity retEntity;<br/> using (Transaction trans = db.TransactionManager.StartTransaction())<br/> {<br/> retEntity = (Entity)trans.GetObject(ent.ObjectId, OpenMode.ForWrite);<br/> RegAppTable apptbl = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForWrite);<br/> if (!apptbl.Has(regapptablename))<br/> {<br/> RegAppTableRecord appTblRcd = new RegAppTableRecord();<br/> appTblRcd.Name = regapptablename;<br/> apptbl.Add(appTblRcd);<br/> trans.AddNewlyCreatedDBObject(appTblRcd, true);<br/> }<br/> ResultBuffer resBuf = new ResultBuffer();<br/> resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, regapptablename));<br/> resBuf.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, obj));<br/> ent.XData = resBuf;<br/> trans.Commit();<br/> }<br/> return retEntity;<br/> }<br/>保存之后关闭再打开,为什么扩展数据里就没有了呢??</p> <p>子函数里没找到错,这里改下试试 </p><p>AddXData(lwPolyLine, (i + 1).ToString, "polyId");<br/></p> TypedValue[] fillist = new TypedValue[] { (new TypedValue((int)DxfCode.Start, "LWPolyline"))};//,new TypedValue(8,"外围轮廓线") };
SelectionFilter filter = new SelectionFilter(fillist);
PromptSelectionResult lwPolyRes = ed.SelectAll(filter);
TypedValue[] fillist1 = new TypedValue[] { (new TypedValue((int)DxfCode.Start, "Polyline"))};//, new TypedValue(8, "外围轮廓线") };
SelectionFilter filter1 = new SelectionFilter(fillist1);
PromptSelectionResult polyRes = ed.SelectAll(filter1);
if (lwPolyRes.Status == PromptStatus.OK&&polyRes.Status==PromptStatus.OK)
{
SelectionSet lwPolySet = lwPolyRes.Value;
int lwPolyCount = lwPolySet.Count;
Polyline lwPolyLine = new Polyline();
SelectionSet polySet = polyRes.Value;
int polyCount = polySet.Count;
}
本来想设置断点在第一行的,可是它不执行,直接跑到下面去了,跑就跑呗,执行过的代码还看不到执行结果。是不是vs2005的问题啊??? <p>retEntity = (Entity)trans.GetObject(ent.ObjectId, OpenMode.ForWrite);</p>
<p>------------------</p>
<p>这个函数好搞笑</p> <p>搞不懂,不对吗?</p> <p>哈哈</p>
<p>retEntity == ent;</p> <p>Entity ent,</p>
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div id="textstyle_4" style="FONT-SIZE: 12pt; OVERFLOW: hidden; WORD-BREAK: break-all; TEXT-INDENT: 0px; WORD-WRAP: break-word">
<p>retEntity = (Entity)trans.GetObject(ent.ObjectId, OpenMode.ForWrite);</p></div></td></tr></tbody></table>你的ent类型是Entity,说明若是已存在的实体,已经打开了,你在这里又再打开,你这一行若没有问题也是多余了,你直接使用ent即可,可能前面是只读打开,那么你升级为可写打开即可,若Entity ent是个新建实体(还没提交到数据库),你这一行应该会报错. <p>OK,贴个相关的扩展函数,调用方式:</p>
<p>1/简单的例子</p>
<p> ent.UpgradeOpen(() => ent.ColorIndex = 3) ;</p>
<p>2/较为复杂的例子</p>
<p><font face="Verdana"> BlockTable.UpgradeOpen<br/> (<br/> () =><br/> {<br/> BlockTableRecord btr = new BlockTableRecord();<br/> btr.Name = name;<br/> id = BlockTable.Add(btr);<br/> Transaction.AddNewlyCreatedDBObject(btr, true);<br/> }<br/> );</font></p>
<p> </p>
<p> </p>
<p><font face="Verdana"> public static void UpgradeOpen<T>(this T obj, Action action) where T : DBObject<br/> {<br/> if (obj.IsNotifyEnabled)<br/> {<br/> bool b = obj.IsWriteEnabled;<br/> obj.UpgradeFromNotify();<br/> action();<br/> obj.DowngradeToNotify(b);<br/> }<br/> else if (obj.IsWriteEnabled)<br/> {<br/> action();<br/> }<br/> else<br/> {<br/> obj.UpgradeOpen();<br/> action();<br/> obj.DowngradeOpen();<br/> }<br/> }</font></p> 哦,这样啊.我一直以为
<p>retEntity == ent;</p>跟
<p>retEntity = (Entity)trans.GetObject(ent.ObjectId, OpenMode.ForWrite);</p>一样呢?我习惯这样写了,现在才知道。谢谢谢谢...我再试试 <p>飞狐,我如果把写过扩展数据的dwg文件,复制一份,再进行操作,那是不是原版和复制版都有扩展数据啊???怎么才能看到它的扩展数据捏</p>
页:
[1]
2