高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】大家好 请过来看看下段代码有何问题(字符串替换),谢谢!
大家好 请过来看看下段代码有何问题(字符串替换),谢谢!
大家好 请过来看看下段代码有何问题(字符串替换),谢谢!
acdbdatabase* pdb = new acdbdatabase(false, true);
pdb->readdwgfile(file);
acdbblocktable *pblocktable;
pdb->getsymboltable(pblocktable, acdb::kforread);
acdbblocktablerecord *pblocktablerecord;
pblocktable->getat(acdb_model_space, pblocktablerecord, acdb::kforwrite);
pblocktable->close();
acdbblocktablerecorditerator *pblockiterator;
pblocktablerecord->newiterator(pblockiterator);
for (; !pblockiterator->done(); pblockiterator->step())
{
acdbentity *pentity;
pblockiterator->getentity(pentity, acdb::kforwrite);
const char *pcname = pentity->isa()->name();
if(!strcmp(pcname, "acdbtext"))
{
const char *ptext = ((acdbtext*)pentity)->textstring();
cstring st(ptext);
st.replace(m_searchstr,m_replacestr);
if (((acdbtext*)pentity)->settextstring(st) != acad::eok)
{
acutprintf("\nsorry, that draing is probably already open.");
return;
}
}
else if(!strcmp(pcname, "acdbmtext"))
{
const char *pmtext = ((acdbmtext*)pentity)->contents();
cstring st(pmtext);
st.replace(m_searchstr,m_replacestr);
((acdbmtext*)pentity)->setcontents(st);
if(pmtext)
pmtext = null;
}
pentity->close();
}
delete pblockiterator;
pblocktablerecord->close();
pdb->saveas(file);
delete pdb;
我试了一下,就没什么错误。。。
如果你要读取的文件已经在cad中打开了,运行就会有错误,你应该注意到这个问题吧???
不是这个原因,同样不能替换的文件,操作几次,乃至单独替换都不行
,而其他文件又可以,真不知道什莫原因,拜托大家了!
不能替换的文件如下:举一例:
该文件为 autocad 0 文件,请使用idrop将图形拖放到autocad中直接打开。
大家能不能试一试,看看!
。。。我猜是因为前面打开块表和遍历打开实体的时候都没有检查可能不回返eok,后面就堆积错误。。
虽然没看出来为什么,但是至少可以考虑在所有的操作上都检查回返值,确定最先出错的是什么地方。。
virtue is like a rich stone, best plain set.
-- francis bacon, <of beauty>
我通过查找能够替换和不能够替换的dwg文件得到了答案:原来竟然是图纸中有一图层:ashade层是否被锁,只要打开,就可以正常替换,可我所替换的文字不再此层啊,为啥?
怎样用arx设置此层被打开,谢谢!
。。果然。。
代码遍历model space的时候对每一个实体进行写打开,因为处在被锁的图层上的实体是不能修改的,所以写打开操作很可能回返了错误,但是代码没有处理错误,内部堆积到后面就暴走。。
果然对所有的打开操作都是要检查检查再检查的。。
只为了修改文字而把图层解锁不好吧,建议楼主遍历的时候先以读打开,检查实体类型,如果是文字实体再upgradetowrite。。
virtue is like a rich stone, best plain set.
-- francis bacon, <of beauty>
我明白了!谢谢!
|