2 Replies Latest reply on Feb 16, 2016 5:32 PM by Artem Taturevych

    Why doesn't MacroFeatureData::SetSelections or SetSelections2 work in C#

    Johannes Kronberger

      I have the following code which runs when my property manager closes.

       

             protected override void OnClose(swPropertyManagerPageCloseReasons_e reason)

              {

                   if (reason ==  swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay)

                  {

                         

                      if(State==StateEnum.Edit)

                      {

                          IBody2[] objects = this.MacroFeature.SelectionMgr.GetSelectedObjects((type,mark)=>type==swSelectType_e.swSelSOLIDBODIES)

                              .Cast<IBody2>()

                              .ToArray();

                          //this.MacroFeature.SwFeatureData.SetSelections(ObjectArrayToDispatchWrapper(objects),null);

                         this.MacroFeature.SwFeatureData.SetSelections(objects,null);

                          Debug.Assert(this.MacroFeature.SwFeatureData.GetSelectionCount()==objects.Length);

                          this.MacroFeature.Write();

                          MacroFeature.ModifyDefinition();

                      }

                      else

                      {

                          IBody2 editBody = null;

                          const int opts = 0;

                          FeatureManagerExtensions.InsertMacroFeature

                              (this.MacroFeature.ModelDoc.FeatureManager, featureName, editBody, opts, this.MacroFeature.Database);

                      }

                  }else if (reason == swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Cancel)

                  {

                      MacroFeature.ReleaseSelectionAccess();

                  }

              }

       

      I have previously called AccessSelections before raising the property page.  When I call SetSelections or SetSelections2 with a normal array or an array of DispatchWrappers the selection count does not change. See the Debug.Assert that tests this.

       

      If I ignore the assert and let the feature commit then I find that the selections have not changed. What may I be doing wrong?

       

      For info my Edit method that raises the property page is

       

             protected override object Edit()

              {

                  ppage = new SamplePropertyPage(this, State);

                  if (SwFeatureData != null)

                  {

                      var result = SwFeatureData.AccessSelections(ModelDoc, null);

                      if(!result)

                          throw new Exception("Expected to get true");

                      {

                          object objects;

                          object objectTypes;

                          object marks;

                          object drViews;

                          object componentXForms;

                          SwFeatureData.GetSelections3(out objects, out objectTypes, out marks, out drViews, out componentXForms);

       

                          if(objects!=null)

                          {

                              var objectsArray = ((object[])objects).Cast<IBody2>().ToList();

                              swSelectType_e[] typesArray = (swSelectType_e[])objectTypes;

       

       

                              ModelDoc.ClearSelection2(true);

                              foreach (var feature in objectsArray)

                              {

                                  feature.Select2(true, null);

                              }

                             

                          }

                      }

       

       

                  }

       

       

                  ppage.Show();

                  return null;

              }