Author Topic: Copy block definitions - Beta testing  (Read 8624 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Copy block definitions - Beta testing
« on: May 10, 2010, 12:59:30 PM »
I guess it really should be called ' replace block definitions ', but I've called it ' copy block definitions ' for now.

What it does:
It will allow you to update/replace a block definition within a file, open current/non-current or closed, from another file, open current/non-current or closed.  It will let you map attributes definitions between the old/new blocks.  It will erase all old attribute references associated with the inserts of said blocks, and replace them with attributes from the new block.  It will save drawings where block definitions are updated/replaced only if the drawing is not opened.  If the drawing is open, and not current, it will make that drawing active, update the blocks, then switch back to the drawing the routine was called in.  You can update the same block in many drawings at once by selecting all drawings you want updated.  You can remove the mapping of either block or attribute by right clicking on them in the mapping views.

To call, either build it from the files in the zip, or just ' netload ' the dll file, and type ' CBD ' at the command line.

As always, comments/suggestions/concerns/ideas/criticisms are all welcomed.  Thanks in advance.  I have tested it, and it works well.  The only time I got it to error, was when I tried to update a block in the same file I was getting the new definition from.  I'm working on this issue now.

Edit:  Issue fixed, with copying/replacing within the same drawing.  Needed to commit the actions within the transaction that edited the block definition.  Didn't update code in post though.
« Last Edit: May 10, 2010, 01:49:59 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Copy block definitions - Beta testing
« Reply #1 on: May 11, 2010, 02:22:01 AM »
Excellent work!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy block definitions - Beta testing
« Reply #2 on: May 11, 2010, 11:01:34 AM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Copy block definitions - Beta testing
« Reply #3 on: May 12, 2010, 07:41:07 AM »
Nicely done Tim!

vegbruiser

  • Guest
Re: Copy block definitions - Beta testing
« Reply #4 on: May 12, 2010, 09:04:26 AM »
This looks really good Tim, I have one question though; What version of AutoCAD does this work with?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy block definitions - Beta testing
« Reply #5 on: May 12, 2010, 11:20:35 AM »
Nicely done Tim!

Thanks Glenn.

This looks really good Tim, I have one question though; What version of AutoCAD does this work with?

I wrote it while on '09, but I think it should be fine to use in earlier version, as I don't think I use anything that wasn't there before '09, but that would take some testing.  It is built with .Net 2.0 in mind, so in earlier version you may have to tell it to use the latest version of .Net.



I'm trying to get dynamic blocks to work now.  Once I get those I'll post a newer version.  They are proving a little move elusive than I thought they were going to be, but I have some ideas of how to handle them.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE3

  • Guest
Re: Copy block definitions - Beta testing
« Reply #6 on: May 12, 2010, 11:29:36 AM »
Hi Tim,

Have not seen your code, it is this tool for your workplace? (if it is, nice that you have that opportunity) or just as normal to fill the need of coding? :)


Have a good one sir!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy block definitions - Beta testing
« Reply #7 on: May 12, 2010, 11:31:48 AM »
Hi Tim,

Have not seen your code, it is this tool for your workplace? (if it is, nice that you have that opportunity) or just as normal to feel the need of coding? :)

More that I have seen it requested plenty of times, and thought it would be fun to see how to code it.  If work wants to use it, then cool, but not really a code I would use at work very often.

Have a good one sir!

Thanks, and you too sir.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Glenn R

  • Guest
Re: Copy block definitions - Beta testing
« Reply #8 on: May 12, 2010, 11:47:11 AM »
I think the dialog is too small - can you make it larger, Tim?  :evil:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy block definitions - Beta testing
« Reply #9 on: May 12, 2010, 12:13:39 PM »
I think the dialog is too small - can you make it larger, Tim?  :evil:

I was trying, but then there was so much empty space.... I said forget it.  Then said to myself ' this is just the right size to have all the information visible '.   :lmao:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy block definitions - Beta testing
« Reply #10 on: May 12, 2010, 07:58:07 PM »
In my quest to find a way to have dynamic blocks work, I decided to try a different way to copy over the blocks.  The problem is that it seems like I need to translate them, as it's crashing like it was before.  So my question is, how would I translate the object id's, using the code below?

Thanks for any tidbits.

Code: [Select]
string tempBlkName = "lkasjdflkj3523489579";
using ( Database tempDb = deDb.Wblock( deObjId ) ) {
reBlkTblRec.Name = tempBlkName;
ObjectId BlkId = reDb.Insert( rb.Name, tempDb, true );
BlockTableRecord BlkTblRec = reTrans.GetObject( BlkId, OpenMode.ForWrite ) as BlockTableRecord;
BlkTblRec.SwapIdWith( reBlkTblRec.ObjectId, true, false );
MapAttributes( BlkTblRec.ObjectId, rb.AttributeMapping );
reBlkTblRec.Erase();
}
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy block definitions - Beta testing
« Reply #11 on: May 13, 2010, 03:05:34 PM »
The problem seems to be with the SwapIdWith method.  It will swap the information, but it will still be associated with the old block record, so once that is erased, then Acad crashes.  If I don't delete the old block record, then it won't crash, but another error occur.  The error is when one inserts the new block, it has nothing associated with it, but if you insert the old block, it will show it correct, but it will be listed as the new block.  So it seems like not everything is getting switched like it should.  I'm still doing some testing, but I haven't seen this happen to anyone else, at least I haven't found anything on the net stating this, so I wanted to share my experience.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE3

  • Guest
Re: Copy block definitions - Beta testing
« Reply #12 on: May 13, 2010, 03:34:42 PM »
Tim, do you have access to the adn? there is a doc about the SwapIdWith (ARX) usage in particular.

or do you have seen the arx sample ARXDBG MapTest.cpp (SDK 2008 - might be also on the new ones)
Quote
void         
MapTestReactor::endInsert(AcDbDatabase* pTo)
{
        // only worried about this when going back to the original
        // database.
    if (m_cloneState != kExportInsert)
        return;

    AcDbObjectIdArray eraseList;
    Acad::ErrorStatus es;
    AcDbEntity* ent;

        // go through the swap list and swapIds with the original
        // entity.  I think it is safe to only worry about Entities
        // that got cloned and not objects.  In AEC's case, anchors
        // are directly owned by the entity and got cloned, so no
        // swapping should be necessary.  In the case of Dictionary
        // objects, they have already been merged or remapped by
        // the AcDbDatabase::insert() operation.  So, in this loop,
        // only look for objects of type AcDbEntity when doing the
        // swap.
    ObjIdMapNode* tmpNode;
    int len = m_objIdMap.length();
    int i;
    for (i=0 ; i<len; i++) {
        tmpNode = static_cast<ObjIdMapNode*>(m_objIdMap);

        es = acdbOpenAcDbEntity(ent, tmpNode->m_origExtId, AcDb::kForWrite);
        if (es == Acad::eOk) {
            printObj(_T("Swap from"), ent);
            printObj(_T("Swap to"), tmpNode->m_newExtId);

            es = ent->swapIdWith(tmpNode->m_newExtId);
            if (es != Acad::eOk) {
                acutPrintf(_T("\nERROR: could not swap object: (%s)"), ArxDbgUtils::rxErrorStr(es));
            }
            else {
                    // don't erase anything until all the swapping is completed.
                    // In AEC, erasing some entities that "own" another implicitly
                    // cause others to be erased.  That would screw up the swapping
                    // process if done in mid-stream.  So, just add them to a list
                    // and erase them after things have finished.
                eraseList.append(tmpNode->m_newExtId);    // we swapped Ids with orignal, so use newId
            }

            ent->close();
        }

        // else case isn't necessarily an error, because there will be
        // AcDbObjects that were in the clone set because they were referenced
        // by the entities.
    }

        // walk list of objects again, this time erasing them since things have
        // now quieted down and the set of objects is stable.
    len = eraseList.length();
    for (i=0; i<len; i++) {
        es = acdbOpenAcDbEntity(ent, eraseList, AcDb::kForWrite);
        if (es == Acad::eOk) {
            ent->erase();
            ent->close();
        }
    }
}


don't recall I ever used this method before... hope it helps some how...

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Copy block definitions - Beta testing
« Reply #13 on: May 13, 2010, 04:37:29 PM »
I do have access to ADN, but the last time I looked for something with this routine, I didn't find anything that helped.  I'll take a look at the ADN article, and the code you provided, to see if I can understand what is happening, and how I can fix it.  Have to do real work right now though.  :cry:

Thanks Luis.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

LE3

  • Guest
Re: Copy block definitions - Beta testing
« Reply #14 on: May 13, 2010, 04:49:10 PM »
I do have access to ADN, but the last time I looked for something with this routine, I didn't find anything that helped.  I'll take a look at the ADN article, and the code you provided, to see if I can understand what is happening, and how I can fix it.  Have to do real work right now though.  :cry:

Thanks Luis.

Are these ones:
http://adn.autodesk.com/adn/servlet/devnote?siteID=4814862&id=5415095&linkID=4900509
http://adn.autodesk.com/adn/servlet/devnote?siteID=4814862&id=10354467&linkID=4900509

not much of a help as normal on their samples over there... but you'll never know :)