- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,experts
I have a question,It's about "Block Properties Table",I want to use a Block Properties Table to manage a Dynamic
Block.I have defiened a Dynamic Block and its Block Properties Table in Autocad2010,this is the screenshot of the
Block Properties Table(a1:d1=100,d2=200;a2:d1=100,d2=400;a3:d1=100,d2=600;).
Now I want to insert the Dynamic Block using objectarx2010.after I input a command,the block of a2(d1=100,d2=400)
is inserted.
I have written the code,but the code still can't achieve my aim,Can you tell my mistake?Thank you very much!
And I have attached this dwg-file in my post in order to you can test your code with it.
this is the Dynamic Block
this is the the screenshot of the Block Properties Table
static void aeastbbb(void)
{
AcTransaction* pTrans = actrTransactionManager->startTransaction();
AcDbObjectId blkTabId = acdbHostApplicationServices()->workingDatabase()->blockTableId();
AcDbBlockTable* pBlkTab = NULL;
pTrans->getObject((AcDbObject*&)pBlkTab, blkTabId, AcDb::kForRead);
if(pBlkTab->has(_T("c")))
{
AcDbObjectId blockId;
AcDbBlockTableRecord* pBlock = NULL;
pBlkTab->getAt(_T("c"), blockId);
AcDbBlockReference* pRef = new AcDbBlockReference(AcGePoint3d(0,0,0), blockId);
AcDbObjectId msId;
AcDbBlockTableRecord* pMS = NULL;
pBlkTab->getAt(ACDB_MODEL_SPACE, msId);
pTrans->getObject((AcDbObject*&)pMS, msId, AcDb::kForWrite);
// Add the block reference to the dwg/database first!!!!
pMS->appendAcDbEntity(pRef);
actrTransactionManager->addNewlyCreatedDBRObject(pRef);
// Check to make sure it is a dynamic block
AcDbDynBlockReference dynBlkRef(pRef->id());
if(dynBlkRef.isDynamicBlock())
{
// These are the names of the available visibilty states
//AcArray visNames;
AcStringArray varNames,visNames;
visNames.append(_T("a1"));
visNames.append(_T("a2"));
visNames.append(_T("a3"));
varNames.append(_T("user1"));
AcDbDynBlockReferencePropertyArray propArr;
dynBlkRef.getBlockProperties(propArr);
acutPrintf(_T("\n the length is %d"), propArr.length());//
for(int i = 0; i < propArr.length(); i++)
{
AcDbDynBlockReferenceProperty prop = propArr.at(i);
AcDbEvalVariant val = prop.value();
int iVar = 0;
acutPrintf(_T("\npropertyName is %s "), prop.propertyName());
if (varNames.find(prop.propertyName(),iVar))
{
acutPrintf(_T("\npropertyName is %s "), prop.propertyName());
acutPrintf(_T("\n the length is %d"), iVar);//
acutPrintf(_T("\n zhangzhang !!!!!!!!!!"));
AcDbEvalVariantArray allowedVals;
prop.getAllowedValues(allowedVals);
acutPrintf(_T("\n the allowedVals is %d"), allowedVals.length());//
AcDbEvalVariant visVal(visNames.at(2));
prop.setValue(visVal);
}
}
}
}
actrTransactionManager->endTransaction();
}
Solved! Go to Solution.