70001229 A method to replace an object in the vdEntities collection with a new one

Article 70001229
Type Wish
Product Engine
Version 7012
Date Added 11/28/2017
Fixed 7.7014.0.1 (11/30/2017)
Submitted by Wayne Romer

Summary

A method to replace an object in the vdEntities collection with a new one

Solution

A new method ReplaceItem of vdEntities was added in version 7014.0.2

bool ReplaceItem(int id, vdFigure newobject)

Fast replace an entity in passed position of this collection with a new one
id: A zero based index where the new entity will be placed.
newobject: The new entity of vdFigure type that will replace an old one in this collection
returns True on success.

NOTE:
It is very important to know the position of the object without calling the getRealPosition method (e.g. inside a for statement) because if you call the getRealPosition method you will loose all the speed advantage of this method.
The newobject must not have an owner.If it has it must be removed before this method call.
The newobject must not have a handle
If the method succes the newobject will take the same handle and same guid as the existing.
This change is not added to the undo history
The vdFigure.MatchProperties can be used before or after this method,in order the newobject get same common properties with existing.For example Layer PenColor etc.

Example

Replace all vdLine type entities of model entities, with vdCircle type

for (int i = 0; i < doc.Model.Entities.Count; i++)
{
vdFigure fig = doc.Model.Entities[i];
vdLine line = fig as vdLine;
if (line == null) continue;
vdCircle circle = new vdCircle(doc, (line.StartPoint + line.EndPoint) / 2.0, line.Length() / 2.0);
doc.Model.Entities.ReplaceItem(i,circle );
}

Send comments on this topic.