1 Reply Latest reply on Jun 10, 2016 11:41 AM by William Cruz

    Hiding visible components in a drawing

    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);
                         }
                     }
      
        • Re: Hiding visible components in a drawing
          William Cruz

          For those that might have the same question, I figured it out. See the revised code below.

           

                          /*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];
          
                                  /*ACTIVATE THE CURRENT VIEW*/
                                  _swDwgDoc.ActivateView(CurrentView.Name);
          
                                  /*GET ROOT COMP*/
                                  DrawingComponent rootComp = CurrentView.RootDrawingComponent;
                                  /*GET CHILDREN*/
                                  var childComps = (object[])rootComp.GetChildren();
          
                                  /*HIDE*/
                                  foreach (DrawingComponent ChildComp in childComps)
                                  {
                                      ChildComp.Select(false, null);
                                      _modDoc.HideComponent2();
                                  }
                              }
                          }