|
发表于 2006-8-30 15:48:00
|
显示全部楼层
属性和属性定义的问题:
class bjt:
public AcEdJig
{
AcGePoint3d mTo;
AcDbBlockReference* br;
public:
AcDbObjectId append()
{
AcDbBlockTableRecord *btr;
acdbOpenObject(btr,br->blockTableRecord(),kForRead);
if(btr->hasAttributeDefinitions())
{
AcDbBlockTableRecordIterator *it;
btr->newIterator(it);
for(;!it->done();it->step())
{
AcDbEntity *pEnt;
it->getEntity(pEnt, AcDb::kForRead);
// Make sure the entity is an attribute definition
// and not a constant.
//
AcDbAttributeDefinition *pAttdef = AcDbAttributeDefinition::cast(pEnt);
if (pAttdef != NULL && !pAttdef->isConstant())
{
// We have a non-constant attribute definition,
// so build an attribute entity.
//
AcDbAttribute *pAtt = new AcDbAttribute();
pAtt->setPropertiesFrom(pAttdef);
pAtt->setInvisible(pAttdef->isInvisible());
// Translate the attribute by block reference.
// To be really correct, the entire block
// reference transform should be applied here.
//
AcGePoint3d basePoint = pAttdef->position();
basePoint += br->position().asVector();
pAtt->setPosition(basePoint);
pAtt->setHeight(pAttdef->height());
pAtt->setRotation(pAttdef->rotation());
pAtt->setTag(pAttdef->tag());
pAtt->setFieldLength(25);
char *pStr = pAttdef->tag();
pAtt->setTag(pStr);
free(pStr);
pAtt->setFieldLength(pAttdef->fieldLength());
pAtt->setTextString("Assigned Attribute Value");
br->appendAttribute(pAtt);
pAtt->close();
}
pEnt->close();
}
delete it;
}
btr->close();
return AcEdJig::append();
}
//////////////////////////////////////////////////////////////////////////
virtual DragStatus sampler()
{
DragStatus stat;
setUserInputControls((UserInputControls)
(AcEdJig::kAccept3dCoordinates
| AcEdJig::kNoNegativeResponseAccepted
| AcEdJig::kNoZeroResponseAccepted));
static AcGePoint3d axisPointTemp;
stat = acquirePoint(mTo);
if (axisPointTemp != mTo)
axisPointTemp = mTo;
else if (stat == AcEdJig::kNormal)
return AcEdJig::kNoChange;
return stat;
}
//////////////////////////////////////////////////////////////////////////
virtual Adesk::Boolean update()
{
br->setPosition(mTo);
return Adesk::kTrue;
}
//////////////////////////////////////////////////////////////////////////
virtual AcDbEntity* entity() const
{
return br;
}
//////////////////////////////////////////////////////////////////////////
void start()
{
br=0;
AcDbBlockTable *bt;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(bt,kForRead);
AcDbObjectId bid;
try
{
char text[1024];
if(RTNORM!=acedGetString(1,"input name",text))throw(0);
if (bt->getAt(text,bid)!=eOk)throw(0);
}
catch(...)
{
bt->close();
return;
}
bt->close();
br=new AcDbBlockReference(AcGePoint3d::kOrigin,bid);
setDispPrompt("Jig a Block");
drag();
append();
}
};
另:
static void BlockJigTestnewJ(void)
{
// Add your code for command BlockJigTest.newJ here
bjt b;
b.start();
}
|
|