AnsweredAssumed Answered

Hiding visible components in a drawing

Question asked by William Cruz on Jun 10, 2016
Latest reply on Jun 10, 2016 by William Cruz

I've been trying to get this working for a few days now. Everything seems to be correct but it's not working. My attached code is hiding everything that's visible, this isn't obviously my final intent, when it's all set and done, the intent is to hide only the ones that a user will select from a list.

 

                /*THIS RETURNS A JAGGED ARRAY*/
               var AllViews = _swDwgDoc.GetViews();

               for (int i = 0; i < AllViews.Length; i++)
               {
                   var SingleView = AllViews[i];
                   /*THE FIRST ONE IS THE ENTIRE SHEET.
                    *THE VIEWS START AT POSTION #1*/
                   for (int a = 1; a < SingleView.Length; a++)
                   {
                       SolidWorks.Interop.sldworks.View CurrentView = SingleView[a];

                       _swDwgDoc.ActivateView(CurrentView.Name);

                       var VisComps = CurrentView.GetVisibleComponents();

                       foreach (Component2 swComp in VisComps)
                       {
                           /*BELOW ARE THE 2 METHODS THAT I USE TO HIDE VISIBLE COMPONENTS IN
                             *THE VIEW BUT THEY DO NOT WORK - BOTH ARE SHOWN BUT I TEST ONE AT
                             *A TIME, IN OTHER WORDS, I COMMENT OUT ONE WHEN TESTING THE OTHER*/

                           /*METHOD #1*/
                           swComp.Visible = (int)swComponentVisibilityState_e.swComponentHidden;


                           /*METHOD #2*/
                           _modDoc.Extension.SelectByID2(swComp.Name2.ToString(), "COMPONENT", 0, 0, 0, true, 0, null, 0);

                       }

                       /*METHOD #2*/
                       _modDoc.HideComponent2();
                       _modDoc.ClearSelection2(true);
                   }
               }

Outcomes