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

create block
create block
i am want to create block in autocad.
i has created blocktablerecord in blocktable.
now i want to insert the block(created blocktablerecord ).
visual studio 2005 c++
dwgdirect c++ libraries 2.3.1
coding:
void export::createprimitive( oddbdatabase* pdb, oddbblocktablerecord* pblock, dotcad:rawing::layer^ layer, oddbobjectid btrid )
{
oddbblockreferenceptr pblkref = oddbblockreference::createobject();
pblkref->setdatabasedefaults( pdb );
oddbobjectid btrrefid = pblock->appendoddbentity( pblkref );
pblkref->setlayer( convertlayer( pdb, layer ), true );
pblkref->setblocktablerecord(btrid);
pblkref->setscalefactors( odgescale3d( 20, 20, 20 ) );
oddbblockreferenceptr pblkref1 = btrrefid.safeopenobject( oddb::kforwrite );
odgematrix3d blkxfm;
blkxfm.settranslation( odgevector3d( 1.0, 0.0, 0.0 ) );
pblkref1->transformby(blkxfm);
oddbblocktablerecordptr pblockdef = btrid.safeopenobject();
oddbobjectiteratorptr piter = pblockdef->newiterator();
oddbentityptr pentity;
oddbattributedefinitionptr pattdef;
for(piter->start(); !piter->done(); piter->step())
{
pentity = piter->entity();
pattdef = oddbattributedefinition::cast(pentity);
if((!pattdef.isnull()) && (!pattdef->isconstant()))
{
oddbattributeptr patt = oddbattribute::createobject();
patt->setdatabasedefaults( pdb );
pblkref1->appendattribute( patt );
patt->setpropertiesfrom ( pattdef, false );
patt->setalignmentpoint ( pattdef->alignmentpoint() );
patt->setheight ( pattdef->height() );
patt->sethorizontalmode ( pattdef->horizontalmode() );
patt->setnormal ( pattdef->normal() );
patt->setoblique ( pattdef->oblique() );
patt->setposition ( pattdef->position() );
patt->setrotation ( pattdef->rotation() );
patt->settextstring ( pattdef->textstring() );
patt->settextstyle ( pattdef->textstyle() );
patt->setwidthfactor ( pattdef->widthfactor() );
patt->settextstring ( l"the value" );
patt->transformby ( blkxfm );
}
}
}
the block can't display,why?
pattdef" is always null.
help me . thanks!
(i was referenced "odwriteex" of examples)
block reference may be invisible if
- block does not contain entities :-)
- the entities are on invisible (or frozen) layer,
- the block reference is inserted into a block (pblock) which is not referenced from model of paper spaces (pblock is not inserted into layouts).
pattdef would be always null if the block table record contains no oddbattributedefinition entities.
try to load the saved file into odamfcapp and examine it's structure in tree control.
sergey slezkin
thank you very much.
now ok.
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)