ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

wblockCloneObjects tablestyle

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
daniel_cadext
419 Views, 2 Replies

wblockCloneObjects tablestyle

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
2 REPLIES 2
Message 2 of 3
tbrammer
in reply to: daniel_cadext

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.

Message 3 of 3
daniel_cadext
in reply to: tbrammer

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report