3 Replies Latest reply on Dec 13, 2014 2:33 AM by Yong Ning

    How to Loading Table Driven Patterns with API?

    Yong Ning

      Hope use API., Loading table Driven Pattern

       

      To load a table-driven pattern instance:

      With a part open, click Table Driven Pattern  (Features toolbar) or Insert > Pattern/Mirror > Table Driven Pattern.

      Click Browse to locate the .sldptab file, then click Open.

      The file name appears in Read a file from, along with the X-Y coordinates.

      Select the appropriate Reference point and Coordinate system.

       

       

       

      2014 SOLIDWORKS Help - Saving and Loading Table Driven Patterns

      http://help.solidworks.com/2014/english/solidworks/sldworks/c_Saving_and_Loading_Table_Driven_Patterns.htm

        • Re: How to Loading Table Driven Patterns with API?
          Yong Ning

          Why can't run code→

          .LoadPointsFromFile SwApp.GetCurrentMacroPathFolder & "\a3.SldTab"

           

           

          Sub Ll2()

              Dim SwApp                   As SldWorks.SldWorks

              Dim SwModel                 As SldWorks.ModelDoc

              Dim swSelMgr                As SldWorks.SelectionMgr

              Dim swFeat                  As SldWorks.Feature

              Dim swTableFeatData         As SldWorks.TablePatternFeatureData

              Dim swRefPt                 As SldWorks.Vertex

              Dim swCoordSys              As SldWorks.Feature 'Object

              Dim vBasePt                 As Variant

              Dim vFace                   As Variant

              Dim vFeat                   As Variant

              Dim vPt                     As Variant

              Dim nPtType                 As Long

              Dim vRefPtParam             As Variant

              Dim bRet                    As Boolean

              Dim i                       As Long

              Set SwApp = Application.SldWorks

              Set SwModel = SwApp.ActiveDoc

              Set swSelMgr = SwModel.SelectionManager

              Set swFeat = swSelMgr.GetSelectedObject5(1)

              Set swTableFeatData = swFeat.GetDefinition  

              ' Roll back to get the reference point

              bRet = swTableFeatData.AccessSelections(SwModel, Nothing): Debug.Assert bRet

              Set swRefPt = swTableFeatData.ReferencePoint

           

              Set swCoordSys = swTableFeatData.CoordinateSystem

           

              vBasePt = swTableFeatData.GetBasePoint

              vFace = swTableFeatData.PatternFaceArray

              vFeat = swTableFeatData.PatternFeatureArray

              vPt = swTableFeatData.PointArray

           

              If Not swRefPt Is Nothing Then

                  ' Is NULL if centroid used

                  vRefPtParam = swRefPt.GetPoint

                  Debug.Print "  RefPt                = (" & vRefPtParam(0) * 1000# & ", " & vRefPtParam(1) * 1000# & ", " & vRefPtParam(2) * 1000# & ") mm"

              End If

              Dim ii, Str, Arr()

                ReDim Arr(UBound(vPt))

              For ii = 0 To UBound(Arr)

                Arr(ii) = vPt(ii)

              Next ii

              ''

              With swTableFeatData

                 .PointArray = Arr

                 Debug.Print SwApp.GetCurrentMacroPathFolder & "\a3.SldTab"

                 .LoadPointsFromFile SwApp.GetCurrentMacroPathFolder & "\a3.SldTab"

              End With

              swTableFeatData.ReleaseSelectionAccess

          End Sub

           

          API Table Feature - DASSAULT: SOLIDWORKS 3D Design - Eng-Tips

          http://www.eng-tips.com/viewthread.cfm?qid=133453

           

          API Table Feature - DASSAULT: SOLIDWORKS 3D Design - Eng-Tips

          http://www.eng-tips.com/viewthread.cfm?qid=133453

            • Re: How to Loading Table Driven Patterns with API?
              Daniel Andersson
              swTableFeatData.ReleaseSelectionAccess

              Will make you lose the changes... see Remarks for 2014 SolidWorks API Help - ReleaseSelectionAccess Method (ITablePatternFeatureData)

              Use this method to restore the rollback state if you did not modify the feature, or use IFeature::ModifyDefinition or IFeature::IModifyDefinition2 if you did modify the feature.

               

              Use 2014 SolidWorks API Help - ModifyDefinition Method (IFeature) instead of the ReleaseSelectionAccess method.

               

              Which means replace:

              swTableFeatData.ReleaseSelectionAccess

              with

              swFeat.ModifyDefinition swTableFeatData, SwModel, Nothing

              and it will work.

               

              You should also keep an eye on the file extensions since the API reference refers to file extension sldptab and not sldtab. However, this is not that critical as long as the format of the text rows is correct.

                • Re: How to Loading Table Driven Patterns with API?
                  Yong Ning

                  Thanks your web like

                  ****************************.

                  The need for further study "ModifyDefinition" statement

                  ***************************

                  Sub main()

                      Dim SwApp                   As SldWorks.SldWorks

                      Dim SwModel                 As SldWorks.ModelDoc2

                      Dim swSelMgr                As SldWorks.SelectionMgr

                      Dim swFeat                  As SldWorks.Feature

                      Dim SwTabFeat As TablePatternFeatureData

                      Dim bRet                    As Boolean

                      Set SwApp = Application.SldWorks

                        Path = SwApp.GetCurrentMacroPathFolder

                        Debug.Print Path

                      Set SwModel = SwApp.ActiveDoc

                      Set swSelMgr = SwModel.SelectionManager

                      Set swFeat = swSelMgr.GetSelectedObject5(1)

                      Set SwTabFeat = swFeat.GetDefinition

                      ''

                     

                      With SwTabFeat

                        tmp = .AccessSelections(SwModel, Nothing)

                        .LoadPointsFromFile Path & "\aa.SldPTab"

                      End With

                      swFeat.ModifyDefinition SwTabFeat, SwModel, Nothing

                     

                     

                  End Sub

                   

                   

                  ****************************

                  Sub main()

                      Dim swApp                   As SldWorks.SldWorks

                      Dim swModel                 As SldWorks.ModelDoc2

                      Dim swSelMgr                As SldWorks.SelectionMgr

                      Dim swFeat                  As SldWorks.Feature

                      Dim swSheetMetal            As SldWorks.SheetMetalFeatureData

                      Dim bRet                    As Boolean

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc

                      Set swSelMgr = swModel.SelectionManager

                      Set swFeat = swSelMgr.GetSelectedObject5(1)

                      Set swSheetMetal = swFeat.GetDefinition

                   

                      Debug.Print "Feature = " & swFeat.Name

                      Debug.Print "  BendRadius = " & swSheetMetal.BendRadius * 1000# & " mm"

                   

                      ' Rollback to change default bend radius

                      bRet = swSheetMetal.AccessSelections(swModel, Nothing): Debug.Assert bRet

                   

                      ' Double the default bend radius value

                      swSheetMetal.BendRadius = 2# * swSheetMetal.BendRadius

                   

                      ' Apply changes

                      bRet = swFeat.ModifyDefinition(swSheetMetal, swModel, Nothing): Debug.Assert bRet

                      Debug.Print "  BendRadius = " & swSheetMetal.BendRadius * 1000# & " mm"

                  End Sub

                  '----------