WblockCloneObjects method

WblockCloneObjects method

Anonymous
Not applicable
541 Views
0 Replies
Message 1 of 1

WblockCloneObjects method

Anonymous
Not applicable
Hi,

I am trying to import entities from one drawing to current open drawing. I use the WblockCloneObjects method.
Is there anyway to specify that all entities should be copied at 0,0,0 in the current drawing?


Thanks a lot in advance.


ObjectIdCollection acObjIdColl = new ObjectIdCollection();
OpenFileDialog ofd = new OpenFileDialog("\nSelect dwg file from which to copy data", null, "dwg", "DWGFile", OpenFileDialog.OpenFileDialogFlags.DoNotTransferRemoteFiles);
System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
if (dr != System.Windows.Forms.DialogResult.OK)
return;

String fileName = ofd.Filename;
ed.WriteMessage("\n File selected was " + fileName);

//Database sourceDB = new Database(false,true);
//sourceDB.ReadDwgFile(fileName, System.IO.FileShare.ReadWrite, true, "");
DocumentCollection docs = Application.DocumentManager;
Document sourceDoc = docs.Open(fileName);
Database sourceDB = sourceDoc.Database;



int no_EntitiesSourceDWG = 0;
int no_EntSDWGLayerZ = 0;
//We now have Source dwg's database and Destination dwg's database.
//Now create an oid array of source dwg's
Entity[] sourceEntities;

using (Transaction sourceTrans = sourceDB.TransactionManager.StartTransaction())
{
BlockTable sourceBT = (BlockTable)sourceTrans.GetObject(sourceDB.BlockTableId, OpenMode.ForRead);
BlockTableRecord sourceBTR = (BlockTableRecord)sourceTrans.GetObject(sourceBT[BlockTableRecord.ModelSpace], OpenMode.ForRead);
BlockTableRecordEnumerator sourceBTRE = sourceBTR.GetEnumerator();

foreach (ObjectId objID in sourceBTR)
{
no_EntitiesSourceDWG++;
Entity ent = (Entity)sourceTrans.GetObject(objID, OpenMode.ForRead);

if (ent.Layer == "0")
{
no_EntSDWGLayerZ++;
}

}

if (no_EntitiesSourceDWG == 0)
{
ed.WriteMessage("\n No entities in the source drawing");
return;
}

else if (no_EntitiesSourceDWG == no_EntSDWGLayerZ)
{
ed.WriteMessage("\n All entities in the source drawing are on layer 0");
return;
}

else
{
ed.WriteMessage("\n Number of entities in source drawing : " + no_EntitiesSourceDWG);
}




int i = 0;

foreach (ObjectId objID in sourceBTR)
{

Entity ent = (Entity)sourceTrans.GetObject(objID, OpenMode.ForRead);
if (ent.Layer != "0")
{

acObjIdColl.Add(ent.ObjectId);
}


}
sourceTrans.Commit();
}


Document ThisDrawing = Application.DocumentManager.MdiActiveDocument;
DocumentLock docLock = ThisDrawing.LockDocument();

using (Transaction destTrans = db.TransactionManager.StartTransaction())
{
BlockTable destBT = (BlockTable)destTrans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord destBTR = (BlockTableRecord)destTrans.GetObject(destBT[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
// Clone the objects to the new database

sourceDB.WblockCloneObjects(acObjIdColl, destBTR.ObjectId, new IdMapping(), DuplicateRecordCloning.Ignore, false);
destTrans.Commit();
}
docLock.Dispose();
0 Likes
542 Views
0 Replies
Replies (0)