1

How to get ObjectId of the recently modified object? I add some polyline to the drawing. Each one is the same. When one modifies the other, they must also be adjusted to the changes. I need to exclude from the list of objects that need to be updated, the object I just modified. I can not find the answer.

Example: I have some polyline. When creating them, an event handler is added (ObjectId of each object is added to NOD). At the moment of modifying one of them, the function assigned to the modification will loop through all objects stored in NOD. When the length is changed other objects must also do so. Initially I want to do that the rest will be removed and replaced with a modified copy of the object.

Here I need to access the last modified object to be able to skip it while modifying other polyline. At the moment, the program ends and I think this is a problem because I'm trying to convert the polylines to the same one.

Liam
  • 27,717
  • 28
  • 128
  • 190
programmerJavaPL
  • 496
  • 6
  • 23

1 Answers1

0

If I understand your problem correctly, what you need is a dynamic exclusion list. A Hashset<ObjectID> instance will serve you well, as ObjectID is a struct (i.e. a value type). See this tutorial:

HashSet is an unordered collection that contains unique elements. We can apply various operations on a HashSet like, Add, Remove, Contains etc.

Once a polyline is modified by user, I am assuming an event triggers your process to go ahead and modify all other polylines in your NOD. To utilize your exclusion list, add a private field to the class that contains your Command Methods:

private static HashSet<ObjectId> exclusionList = new HashSet<ObjectId>();

Make sure to add the ObjectID of the polyline that the user modified to the exclusionList right away:

exclusionList.Add(modifiedObjectID);

The Add() method returns true if the list does not contain the objectID you tried to add, and adds it to the set. It will return false if the set already contains the ObjectID. This is the key to solving your issue. You add each entity to the exclusion set so that each one is only modified once per cycle. Also, since you already added your original polyline's ObjectID to the set, it will never be modified in the loop. After the loop ends, clear the list and wait for the next time the user modifies an entity.

In your loop that cycles through your MOD, do the following:

public void ProcessEntities()
{
    foreach(DBDictionaryEntry obj in MyNOD)
    {
        //Add each objectID to your exclusion List
        //if it's already there, everything inside the if statement is skipped!
        if(exclusionList.Add(obj.Value))
        {
             //do your object modification here
        }
    }

    //All entities have been processed now
    //clear the list and wait for the next event
    exclusionList.Clear();
}
Nik
  • 1,780
  • 1
  • 14
  • 23