How does one create a copy of an entity via a script?
It would be possible to loop through all of the entity's objects and copy all items one-by-one, but hoping there is a faster/better way.
The following are two failed attempts using the CopyManagerWrapper.
Ent = Model.Entities.GetObjectByName("Entity1");
CM = Model.CreateCopyManager();
EntCopy = CM.Copy(Ent);
Ent = Model.Entities.GetObjectByName("Entity1");
EntCopy = Model.CreateNewObject(2002);
CM = Model.CreateCopyManager();
CM.AddObject(Ent);
CM.Copy(EntCopy);
Thanks in advance.
Using TDM 7.1.0.216 Windows 10 Enterprise v. 1809
Bravo, you were almost right with your code, there is only small change:
function main(){
CM = Model.CreateCopyManager();
for(i=0; i<Model.Entities.Count;i++)
{
// add objects which you want to copy
// it's better to copy objects of the same type (don't mix them) at the time
CM.AddObject(Model.Entities.GetObject(i))
}
CM.Copy(Model); // select the destination
// most objects' destination is Model,
// but there are secondary level objects like attributss,
// triggers, ... where the destination is their parent object,
// like Entity or View - you can see that in Model Explorer.
// That is because you can copy from one entity to another
// or even between models
}
1 Like
Thank you for the code example and code comments.