wblockCloneObjects tablestyle

wblockCloneObjects tablestyle

daniel_cadext
Advisor Advisor
639 Views
2 Replies
Message 1 of 3

wblockCloneObjects tablestyle

daniel_cadext
Advisor
Advisor

Why doesn't this work? It does with other dictionaries.

There's no errors, nothing happens

 

 static void AcRxPyApp_idoit(void)
 {
     AcDbDatabase* pDestDb = acdbHostApplicationServices()->workingDatabase();

     std::unique_ptr<AcDbDatabase> pSrcDb(new AcDbDatabase(false, true));

     if (auto es = pSrcDb->readDwgFile(_T("E://SrcTableStyle.dwg")); es != eOk)
         acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

     if (auto es = pSrcDb->closeInput(true); es != eOk)
         acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

     AcDbIdMapping idmap;
     AcDbObjectIdArray ids;
     ids.append(pSrcDb->tablestyle());

     if (auto es = pDestDb->wblockCloneObjects(ids, pDestDb->tableStyleDictionaryId(), idmap, AcDb::kDrcReplace, false); es != eOk)
         acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));
 }

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Accepted solutions (1)
640 Views
2 Replies
Replies (2)
Message 2 of 3

tbrammer
Advisor
Advisor
Accepted solution

I tried your code. If the name of the the current tablestyle in the source DB  does not exist in the target DB, it works fine. But if the tablestyle exists in the destination DB, the style is not overwritten - even though you pass
AcDb::DuplicateRecordCloning drc = AcDb::kDrcReplaceSeems to be a bug in the SDK.

Workaround: Check for existence and erase the style from the target DB if it exist.

 

For the sake of completeness: I replaced std::unique_ptr<AcDbDatabase> pSrcDb; 
by AcDbDatabase *pSrcDb; / delete pSrcDb. But this shouldn't make any difference.


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 3 of 3

daniel_cadext
Advisor
Advisor

Thanks for testing this, I think it’s a bug as well, or Autodesk didn’t want to nuke existing tables that have a tablestyleid assigned.  kDrcMangleName and swap id seems to work, and may be the safest approach

 

 

    static void AcRxPyApp_idoit(void)
    {
        AcDbDatabase* pDestDb = acdbHostApplicationServices()->workingDatabase();

        std::unique_ptr<AcDbDatabase> pSrcDb(new AcDbDatabase(false, true));

        if (auto es = pSrcDb->readDwgFile(_T("E://SrcTableStyle.dwg")); es != eOk)
            acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

        if (auto es = pSrcDb->closeInput(true); es != eOk)
            acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

        AcDbIdMapping idmap;
        AcDbObjectIdArray srcids;
        srcids.append(pSrcDb->tablestyle());
        AcDbObjectId ownerId = pDestDb->tableStyleDictionaryId();

        if (auto es = pDestDb->wblockCloneObjects(srcids, ownerId, idmap, AcDb::kDrcMangleName, false); es != eOk)
            acutPrintf(_T("\nOops %ls"), acadErrorStatusText(es));

        AcDbIdPair idPair;
        AcDbIdMappingIter iter(idmap);
        for (iter.start(); !iter.done(); iter.next())
        {
            if(!iter.getMap(idPair))
                continue;
            if (idPair.key() == pSrcDb->tablestyle())
            {
                const auto sid = idPair.value();
                {
                    AcDbObjectPointer<AcDbObject> newStyle(sid, AcDb::kForWrite);
                    newStyle->swapIdWith(pDestDb->tablestyle(), true, true);
                }
                {
                    AcDbObjectPointer<AcDbObject> oldStyle(sid, AcDb::kForWrite);
                    oldStyle->erase();
                }
                break;
            }
        }
    }

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes