5 Replies Latest reply on Jan 3, 2016 11:37 AM by Amen Allah Jlili

    How to change num of Circular Pattern wiht API

    Yong Ning

      0.jpg

       

      Number of Instances . Sets the number of instances of the seed feature.

        • Re: How to change num of Circular Pattern wiht API
          Amen Allah Jlili

          I'm going to assume you already have the circular feature object figured out. Going to call it

          CircularPattern1
          

          for the purpose of this answer.


          You simply get the data feature object of that circular pattern object.

           

          Dim CircularPattern1FeatureData As CircularPatternFeatureData
          Set CircularPattern1FeatureData = CircularPattern1.GetDefinition


          Now, you can set the number of instances using

           

          CircularPattern1FeatureData.TotalInstances
          

           

          Finally, to apply changes, simply save the modification to the feature definition

           

          Dim Result As Boolean
          Result = CircularPattern1.ModifyDefinition(CircularPattern1FeatureData,TopDoc,Nothing)
          

           

          To modify a feature in...

          Then TopDoc argument...

          A part

          Is the IModelDoc2 object for the part and the Component argument should be Nothing or null

          An assembly

          Should be the assembly IModelDoc2 object and the Component argument should be the IComponent2 object in which the feature is to be modified

           

          Be a good citizen and save the changes using

           

          TopDoc.Save

           

           

          1st API answer in 2016! Woohoo! Happy new year!

            • Re: How to change num of Circular Pattern wiht API
              Yong Ning

              I'm chinese, Happy new year every one.in 2016

               

               

              1.jpg

               

               

               

              Private Sub l11()

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                     Set SwApp = Application.SldWorks

                     Set SwModel = SwApp.ActiveDoc

                 Dim SwSelMgr As SelectionMgr

                     Set SwSelMgr = SwModel.SelectionManager

                 Dim SwPart As PartDoc

                     Set SwPart = SwModel

                 Dim SwFeat As Feature

                     'Set SwFeat = SwPart.FeatureByName("CirPattern")

                     Set SwFeat = SwSelMgr.GetSelectedObject5(1)

                     Debug.Print SwFeat.Name

                 Dim SwCirData As CircularPatternFeatureData

                     Set SwCirData = SwFeat.GetDefinition

                     SwCirData.TotalInstances = 6

                     Debug.Print SwCirData.TotalInstances

                     SwFeat.ModifyDefinition SwCirData, SwModel, Nothing

              End Sub

               

               

              Private Sub ll3()

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                     Set SwApp = Application.SldWorks

                     Set SwModel = SwApp.ActiveDoc

                 Dim SwSelMgr As SelectionMgr

                     Set SwSelMgr = SwModel.SelectionManager

                 Dim SwFeat As Feature

                     Set SwFeat = SwSelMgr.GetSelectedObject5(1)

                   

                 Dim LCircularPattern1FeatureData As LocalCircularPatternFeatureData

                      Set LCircularPattern1FeatureData = SwFeat.GetDefinition

                    

                      LCircularPattern1FeatureData.TotalInstances = 2

                      SwFeat.ModifyDefinition LCircularPattern1FeatureData, SwModel, Nothing

                      SwModel.ForceRebuild3 True

              End Sub

               

              ‘‘’

              Private Sub ll3()

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                     Set SwApp = Application.SldWorks

                     Set SwModel = SwApp.ActiveDoc

                 Dim SwAssy As AssemblyDoc

                     Set SwAssy = SwModel

                 Dim tmp

                     tmp = SwModel.Extension.SelectByID2("LocalCirPattern1", "COMPPATTERN", 0, 0, 0, False, 0, Nothing, 0)

                 Dim SwSelMgr As SelectionMgr

                     Set SwSelMgr = SwModel.SelectionManager

                 Dim SwFeat As Feature

                     Set SwFeat = SwSelMgr.GetSelectedObject5(1)

                   

                 Dim lCircularPattern1FeatureData As LocalCircularPatternFeatureData

                      Set lCircularPattern1FeatureData = SwFeat.GetDefinition

                      Debug.Print lCircularPattern1FeatureData.TotalInstances

                      'Stop

                      With lCircularPattern1FeatureData

                          .AccessSelections SwAssy, Nothing

                          .Spacing = 45 * 3.1415926 / 180

                          .TotalInstances = 8

                          '.ReleaseSelectionAccess

                     

                         

                      End With

                     

                      SwFeat.ModifyDefinition lCircularPattern1FeatureData, SwAssy, Nothing

                      'SwModel.ForceRebuild3 True

              End Sub

                • Re: How to change num of Circular Pattern wiht API
                  Amen Allah Jlili

                  Good job! Tick the right answer!

                    • Re: How to change num of Circular Pattern wiht API
                      Yong Ning

                      question:

                       

                      In SldPrt file,

                            Set SwCirData = SwFeat.GetDefinition → result is True

                       

                       

                      but In SldAsm file,

                       

                       

                       

                      Run time error'13'type does not match

                       

                           Set SwCirData = SwFeat.GetDefinition → result is Error

                      2.jpg

                       

                       

                       

                       

                      Private Sub ll5()

                         Dim T: T = Timer

                         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                             Set SwApp = Application.SldWorks

                             Set SwModel = SwApp.ActiveDoc

                         Dim ConfArr, SwConf As Configuration

                             ConfArr = SwModel.GetConfigurationNames

                            

                         Dim SwAssy As AssemblyDoc

                             Set SwAssy = SwModel

                         Dim tmp, Num

                            

                         Dim SwSelMgr As SelectionMgr

                             Set SwSelMgr = SwModel.SelectionManager

                         Dim SwFeat As Feature

                           

                         Dim lCircularPattern1FeatureData As LocalCircularPatternFeatureData

                            For ii = UBound(ConfArr) To UBound(ConfArr) / 4 Step -1

                                SwModel.ShowConfiguration ConfArr(ii)

                                Set SwConf = SwModel.GetActiveConfiguration

                                Debug.Print SwConf.Name,

                                For jj = 1 To 2

                                   tmp = SwModel.Extension.SelectByID2("LocalCirPattern" & jj, "COMPPATTERN", 0, 0, 0, False, 0, Nothing, 0)

                                   Set SwFeat = SwSelMgr.GetSelectedObject5(1)

                                   Set lCircularPattern1FeatureData = SwFeat.GetDefinition

                                   With lCircularPattern1FeatureData

                                       .AccessSelections SwAssy, Nothing

                                       Num = .TotalInstances

                                       .Spacing = (360 / Num) * 3.1415926 / 180

                                   End With

                                   SwFeat.ModifyDefinition lCircularPattern1FeatureData, SwAssy, Nothing

                                Next jj

                                PrintTiming T

                            Next ii

                            SwModel.Save

                            SwApp.CloseDoc SwModel.GetTitle

                      End Sub