高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】changing the font associated with the standard text style
changing the font associated with the "standard" text style.
changing the font associated with the "standard" text style.
hello, i've been using the following code in order to establish "romans.shx" as the font associated with the standard text style (i have deleted the unnecessary code):
code:
cstring strfilenamedwg;
strfilenamedwg = "c:\\test.dwg";
odwrfilebuf fb(strfilenamedwg);
oddbdatabaseptr pdb = this->createdatabase(true,oddb::kmetric);
oddbobjectid idstdtextstyle = pdb->gettextstylestandardid();
oddbtextstyletablerecordptr ptextstyletablerecordptr =
idstdtextstyle.safeopenobject(oddb::kforwrite);
strtextfilename = "romans.shx";
cstring strpath = "c:\\prog sbesa";
if(!finder.findfile(strpath + "\\" + strtextfilename))
{
cstring strmessage;
strmessage = "didn't find the file";
afxmessagebox(strmessage);
}
ptextstyletablerecordptr->setfilename((odstring&)(strpath + "\\" + strtextfilename));
oddb::savetype filetype;
oddb::dwgversion outver;
filetype = oddb::kdwg;
outver = oddb::vac14;
pdb->writefile(&fb, filetype, outver);
auditinfo aiappaudit;
aiappaudit.setfixerrors(true);
aiappaudit.setprintdest(oddbauditinfo::kboth);
//aiappaudit.sethostappservices(&theapp);
pdb->auditdatabase(&aiappaudit);
std(cout) << "database has been saved to: " << pdb->getfilename().c_str() << std(endl);
}
catch(oderror& e)
{
std(cout) << "error :" << this->geterrordescription(e.code()).c_str() << std(endl);
}
catch(...)
{
std(cout) << "unexpected error." << std(endl);
}
with dd109 this has been working fine but with dd111.01 the program launches an exception while executing "pdb->writefile(&fb, filetype, outver);" with message "was open for write".
audit doesn't report errors.
any idea?
thanks in advance.
the reason is that text style table record you modified is still opened for write while writing the file.
it must be closed. this can be done by calling
ptextstyletablerecordptr.release();
or
ptextstyletablerecordptr = 0;
or
if your smart pointer goes out of scope by the moment the writefile() is called (its destructor will close the object it's referencing if the reference is the last one).
sergey slezkin
|