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.
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
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()