Hi!
I'm running through a ObjectID collection, creating clones of the objects, then adding them to the block table record, and transaction. The problem is that I'm also trying to create a second ObjectID collection for just the cloned entities. The problem is that each time the loop runs, the cloned entities have a Object Id of zero.
Anyone know why, and how to fix this / get around it?
Thanks!
ObjectIdCollection entityCopyCol = new ObjectIdCollection();
foreach (ObjectId objectId in ObjID)
{
Entity entity = (Entity)trans3.GetObject(objectId, OpenMode.ForRead);
Entity entityCopy = (Entity)entity.Clone();
entityCopyCol.Add(entityCopy.ObjectId);
if (entityCopy.GetType() == typeof(MText))
{
MText MtextSendBack = entityCopy as MText;
if (MtextSendBack.Contents.Contains("Status"))
{
doc.Editor.WriteMessage("\n You Entity Was Found!");
idSendBack = entityCopy.ObjectId;
}
}
btr3.AppendEntity(entityCopy);
trans3.AddNewlyCreatedDBObject(entityCopy, true);
}
Solved! Go to Solution.
Solved by Yehoshua18. Go to Solution.
Ok! After a good number of hours of research I have reached a solution! The Entities are not assigned object id's until they are added to the database!
Sorry for spamming the forums. I only post a question after I've spent a good few hours trying to figure it out myself. Somehow though, I tend to find the answer a short time after finally convincing myself I need to ask. But I figure if I had this issues, someone might in the future. So here's the solution.
ObjectIdCollection entityCopyCol = new ObjectIdCollection();
foreach (ObjectId objectId in ObjID)
{
Entity entity = (Entity)trans3.GetObject(objectId, OpenMode.ForRead);
Entity entityCopy = (Entity)entity.Clone();
btr3.AppendEntity(entityCopy);
trans3.AddNewlyCreatedDBObject(entityCopy, true);
entityCopyCol.Add(entityCopy.ObjectId);
if (entityCopy.GetType() == typeof(MText))
{
MText MtextSendBack = entityCopy as MText;
if (MtextSendBack.Contents.Contains("Status"))
{
doc.Editor.WriteMessage("\n You Entity Was Found!");
idSendBack = entityCopy.ObjectId;
}
}
}
Can't find what you're looking for? Ask the community or share your knowledge.