ObjectARX

Reply
Active Contributor
Posts: 32
Registered: ‎01-29-2013
Message 1 of 9 (399 Views)
Accepted Solution

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

399 Views, 8 Replies
03-04-2013 04:32 AM

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:smileywink:.
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();


}


 

 

 

 

 

 

 

Moderator
Alexander.Rivilis
Posts: 1,346
Registered: ‎04-09-2008
Message 2 of 9 (387 Views)

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

03-04-2013 06:38 AM in reply to: zhangxinhua789

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? :smileymad:

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
Posts: 32
Registered: ‎01-29-2013
Message 3 of 9 (378 Views)

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

03-04-2013 04:51 PM in reply to: Alexander.Rivilis

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!

Active Contributor
Posts: 32
Registered: ‎01-29-2013
Message 4 of 9 (360 Views)

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

03-06-2013 04:27 AM in reply to: Alexander.Rivilis

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!  

Moderator
Alexander.Rivilis
Posts: 1,346
Registered: ‎04-09-2008
Message 5 of 9 (355 Views)

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

03-06-2013 04:44 AM in reply to: zhangxinhua789

zhangxinhua789 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.

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Moderator
Alexander.Rivilis
Posts: 1,346
Registered: ‎04-09-2008
Message 6 of 9 (352 Views)

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

03-06-2013 05:59 AM in reply to: Alexander.Rivilis

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

 

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
Posts: 32
Registered: ‎01-29-2013
Message 7 of 9 (337 Views)

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

03-07-2013 03:04 AM in reply to: Alexander.Rivilis

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!

Moderator
Alexander.Rivilis
Posts: 1,346
Registered: ‎04-09-2008
Message 8 of 9 (333 Views)

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

03-07-2013 03:29 AM in reply to: zhangxinhua789

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


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Active Contributor
Posts: 32
Registered: ‎01-29-2013
Message 9 of 9 (329 Views)

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

03-07-2013 04:34 AM in reply to: Alexander.Rivilis

Ok

Thank you very much!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community