.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cloned Entities have 0 as their object Id's.

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Yehoshua18
180 Views, 1 Reply

Cloned Entities have 0 as their object Id's.

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. 

 

Yehoshua18_1-1680598171661.png

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);
                        }

 

1 REPLY 1
Message 2 of 2
Yehoshua18
in reply to: Yehoshua18

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.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report