6 Replies Latest reply on Mar 6, 2018 3:51 PM by Amen Allah Jlili

    Find picture in drawing

    Jessica Smith

      I'm trying to write a macro that will search a drawing sheet for pictures, sketch pictures, and return their object or or feature to me.


      Basically our company templates have an old logo on them, and I want to search the drawing sheet for all sketch pictures to find it.


      I have already tried the examples of searching all features macro, but those don't pull up sketch pictures in drawing sheets.


      Help plz???

        • Re: Find picture in drawing
          Jessica Smith

          Here is the code I'm using, but for some reason it doesn't find the sketch pictures in the drawing.. what am I doing wrong??


              swFeature = swModel.FirstFeature

                  Do While Not swFeature Is Nothing

                      If swFeature.Name.Contains("logo_picture") Then

                          Return True

                      End If

                      swFeature = swFeature.GetNextFeature()


            • Re: Find picture in drawing
              Jacob Corder

              what Amen Allah Jlili meant to say was


                  Function GetSketchPicturesFromSheet(ByVal Sheet As Sheet) As SketchPicture()

                      Dim List = New List(Of SketchPicture)()

                      If Me.FeatureManager IsNot Nothing Then

                          Dim Features As Object() = CType(FeatureManager.GetFeatures(False), Object())

                          Dim swFeature As Feature

                          For Each featobj As Object In Features

                              swFeature = CType(featobj, Feature)

                              If swFeature.GetTypeName2 = "SketchPicture" Then

                                  Dim FirstOwner = swFeature.GetOwnerFeature

                                  Dim UtimateOwner = swFeature.GetOwnerFeature

                                  If UtimateOwner.GetTypeName2  = "Sheet" Then

                                      Dim UltimateOwnerSheet As Sheet = CType(UtimateOwner.GetSpecificFeature2 , Sheet)

                                      If UltimateOwnerSheet.GetName() = Sheet.GetName() Then

                                          List.Add(CType(swFeature, SketchPicture))

                                      End If

                                  End If

                              End If


                          Return List.ToArray()

                      End If

                  End Function


              Converted with Telerik



              'Service provided by Telerik (www.telerik.com)

              'Conversion powered by Refactoring Essentials.

              'Twitter: @telerik

              'Facebook: facebook.com/telerik


            • Re: Find picture in drawing
              Amen Allah Jlili


              You can use this extension method I wrote to get an array of sketch pictures from from a sheet object


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


              SolidWorks API Video Tutorials