3 Replies Latest reply on Aug 5, 2017 12:28 PM by Lukas Bernhardt

    Get Visibility State of Sketch

    Lukas Bernhardt

      Hi,

       

      ist there an API Method to get the Information whether a selected Sketch is visible oder hidden ?! I want to create a

      macro which changes the visibility of a specific sketch every time i run the macro. The code above just show the sketch. Bute i need a information

      if the macro should blank or unblank.

       

      Thanks for Help !

       

       

       

      Sub main()

       

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

      Set swModelDocExt = swModel.Extension

       

      'Hole die Dokumenteigenschaft v_Teilenummer

      Set swCustProp = swModelDocExt.CustomPropertyManager("")

      bool = swCustProp.Get4("v_teilenummer", False, val, valout)

       

       

      Name = "3D-Rahmen_" + val

       

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc

       

      boolstatus = Part.Extension.SelectByID2(Name, "SKETCH", 0, 0, 0, False, 0, Nothing, selectval)

      Part.UnblankSketch

       

      End Sub

        • Re: Get Visibility State of Sketch
          Viktor Bovzdarenko

          Hi Lukas.

          Feature can be received from Sketch. Feature Has a visibility parameter: value = IFeature.Visible

           

          Here is an example:

           

          Dim swApp As SldWorks.SldWorks

          Dim Model As ModelDoc2

           

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Dim swFeat As Feature: Set swFeat = swModel.SelectionManager.GetSelectedObject6(1, 0)

             

              If (Not swFeat Is Nothing) Then

                  Dim res As Integer: res = swFeat.Visible

                 

                  If (res = swVisibilityState_e.swVisibilityStateShown) Then

                      Debug.Print "SKETCH: '" & swFeat.Name & "' IS VISIBLE"

                  Else

                      Debug.Print "SKETCH: '" & swFeat.Name & "' IS NOT VISIBLE"

                  End If

              End If

          End Sub

           

          In this example you need to preselect the sketch first

           

          Regards

          Viktor

          • Re: Get Visibility State of Sketch
            Lukas Bernhardt

            Hi Victor,

             

            thank you for the fast answer. That is exactly what i need.

            I still have to make it work with SelectByID2.

             

             

            Thank You

              • Re: Get Visibility State of Sketch
                Lukas Bernhardt

                At least i did it this way ! Thanks for your help.

                 

                Sub main()

                 

                Dim swapp As SldWorks.SldWorks

                Dim Part As SldWorks.ModelDoc2

                Dim myfeature As Feature

                Dim subfeature As Feature

                Dim retval As Boolean

                Dim boolstatus As Boolean

                Dim name_skizze As String

                 

                 

                Set swapp = Application.SldWorks

                Set Part = swapp.ActiveDoc

                Set myfeature = Part.FirstFeature

                 

                Do While Not myfeature Is Nothing

                       

                        Debug.Print myfeature.Name & " "; "[" + myfeature.GetTypeName2 + "]"

                   

                        Set subfeature = myfeature.GetFirstSubFeature

                                Do While Not subfeature Is Nothing

                                Debug.Print "       "; subfeature.Name & " "; "[" + subfeature.GetTypeName2 + "]"

                               

                                    If myfeature.GetTypeName2 = "CutListFolder" And subfeature.GetTypeName2 = "3DProfileFeature" Then

                                    name_skizze = subfeature.Name

                                    Debug.Print "Die Skizze des 3D-Rahmen heißt : " & name_skizze

                                    boolstatus = Part.Extension.SelectByID2(name_skizze, "SKETCH", 0, 0, 0, False, 0, Nothing, 0)

                                    Debug.Print subfeature.Visible

                                   

                                        If subfeature.Visible = 1 Then

                                        Part.UnblankSketch

                                        Else

                                        Part.BlankSketch

                                        End If

                                   

                                    End If

                               

                                Set subfeature = subfeature.GetNextSubFeature

                                Loop

                 

                    Set myfeature = myfeature.GetNextFeature

                Loop

                 

                 

                End Sub