- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm using the code below (which was posted on this forum, I forgot who posted this.)
When I try to deep clone some blocks, I'm getting eNotApplicable error at line cloned.TransformBy(transform) for some blocks.
I've noticed that this does not happen to all blocks.
When the code works, the loop foreach (IdPair pair in mapping) iterates only one time.
When the code fails, foreach loops many more times in one of which it fails. (result view shown when it fails in below image (Image 1).
I've also shown the cloned object which fails.
Could any one please help?
public static void DoDatabaseDeepClone(Transaction tran,
ObjectId entId, Matrix3d transform)
{
//using (var tran =
//entId.Database.TransactionManager.StartTransaction())
//{
var ent = (Entity)tran.GetObject(entId, OpenMode.ForRead);
ObjectId ownerId = ent.OwnerId;
var mapping = new IdMapping();
ObjectIdCollection ids = new ObjectIdCollection(
new ObjectId[] { entId });
entId.Database.DeepCloneObjects(ids, ownerId, mapping, false);
foreach (IdPair pair in mapping)
{
if (pair.IsCloned)
{
var cloned = tran.GetObject(
pair.Value, OpenMode.ForRead) as Entity;
if (cloned != null)
{
cloned.UpgradeOpen();
cloned.TransformBy(transform);
}
}
}
// tran.Commit();
//}
}
I'm calling the method like this.
if (bt.Has(blockName))
{
BlockReference original = BlockMethods.InsertBlock(blockName, startPoint, modelSpace, db, trans);
//modelSpace.AppendEntity(original);
// trans.AddNewlyCreatedDBObject(original, true);
Point3d insertPoint = startPoint;
for (int i = 0; i < columns; i++)
{
insertPoint = startPoint + new Vector3d(1, 0, 0) * 2800 * i;
Vector3d moveVector = startPoint.GetVectorTo(insertPoint);
if (i != 0)
{
Matrix3d translation = Matrix3d.Displacement(moveVector);
BlockMethods.DoDatabaseDeepClone(trans, original.ObjectId, translation);
}
for (int j = 1; j < rows; j++)
{
//insertTower(blockName, insertPoint, modelSpace, db, trans);
insertPoint = insertPoint + new Vector3d(0, 1, 0) * 950;
Vector3d moveVec = startPoint.GetVectorTo(insertPoint);
Matrix3d tranmat = Matrix3d.Displacement(moveVec);
BlockMethods.DoDatabaseDeepClone(trans, original.ObjectId, tranmat);
}
}
Image 1
Image 2
Thanks in advance!
Solved! Go to Solution.
Link copied