8 Replies Latest reply on Jul 28, 2017 6:17 AM by Craig Adendorff

    API - TOGGLE "SHOW BEND LINE NOTES" IN FLAT PATTERN DRAWING VIEW

    Elmar Klammer


      Hello,

       

      I was wondering if anybody knows how to control the "Display sheet metal bend notes" check box via API/Macro code.

      This settings is found in the drawing view property for sheet metal flat pattern views.

       

      Thanks for all pointers.

       

      Elmar

        • Re: API - TOGGLE "SHOW BEND LINE NOTES" IN FLAT PATTERN DRAWING VIEW
          Deepak Gupta

          The following code will set it on and it you use False instead of true in the following codes, the option will be unchecked.

          Dim swApp                   As SldWorks.SldWorks

          Dim swModel                 As SldWorks.ModelDoc2

          Dim boolstatus As Boolean

           

          Sub main()

           

          Set swApp = Application.SldWorks

          Set Part = swApp.ActiveDoc

           

          boolstatus = Part.Extension.SetUserPreferenceToggle(swUserPreferenceToggle_e.swShowSheetMetalBendNotes, 0, True)

           

          End Sub

          • Re: API - TOGGLE "SHOW BEND LINE NOTES" IN FLAT PATTERN DRAWING VIEW
            Keith Rice

            Elmar,

             

            A quick way to determine if a method exists is to look in the API Help. For example, I opened up the local API Help, went to the Index tab, typed in "bend line", and quickly found IView::ShowSheetMetalBendNotes. If you are new to the API, you can see more examples on how to use the API Help in Lesson 2.2, a free tutorial at my web site.

             

            Here is some code that will toggle the bend line note state of Drawing View1:

             

            ========

             

            Dim swApp As SldWorks.SldWorks

            Dim swModel As SldWorks.ModelDoc2

            Dim swDraw As SldWorks.DrawingDoc

            Dim swFeat As SldWorks.Feature

            Dim swView As SldWorks.View

             

            Sub main()

                Set swApp = Application.SldWorks

                Set swModel = swApp.ActiveDoc

                Set swDraw = swModel

                Set swFeat = swDraw.FeatureByName("Drawing View1")

                Set swView = swFeat.GetSpecificFeature2

                If swView.ShowSheetMetalBendNotes = False Then

                    swView.ShowSheetMetalBendNotes = True

                Else

                    swView.ShowSheetMetalBendNotes = False

                End If

                swModel.EditRebuild3

            End Sub

             

            ========

             

            Keith

            Video Tutorials for the SolidWorks API

            • Re: API - TOGGLE "SHOW BEND LINE NOTES" IN FLAT PATTERN DRAWING VIEW
              Craig Adendorff

              Hi there, sorry to bring up an old thread but I am trying to add the above to the following code but am struggling as my programming knowledge is little to none.

               

              The code I am trying to add it to is the following:

               

              Sub main()

               

               

                 Dim swApp                       As SldWorks.SldWorks

                 Dim swModel                     As SldWorks.ModelDoc2

                 Dim swAssy                      As SldWorks.AssemblyDoc

                 Dim swConf                      As SldWorks.Configuration

                 Dim swRootComp                  As SldWorks.Component2

                 Dim nStart                      As Single

                 Dim bRet                        As Boolean

               

                 Set swApp = Application.SldWorks

                 Set swModel = swApp.ActiveDoc

                 Set swConf = swModel.GetActiveConfiguration

                 Set swRootComp = swConf.GetRootComponent3(True)

               

                 'Debug.Print "File = " & swModel.GetPathName

               

                 TraverseComponent swRootComp, 1

               

                 Debug.Print "Finished!"

               

               

              End Sub

               

               

              Sub TraverseComponent(swComp As SldWorks.Component2, nLevel As Long)

               

               

              Dim vChildComp                  As Variant

               

               

                 Dim swApp                       As SldWorks.SldWorks

                 Dim swpart                      As SldWorks.PartDoc

               

                 Dim swChildComp                 As SldWorks.Component2

                 Dim swConfig                    As SldWorks.Configuration

                 Dim swConfMgr                   As SldWorks.ConfigurationManager

                 Dim swChildModel                As SldWorks.ModelDoc2

                 Dim swOpenModel                 As SldWorks.ModelDoc2

               

                 Dim swChildCustPropMngr         As CustomPropertyManager

                 Dim swChildModelDocExt          As ModelDocExtension

                 Dim swsheetmetal                As SldWorks.SheetMetalFeatureData

                 Dim swFeat                      As SldWorks.Feature

                 Dim swBody                      As SldWorks.Body2

               

               

                 Dim Sheet_metal                 As Boolean

                 Dim Boolstatus                  As Boolean

                   

                 Dim Thickness                   As Double

                 Dim conv                        As Double

               

               

                 Dim i                           As Long

                 Dim loptions                    As Long

                 Dim lerrors                     As Long

               

               

                 Dim sPadStr                     As String

                 Dim FilePath                    As String

                 Dim FileName                    As String

                 Dim swThkDir                    As String

                 Dim swMatDir                    As String

                 Dim swCurrent                   As String

                 Dim RefCfg                      As String

                 Dim ChildConfigName             As String

                 Dim sMatName                    As String

                 Dim sMatDB                      As String

                 Dim exFileName                  As String

               

                 Dim Bodies                      As Variant

               

                 vChildComp = swComp.GetChildren

               

               

                 For i = 0 To UBound(vChildComp)

                     Set swChildComp = vChildComp(i)

                   

                     'Check to see if current component is suppressed

                     If swChildComp.IsSuppressed = False Then GoTo Active Else GoTo Skip

                   

              Active:

              Set swApp = Application.SldWorks

               

               

              Set swChildModel = swChildComp.GetModelDoc2

                 'Check to see if child component is an Assembly or part

                 If (swChildModel.GetType <> swDocPART) Then GoTo Jump 'Skips Subassemby level

               

               

              Set swpart = swChildModel 'Applies part commands for current component

               

               

              FilePath = Left(swComp.GetPathName, InStrRev(swComp.GetPathName, "\") - 1)

               

              FileName = swChildModel.GetTitle 'Get title of component

              swCurrent = swChildComp.ReferencedConfiguration 'Get current configuration of component

               

               

              Bodies = swpart.GetBodies2(swBodyType_e.swAllBodies, True)

              Set swBody = Bodies(0)

               

               

                 If swBody.IsSheetMetal = 0 Then 'If Body is not sheet metal

               

               

                     'Debug.Print "Component " & FileName & " is not a sheet metal component"

                     'Debug.Print "Current Config is : "; swCurrent

                         GoTo Jump

                 End If

               

                 If swBody.IsSheetMetal = 1 Then 'If body is sheet metal

               

               

                     Debug.Print "Processing component " & FileName & " as a sheet metal component"

                     Debug.Print "Current Config is : "; swCurrent

                     GoTo Process

                 End If

               

               

              Process:

               

               

              'Get Part Material

               

               

              Set swpart = swChildModel

              sMatName = swpart.GetMaterialPropertyName2(swCurrent, sMatDB)

               

               

              If sMatName = "" Then sMatName = "None"

               

               

              Debug.Print "    Current material is : "; sMatName

               

               

              'Get part Thickness

               

               

              Set swFeat = swChildModel.FirstFeature

                 While Not swFeat Is Nothing

               

               

                 If swFeat.GetTypeName = "SheetMetal" Then

                     Set swsheetmetal = swFeat.GetDefinition

                   

                     Thickness = swsheetmetal.Thickness

                   

                     conv = 39.3700787401575

                     Thickness = Thickness * conv

               

               

              Debug.Print "    Thickness is :"; Thickness; "inches"

                       

                 End If

               

               

              Set swFeat = swFeat.GetNextFeature

                           

                 Wend

               

              swMatDir = FilePath & "\" & sMatName

              Debug.Print swMatDir

               

               

              If Dir(swMatDir, vbDirectory) = "" Then MkDir swMatDir

               

               

              swThkDir = FilePath & "\" & sMatName & "\" & Thickness

              Debug.Print swThkDir

               

               

              If Dir(swThkDir, vbDirectory) = "" Then MkDir swThkDir

               

               

              exFileName = FilePath & "\" & sMatName & "\" & Thickness & "\" & FileName & "-" & swCurrent

               

               

              Debug.Print exFileName

               

               

              Set swOpenModel = swApp.ActivateDoc3(swChildModel.GetPathName, True, loptions, lerrors)

               

               

              Boolstatus = swChildModel.ShowConfiguration2(swCurrent)

               

               

              swChildModel.ExportFlatPatternView exFileName & ".DXF", 0

               

               

              swApp.CloseDoc (swChildModel.GetPathName)

               

               

                      

              GoTo Jump

                      

              Skip:

               

               

                 Debug.Print "Skipped"

               

               

              Jump:

                     TraverseComponent swChildComp, nLevel + 1

                        Next i

               

               

              End Sub