7 Replies Latest reply on Jan 31, 2015 6:41 PM by Yong Ning

    FeatureManager→Why don't InsertTableDrivenPattern

    Yong Ning

      Table-driven+Pattern.jpg

      Why this sentence is true

      Set swFeat = swFeatMgr.InsertFeatureTreeFolder2(swFeatureTreeFolder_Containing)

      but this sentence is false

      Set swFeat = swFeatMgr.InsertTableDrivenPattern(FileName, Pt, False, True)

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

      follow code

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

      Private Sub ss()

         Dim swApp As SldWorks.SldWorks, swModel As ModelDoc2

            Set swApp = Application.SldWorks

            Set swModel = swApp.ActiveDoc

         Dim swFeat As Feature, swFeatMgr As FeatureManager, SwTabFeat As TablePatternFeatureData

            Set swFeatMgr = swModel.FeatureManager

         Dim FileName, Pt '(1) As Double

            Debug.Print swModel.GetPathName

            Path = swApp.GetCurrentMacroPathFolder

            FileName = Path & "\a.SldPTab"

            Pt = Array(10, 10)

            'Set SwTabFeat = SwFeatMgr.InsertTableDrivenPattern(FileName, Pt, False, True)

            'SwFeatMgr.InsertTableDrivenPattern FileName, Pt, False, True

         

            Stop

            Set swFeat = swFeatMgr.InsertTableDrivenPattern(FileName, Pt, False, True)

            Stop

        

      End Sub

        • Re: FeatureManager→Why don't InsertTableDrivenPattern
          Yong Ning

          How to Loading Table Driven Patterns with API? | SOLIDWORKS Forums

          https://forum.solidworks.com/thread/88961

           

          In this website, my question don't run →  LoadPointsFromFile sentence.

           

          Mr Daniel Andersson solution method is

          FeatureManager→ ModifyDefinition sentence. Problem solved

           

          key code is

             SwTabFeat.LoadPointsFromFile Path & "\a.SldPTab"

             swFeat.ModifyDefinition SwTabFeat, swModel, Nothing

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

           

          Help  me

          Why ?

          Set swFeat = swFeatMgr.InsertTableDrivenPattern(FileName, Pt, False, True)→ result is Nothing

          NotFeature.jpg

          • Re: FeatureManager→Why don't InsertTableDrivenPattern
            Daniel Andersson

            I have no experience from using this method in API. Currently I'm not at the computer but will try to help as good as I can.

             

            The first thing that comes to my mind is if you have the selection done in a way that the method requires. I think you should consider the mark of the selections. Below a quote from the API reference.

             

            This method requires selecting the required input entities using the proper selection marks:

            Coordinate system 16

            Seed feature 4

            Seed face 128

            Seed body 256

            Reference point 32

             

            Further details here: http://help.solidworks.com/2014/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.ifeaturemanager~inserttabledrivenpattern.html

             

            To me it looks like you have to select following object and use stated marks (see numbers).

            Coordinate system 16

            Seed feature 4

            Reference point 32

             

            I also do not see the use of array Pt since you want to load all the points from file.

             

            This is about what I can help with, without doing some sampling myself. Hope it brings you forward. If not, I might be able to test it out on Tuesday.

              • Re: FeatureManager→Why don't InsertTableDrivenPattern
                Yong Ning

                Thank you Mr Daniel Andersson,Thank your reply.

                 

                I read many times → proper selection marks: ,but don't use  Coordinate system 16. marks

                 

                 

                Manual operation method,see follow picture.

                CoordinateSystem.jpg

                 

                PointVar→ Pt=array(10,10)

                UseCentrod→ boolean→ True (False)

                GeomPatt → boolean → True(False)

                proper selection marks: not select item of  Coordinate system 16. marks?

                  • Re: FeatureManager→Why don't InsertTableDrivenPattern
                    Daniel Andersson

                    The number of the mark is not related to the feature name. I made an example macro that selects the features with the correct marks. The example works for the file "NoInsertTableDrivenPattern.sldprt" attached in aaa.zip. Please read this post from Keith Rice that explains the selection mark in a very good way.

                     

                    VBA Macro

                    Dim swApp As SldWorks.SldWorks

                    Dim swModel As SldWorks.ModelDoc2

                    Dim swModelExt As SldWorks.ModelDocExtension

                    Dim swPart As SldWorks.PartDoc

                    Dim swFeatMgr As SldWorks.FeatureManager

                    Dim swFeature As SldWorks.Feature

                     

                    Dim FileName As String

                    Dim bRetVal As Boolean

                     

                    Sub main()

                    Set swApp = Application.SldWorks

                    Set swModel = swApp.ActiveDoc

                    Set swPart = swModel

                    Set swFeatMgr = swModel.FeatureManager

                    Set swModelExt = swModel.Extension

                     

                    swModel.ClearSelection2 True

                     

                    bRetVal = swModelExt.SelectByID2("Coordinate System1", "COORDSYS", 0, 0, 0, False, 16, Nothing, 0)

                    bRetVal = swModelExt.SelectByID2("Cut-Extrude1", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0)

                     

                    FileName = swApp.GetCurrentMacroPathFolder & "\example.sldptab"

                     

                    Set swFeature = swFeatMgr.InsertTableDrivenPattern(FileName, Nothing, True, True)

                    End Sub

                     

                    Data for example.sldptab - file to be at same location as macro file.

                    0mm 40mm

                    0mm -40mm

                    0mm -20mm

                    0mm 20mm

                     

                    How the features should/are selected in your case is hard to say since we do not know about the application, either you have to processes the selections from the user and sort out what you need and change to marks to the be as required for the method.

                     

                    You can use 2014 SolidWorks API Help - SetSelectedObjectMark Method (ISelectionMgr) to change a selection mark of a selected object.

                     

                    Or... you select them with API code...

                    1 person found this helpful
                      • Re: FeatureManager→Why don't InsertTableDrivenPattern
                        Yong Ning

                        thank you ,Mr  Mr Daniel Andersson.

                        Understanding of Coordinate system 16 and Seed feature 4 usage

                         

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

                        swModelExt.SelectByID2("Coordinate System1", "COORDSYS", 0, 0, 0, False, 16, Nothing, 0)

                        swModelExt.SelectByID2("Cut-Extrude1", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0)

                          • Re: FeatureManager→Why don't InsertTableDrivenPattern
                            Daniel Andersson

                            Not sure if you ask a question. But the number 16 and 4 is the required markers of selected objects for this method.

                             

                            Please change the question to be assumed to be answered or select one of the answers as correct if you consider the question to be solved.

                              • Re: FeatureManager→Why don't InsertTableDrivenPattern
                                Yong Ning

                                Thank you reply, I only read the English ability, writing English ability is not good .

                                 

                                Your code, my question has been resolved.

                                 

                                Thank you very much.

                                 

                                 

                                 

                                Function Pass4TubeArr(Rng As Range)

                                   ''

                                   Dim Xx, Yy, Sn, Arr()

                                      Sn = Sqr(2 * 32 ^ 2)

                                      Yy = 45 / 2

                                   Dim ii, kk

                                     For ii = 1 To Rng.Rows.Count

                                        If ii Mod 2 Then

                                           '''

                                           Xx = Sn / 2

                                        Else

                                           '''

                                           Xx = Sn

                                        End If

                                      

                                      

                                        For jj = 1 To Rng(ii, 1)

                                         

                                           'Debug.Print Yy + Sn * (ii - 1), Xx + Sn * (jj - 1)

                                         

                                          ReDim Preserve Arr(kk)

                                           Arr(kk) = Xx + Sn * (jj - 1) & "," & Yy + Sn * (ii - 1) / 2

                                           kk = kk + 1

                                          ReDim Preserve Arr(kk)

                                           Arr(kk) = Xx + Sn * (jj - 1) & "," & -(Yy + Sn * (ii - 1) / 2)

                                           kk = kk + 1

                                          ReDim Preserve Arr(kk)

                                           Arr(kk) = -(Xx + Sn * (jj - 1)) & "," & -(Yy + Sn * (ii - 1) / 2)

                                           kk = kk + 1

                                          ReDim Preserve Arr(kk)

                                           Arr(kk) = -(Xx + Sn * (jj - 1)) & "," & Yy + Sn * (ii - 1) / 2

                                           kk = kk + 1

                                        Next jj

                                     Next ii

                                     Dim oArr()

                                     ReDim oArr(UBound(Arr) - 1)

                                     For ii = 0 To UBound(oArr)

                                       oArr(ii) = Arr(ii + 1)

                                     Next ii

                                     ''

                                     Pass4TubeArr = oArr

                                End Function

                                Private Sub WriteSldPtab()

                                   ''

                                   Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                      Set SwApp = Application.SldWorks

                                   Dim Path

                                      Path = SwApp.GetCurrentMacroPathFolder & "\"

                                 

                                   Dim Xls As Excel.Application, Rng As Range

                                      Set Xls = GetObject(, "Excel.Application")

                                      Set Rng = Xls.Selection

                                 

                                   Dim Arr, Sht As Worksheet, oRng As Range

                                    

                                      Set Sht = Xls.Worksheets(Rng.Parent.Name)

                                 

                                 

                                      For ii = 1 To Rng.Rows.Count

                                 

                                 

                                         Set oRng = Sht.Range(Rng(ii, 3))

                                         Arr = Pass4TubeArr(oRng)

                                         Open Path & Rng(ii, 1) & ".SldPtab" For Output As #1

                                            Print #1, Join(Arr, vbCrLf)

                                         Close #1

                                      Next

                                      ''

                                End Sub

                                 

                                 

                                 

                                 

                                Function InsTabDrivenPattern(SwModel As ModelDoc2, FileName, FeatName, CoordName, BodyArr)

                                   Dim SwFeat As Feature, SwFeatMgr As FeatureManager

                                   Set SwFeatMgr = SwModel.FeatureManager

                                   With SwModel.Extension

                                     .SelectByID2 CoordName, "COORDSYS", 0, 0, 0, False, 16, Nothing, 0

                                     For ii = 0 To UBound(BodyArr)

                                       .SelectByID2 BodyArr(ii), "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0

                                     Next ii

                                   End With

                                   ''

                                   Set SwFeat = SwFeatMgr.InsertTableDrivenPattern(FileName, Nothing, True, True)

                                   SwFeat.Name = FeatName

                                   SwFeat.Select True

                                   SwModel.EditSuppress2

                                End Function

                                 

                                 

                                ''

                                Private Sub sss()

                                  Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                     Set SwApp = Application.SldWorks

                                     Set SwModel = SwApp.ActiveDoc

                                  Dim Str, Path, FileName, BodyArr

                                   

                                     Str = "Dn900"

                                     Path = SwApp.GetCurrentMacroPathFolder

                                     FileName = Path & "\" & Str & ".SldPTab"

                                     InsTabDrivenPattern SwModel, FileName, Str, "CoordinateSystem", Array("Hole", "倒角1", "倒角2")

                                End Sub

                                 

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

                                Private Sub Ss4()

                                   Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                      Set SwApp = Application.SldWorks

                                      Set SwModel = SwApp.ActiveDoc

                                     

                                   Dim SwModelExt As ModelDocExtension

                                      Set SwModelExt = SwModel.Extension

                                   Dim SwFeat As Feature, SwFeatMgr As FeatureManager, SwTabFeat As TablePatternFeatureData

                                      Set SwFeatMgr = SwModel.FeatureManager

                                   Dim FileName, Pt '(1) As Double

                                      Debug.Print SwModel.GetPathName

                                      'Path = SwApp.GetCurrentMacroPathFolder

                                      Path = SwModel.GetPathName

                                      FileName = Left(Path, InStrRev(Path, "\")) & "a.SldPTab"

                                      Debug.Print FileName

                                      With SwModelExt

                                         '.SelectByID2 "Coordinate System1", "COORDSYS", 0, 0, 0, False, 16, Nothing, 0

                                         '.SelectByID2 "Cut-Extrude1", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0         '

                                          'bRetVal = SwModelExt.SelectByID2("Coordinate System1", "COORDSYS", 0, 0, 0, False, 16, Nothing, 0)

                                          'bRetVal = SwModelExt.SelectByID2("Cut-Extrude1", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0)

                                          bRetVal = SwModelExt.SelectByID2("坐标系1", "COORDSYS", 0, 0, 0, False, 16, Nothing, 0)

                                          bRetVal = SwModelExt.SelectByID2("切除-拉伸1", "BODYFEATURE", 0, 0, 0, True, 4, Nothing, 0)

                                      End With

                                      ''

                                      Set SwFeat = SwFeatMgr.InsertTableDrivenPattern(FileName, Nothing, True, True)

                                      Stop

                                     

                                End Sub