how to use a Block Properties Table of a a Dynamic Block in objectarx2010?

This widget could not be displayed.

how to use a Block Properties Table of a a Dynamic Block in objectarx2010?

Anonymous
Not applicable

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

1.png

 

this is the  the screenshot of the Block Properties Table

 

2.png

 

 

 

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();


}


 

 

 

 

 

 

 

0 Likes
Reply
Accepted solutions (1)
2,021 Views
8 Replies
Replies (8)

Alexander.Rivilis
Mentor
Mentor
Accepted solution

I did not found any public API in native ObjectARX which allow read/write Block Properties Table. With help of AutoCAD .NET API you can access it:

Reading the Block Table of a Dynamic Block

 

P.S.: Again you are creating multiple topic/posts with the same content? Smiley Mad

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Anonymous
Not applicable

Hello,expert

I am very sorry,but the content Is not completely the same,they are a Alittle different. Since I  find that it is very convenient to manage the block using the Block Properties Table.

Thanks again!

0 Likes

Anonymous
Not applicable

Hello,experts
I have read the help of the Block Table of a Dynamic Block,but I don't want to access the content of the Block Properties Table,my purpose is to insert the Dynamic Block(user1=a2,d1=100,d2=400).I think that is to set the value of user1,but I don't know the function,can you tell me the code ?
Thank you very much!  

0 Likes

Alexander.Rivilis
Mentor
Mentor

@Anonymous wrote:

Hello,experts
I have read the help of the Block Table of a Dynamic Block,but I don't want to access the content of the Block Properties Table,my purpose is to insert the Dynamic Block(user1=a2,d1=100,d2=400).I think that is to set the value of user1,but I don't know the function,can you tell me the code ?
Thank you very much!  


IMHO to find out what values can be assigned to user1 you must read Block Properties Table (BPT). But it is impossible in native ObjectARX (it was wish-listed).

I've tried to set to user1 string value "a2". But values of d1 and d2 was not assigned automatically. So those value have to be assigned with values from BPT corresponding to user1 == "a2". But with native ObjectARX it is impossible to read cells of BPT. You have to use mixed/managed ObjectARX C++ (or AutoCAD .NET API) In order to achieve the result.

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes

Alexander.Rivilis
Mentor
Mentor

If it suits you, then you can assign values without BPT:

static void InsBlk(void)
{
    AcDbDatabase *pCurDb = acdbCurDwg();
    AcDbObjectId idCurSpace = pCurDb->currentSpaceId();
    ACHAR blockName[512] = _T("");
    if (acedGetString(TRUE, _T("\nEnter block name: "),blockName) != RTNORM) 
        return;
    AcGePoint3d pIns;
    if (acedGetPoint(NULL,_T("\nEnter position: "),asDblArray(pIns)) != RTNORM) 
        return;
    AcGeMatrix3d matUCS; acedGetCurrentUCS(matUCS); pIns.transformBy(matUCS);
    AcDbObjectId idBTR;
    {
        AcDbBlockTableRecordPointer pBTR(blockName, pCurDb, AcDb::kForRead);
        if (pBTR.openStatus() != Acad::eOk) {
            acutPrintf(_T("\nBlock <%s> not found!"), blockName);
            return;
        }
        idBTR = pBTR->objectId();
    }

    AcDbObjectPointer<AcDbBlockReference> pBref; pBref.create();
    pBref->setBlockTableRecord(idBTR);
    pBref->setPosition(pIns);
    AcDbObjectId idBref;
    {
        AcDbBlockTableRecordPointer pBTRCurSpace(idCurSpace, AcDb::kForWrite);
        if (pBTRCurSpace.openStatus() != Acad::eOk) return;
        pBTRCurSpace->appendAcDbEntity(idBref,pBref);
    }

    // NOTE: Skip adding attributes to block reference

    AcDbDynBlockReference pDynRef(pBref);
    if (!pDynRef.isDynamicBlock()) {
        acutPrintf(_T("\nBlock <%s> is not dynamic!"), blockName);
        return;
    }
    AcDbDynBlockReferencePropertyArray propArr;
    pDynRef.getBlockProperties(propArr);

    typedef std::map<AcString, AcDbEvalVariant> MapVars; MapVars vars;
    //////////////////////////////////////////////
    // Fill map with pairs: (VarName VarValue)
    //////////////////////////////////////////////
    vars[_T("user1")] = AcDbEvalVariant(_T("a2"));
    vars[_T("d1")]    = AcDbEvalVariant(100.0);
    vars[_T("d2")]    = AcDbEvalVariant(400.0);
    MapVars::iterator iterVars;
    Acad::ErrorStatus es;
    for (int i = 0; i < propArr.length(); i++) {
        AcDbDynBlockReferenceProperty prop = propArr[i];
        if ((iterVars = vars.find(prop.propertyName())) != vars.end()) {
            prop.setValue(iterVars->second);
        }
    }
}

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes

Anonymous
Not applicable

Hello,experts
   as I have a lot of similar data to deal with,I have to use BPT,you know it is very convenient to deal with a lot of similar data using BPT;
  I want to begin to learn  AutoCAD .NET API. I have read the help about it,but I still don't know what the code is,Can you tell me the code of AutoCAD .NET API which can achieve my goal.
Thank you very much!

0 Likes

Alexander.Rivilis
Mentor
Mentor

Please create topic with your's question in .NET board.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes

Anonymous
Not applicable

Ok

Thank you very much!

0 Likes