查看单个帖子
旧 2009-05-04, 04:46 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】block creation

block creation
block creation
what i have to do for creation a block and a reference to this block ?
i open the blocktable, creates a blocktablerecord and add it to the table.
then i add some entities to the blockrecord. after this i create the blockreference and store it to e.g. modelspace.
the file writing crashes.
can you give more on the nature of the crash and provide some code as well?
codefragment, error message
sorry, many tabs inside the code fragment.
call stack
kernel32! 77f1d479()
msvcrt! 78008fa5()
dd_db! 627ebb1f()
and
kernel32! 77f1d479()
msvcrt! 78008fa5()
dd_db! 6286907c()
nexi_acdd_doccoverdecorator::initializeforconverti ng() line 1112
after crash : !! dwgdirecterror : was open for write
oddbblocktableptr pblocks = m_ad2tbh.m_val->getblocktableid().safeopenobject(oddb::kforwrite) ;
// get an iterator for the block table
oddbsymboltableiteratorptr pblkiter = pblocks->newiterator();
for (pblkiter->start(); ! pblkiter->done(); pblkiter->step())
{
// open the block
blocktablerecordptr pblock = pblkiter->getrecordid().safeopenobject(oddb::kforwrite);
// get an entity iterator
oddbobjectiteratorptr pentiter = pblock->newiterator();
// for each entity in the block
oddbvoidptrarray explodeentityset;
oddbvoidptrarray eraseentityset;
oddbvoidptrarray::iterator it;
n_bool iterisstepped = n_true; // for the first step
for ( ; !pentiter->done () ; )
{
if ( iterisstepped == n_false )
pentiter->step ();
if ( pentiter->done () )
break;
iterisstepped = n_false;
oddbentityptr pentity = pentiter->entity(oddb::kforwrite);
odsmartptr<oddbentity_analyzer> pentanalyzer = pentity;
switch ( pentanalyzer->gettype () )
case dbenttype_hatch :
{
n_char* stringidptr;
oddbvoidptrarray explodeset;
oddbhatch subent;
oddbhatchptr psubent;
psubent = pentity;
int length=0;
odresult result = psubent->explode ( explodeset );
if ( result == eok )
{
oddbblocktablerecordptr newblocktablerecordptr = new oddbblocktablerecord;
if ( !newblocktablerecordptr.isnull() )
{
odstring newname;
newname.format("%s_%d",stringidptr,knum++);
newblocktablerecordptr->setname (newname);
// add the new blocktablerecord to the table
pblocks->add (newblocktablerecordptr);
for ( it = explodeset.begin () ; it != explodeset.end () ; ++it )
{
odrxobjectptr pexplodeobject = (*it);
oddbentityptr pexplodeentity = pexplodeobject;
newblocktablerecordptr->appendoddbentity ( pexplodeentity );
}
// add an insert for the new block
oddbblockreferenceptr insertptr = new oddbblockreference;
if ( !insertptr.isnull () )
{
insertptr->setposition (odgepoint3d(0.0,0.0,0.0));
insertptr->setrotation (0.0);
insertptr->setscalefactors (odgescale3d(1.0,1.0,1.0));
insertptr->setblocktablerecord (newblocktablerecordptr->objectid());
pblock->appendoddbentity ( insertptr );
}
}
eraseentityset.push_back ((odrxobjectptr)(pentity));
}
break;
}
}
for ( it = eraseentityset.begin () ; it != eraseentityset.end () ; ++it )
{
odrxobjectptr peraseobject = (*it);
oddbentityptr peraseentity = peraseobject;
peraseentity->erase ();
}
}
}
outver = oddb::vac15;
s_filetype = oddb::kdwg;
odwrfilebuf fb ( tempfilename.data () );
m_ad2tbh.m_val->writefile ( &fb, s_filetype, outver );
openforwrite exception during file writing means that an attempt was made to save to file an object which was opened for write and was not closed.
after a new object is created or existing one is modified dd needs to perform some actions to make the object and database valid. this actions are performed in 'close' procedure. close is performed at the moment the last smart pointer to the object is destroyed or assigned another value (reference counter is used).
you need use one of methods below:
code:
oddbobjectptr pobj = .....
// object is created or modified
pobj.release();
// or
pobj = null;
pdb->writefile();
or
{
oddbobjectptr pobj = .....
// object is created or modified
}
// object is closed as a result of leaving smart pointer's scope
pdb->writefile();
sergey slezkin
heureka !
hi sergej, thank you,
i searched for "close", "save" and "write" inside the documentation.
regards,
uwe
ps : my bug was
oddbblocktablerecordptr pblock1 = new oddbblocktablerecord;
instead
oddbblocktablerecordptr pblock1 = oddbblocktablerecord::createobject ();
last edited by uspiess@nemetschek.de; 28th january 2004 at 11:54 pmfff">.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)