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

Exporting dynamic annotative block to dwg

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Ertqwa
791 Views, 2 Replies

Exporting dynamic annotative block to dwg

Hello Forum,

 

I have a drawing with a dynamic annotative block. I want to export that block to another (new) drawing (similar as AutoCAD's wblock command). But whatever I try, I never get the block as a drawing, but always end up with a drawing containing the block.

 

Some of the things I tried:

 

i.e. 1:

structObjectId = objBlockTable[strBlockName];

objBlockTableRecord = (BlockTableRecord)objTransaction.GetObject(structObjectId, OpenMode.ForRead);

objBlockTableRecord.Database.SaveAs(strDirectory + strBlockName + ".dwg", DwgVersion.Current);

 

i.e. 2:

ObjectIdCollection objObjectIdCollection = new ObjectIdCollection();

objBlockTableRecord = (BlockTableRecord)objTransaction.GetObject(objBlockTable[strItem], OpenMode.ForRead);

foreach (ObjectId objObjectId in objBlockTableRecord)

{   

  objObjectIdCollection.Add(objObjectId);}Database objDatabaseNew = new Database(true, false);

  objDatabase.Wblock(objDatabaseNew, objObjectIdCollection, new Point3d(0, 0, 0), DuplicateRecordCloning.Replace);

  objDatabaseNew.SaveAs(strDirectory + strItem + ".dwg", DwgVersion.Current);

}

 

i.e. 3 (not clear yet what this one does):

objBlockReference.SaveAs()

 

 

Any help would be greatly appreciated.

2 REPLIES 2
Message 2 of 3
norman.yuan
in reply to: Ertqwa

You may want to try one of the overloaded Database.WBlock() method that returns a Database object:

 

...

if (objBlockTable.Has(strBlockName]))

{

    //Wblock to a new database, which is the block as drawing

    using (Database blkDwg=objDatabase.WBlock(objBlockTable[strBlockName]))

    {

        //Save it to file

        blkDwg.SaveAs("C:\\My Blocks\" + strBlockName + ".dwg")

    }

}

 

Comments on your 3 approaches:

 

1. You save the current drawing database with renaming it to the block's name. Of course it is not what you want;

2. You create a new drawing database, and then you WBlock your target block into the drawing. Thus, you get a drawing with that block in it;

3. As you already knew, there is no such thing as Blockreference.SaveAs()

Message 3 of 3
Ertqwa
in reply to: norman.yuan

Thanks, just what I needed!

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost