Hello,
I want to copy a block in a drawing to anotherblock in the same drawing. First I inserted a WBock thats OK.
But How can I copy a block(blokreference) in .NET?
I tryed deepclone and getTransformedCopy
I have the following code:
using (Transaction trans = databas.TransactionManager.StartTransaction())
{
Database db = new Database(false, false);
db.ReadDwgFile(comp, System.IO.FileShare.Read, true, "");
ObjectId NewBlkId = new ObjectId();
NewBlkId = doc.Database.Insert(comp, db, false);
BlockTable bt = (BlockTable)trans.GetObject(databas.BlockTableId,
OpenMode.ForRead, true);
BlockTableRecord btr
= (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
BlockReference bref = new BlockReference(new
Autodesk.AutoCAD.Geometry.Point3d(10, 10, 0), NewBlkId);
btr.AppendEntity(bref);
trans.AddNewlyCreatedDBObject(bref, true);
Matrix3d matr = new Matrix3d();
;
BlockReference bref2 = (BlockReference)bref.GetTransformedCopy(matr);
//I tryed this but I get an exception that the block already exist:
//BlockReference bref4 = (BlockReference)bref.DeepClone(bref2, new IdMapping(), true);
btr.AppendEntity(bref2);
trans.AddNewlyCreatedDBObject(bref2, true);
trans.Commit();
}
What I am doing wrong?
thanks
jobro