- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello.
I have a simple case.
I have drawing A and drawing B.
I have a block definition (block table record) in A as well as block references to said block definition in the model space.
The block definition contains 2 texts that change from reference to reference when they are created.
What I need to do is copy the references to certain block definition into drawing B.
I wouldn't care about the block definition being in drawing B but my logic dictates that to copy the block references I would first have to copy the block definition, and that's what I have done, and it works just fine.
When trying to add the block references (by going through the model space and seeing which Entities match my criteria) it seems to work fine but the references don't show on screen. the layer that the references belong to does get created even when it was not there before creation. This is my code base on an artile by Kean(article😞
Again, the block definition is there, but the references are not showing u.u
DocumentCollection dm = Application.DocumentManager;
Editor ed = dm.MdiActiveDocument.Editor;
Database destDb = dm.MdiActiveDocument.Database;
Database sourceDb = new Database(false, true);
// Read the DWG into a side database
sourceDb.ReadDwgFile(orignalDrawingFullPath, System.IO.FileShare.Read, true, "");
// Create a variable to store the list of block identifiers
ObjectIdCollection blockIds1 = new ObjectIdCollection();
ObjectIdCollection blockIds2 = new ObjectIdCollection();
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = sourceDb.TransactionManager;
using (Transaction myT = tm.StartTransaction())
{
// Open the block table
BlockTable bt = (BlockTable)tm.GetObject(sourceDb.BlockTableId, OpenMode.ForRead, false);
// Check each block in the block table
foreach (ObjectId btrId in bt)
{
BlockTableRecord btr = (BlockTableRecord)tm.GetObject(btrId, OpenMode.ForRead, false);
// Only add named & non-layout blocks to the copy list
if (btr.Name == "*MODEL_SPACE")
{
foreach (ObjectId item in btr)
{
if (item.ObjectClass.Name == "AcDbBlockReference")
{
BlockReference tempBR = (BlockReference)tm.GetObject(item, OpenMode.ForRead, false);
if (tempBR.Name == "losa-ne")
blockIds2.Add(item);
}
}
}
if (!btr.IsAnonymous && !btr.IsLayout && btr.Name == "losa-ne")
blockIds1.Add(btrId);
btr.Dispose();
}
}
// Copy blocks from source to destination database
IdMapping mapping1 = new IdMapping();
IdMapping mapping2 = new IdMapping();
sourceDb.WblockCloneObjects(blockIds1, destDb.BlockTableId, mapping1, DuplicateRecordCloning.Replace, true);
sourceDb.WblockCloneObjects(blockIds2, destDb.BlockTableId, mapping2, DuplicateRecordCloning.Replace, false);
Solved! Go to Solution.

