2 Replies Latest reply on Oct 13, 2015 6:46 AM by Dennis Moll

    PersistentID not equal if selected by keycombination CTRL+ A

    Dennis Moll

      Hello,

       

      I am developing an solidworks add-in where all faces of the body are stored in a C# Dictionary at the AddIn-Startup. The key of my dictionary is the PersistentID of the face and the value is an own implementation of a face class (the class contains the Face2 object, too).

       

      My AddIn listens to the DPartDocEvents_NewSelectionNotifyEventHandler to recognize if the user selects a face by mouse. Afterwards I use the dictionary and the PersistentID of the new selected face to lookup my dictionary. For this example - if the user selects the face by mouse - everything works fine. Both the "ContainsKey" function of the dictionary and the IsSamePersistentID of the ModelDocExtension are able to find my face-object/are able determine the equality of persistent id.

       

      If the user selects the faces by keycombination CTRL+A the event fires, too but both the dictionary lookup and the equality check fail.

       

      Does anybody know if the persistent ids are recalculated if the keycombination is used? And if yes, how to handle it?

       

       

      Here is my code snippet:

       

       

      selectedFaces is my dictionary as described above.

       

       

                      List<object> tempSelectedFaces = new List<object>();

       

                      for (int y = 1; y <= SelectionManager.GetSelectedObjectCount2(-1); y++)

                      {

                      tempSelectedFaces.Add(SelectionManager.GetSelectedObject6(y, -1));

                      }

       

                      foreach (object face in tempSelectedFaces)

                      {

                     

                      if (!selectedFaces.ContainsKey(getObjectsPersistentIDAsString(face)))

                      {

                     ((Entity)face).DeSelect();

                      }

                      }

       

       

                      public string getObjectsPersistentIDAsString(object obj)

                      {

                      return System.Text.Encoding.Default.GetString(ModelDocExtension.GetPersistReference3(obj));

                      }

       

       

       

      Thanks in advance.