2 Replies Latest reply on Mar 16, 2017 4:30 PM by Steven Barry

    API (VBA) Get the first drawing view on the "first sheet", not active sheet

    Cad Admin

      What if possible is the easiest way to Get the first drawing view on the first sheet...in a multi-sheet drawing.

       

      I know how to use GetFirstView, Get NextView, as it pertains to the "active sheet", but i want to use the first drawing view on the first drawing view on the first sheet, wile working on any other sheet.

        • Re: API (VBA) Get the first drawing view on the "first sheet", not active sheet
          Amen Allah Jlili

          You need to traverse the feature tree list, get the drawing view features and then check the own feature. It should be a sheet.
          Here's an algorithm that achieves that but for SketchPictures:

                       [DispId(5)]
                      public SolidWorksAPI.SketchPicture[] GetSketchPicturesFromSheet(SolidWorksAPI.Sheet Sheet)
                      {
                          var List = new List<SolidWorksAPI.SketchPicture>();
                          if (this.FeatureManager != null) {
                          var Features = (object[])FeatureManager.GetFeatures(false);
                          SolidWorksAPI.Feature swFeature;
                       
                          foreach (object featobj in Features)
                          {
                              swFeature = (SolidWorksAPI.Feature)featobj;
                              if (swFeature.GetTypeName2() == "SketchPicture")
                              {
                                  var FirstOwner = swFeature.GetOwnerFeature();
                                  var UtimateOwner = swFeature.GetOwnerFeature();
                                  if (UtimateOwner.GetTypeName2() == "Sheet")
                                  {
                                      var UltimateOwnerSheet = (SolidWorksAPI.Sheet)UtimateOwner.GetSpecificFeature2();
                                      if (UltimateOwnerSheet == Sheet)
                                      {
                                          List.Add((SolidWorksAPI.SketchPicture)swFeature);
                                      }
                                  }
                                   
                              }
          
          
                          }
                          }
                          return List.ToArray();
          
          
          
          

           

          Cheers,
          Amen
          www.cadhero.com

          • Re: API (VBA) Get the first drawing view on the "first sheet", not active sheet
            Steven Barry

            Good question...
            I wonder if 2016 SOLIDWORKS API Help - GetSheetNames Method (IDrawingDoc)  returns the sheets in the correct order?

             

            If so, then it would be a matter of using 2016 SOLIDWORKS API Help - Sheet Property (IDrawingDoc) on the first one from that list.

             

            Then, you could use 2016 SOLIDWORKS API Help - GetViews Method (ISheet)  to get the view.