2 Replies Latest reply on Feb 9, 2016 8:23 AM by Yong Ning

    GetEquationMgr

    Yong Ning

      Private Sub AddEquation()

         Dim Xls As Excel.Application, Rng As Range

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

            Set Rng = Xls.Selection

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

            Set SwApp = Application.SldWorks

            Set SwModel = SwApp.ActiveDoc

         Dim SwEqnMgr As EquationMgr, Arr()

            Set SwEqnMgr = SwModel.GetEquationMgr

            Debug.Print SwEqnMgr.GetCount

           

            With SwEqnMgr

                ReDim Arr(.GetCount)

                For ii = .GetCount To 0 Step -1

                    Arr(ii) = .Equation(ii)

                    Debug.Print .Equation(ii), .Value(ii), .Suppression(ii)

                    .Delete ii

                Next ii

                SwModel.ForceRebuild3 True

                'Stop

                For ii = 1 To Rng.Rows.Count

                   .Add ii - 1, Rng(ii, 1)

                Next ii

            End With

            SwModel.ForceRebuild3 True

           

        

      End Sub

        • Re: GetEquationMgr
          Artem Taturevych

          What is the question?

            • Re: GetEquationMgr
              Yong Ning

              360截图20160209211948705.jpgNo problem, just Programming Notes.

               

              Method

               

              1 set Rng = Xls.Selection

              2

                        For ii = 1 To Rng.Rows.Count

                           .Add ii - 1, Rng(ii, 1)

                        Next ii

               

               

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

              Const formulaStr = "7.85×10<STACK size=0.5 divider=no><FONT Size=1>-6<OVER></STACK>="

              Private Sub DELDELAddEquation()

                 Dim Xls As Excel.Application, Rng As Range

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

                    Set Rng = Xls.Selection

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                    Set SwApp = Application.SldWorks

                    Set SwModel = SwApp.ActiveDoc

                 Dim SwEqnMgr As EquationMgr, Arr()

                    Set SwEqnMgr = SwModel.GetEquationMgr

                 Dim ConfArr, Str, ConfModelStr

                    ConfArr = SwModel.GetConfigurationNames

               

               

                        For ii = 1 To Rng.Rows.Count

               

               

                                  For jj = 0 To UBound(ConfArr)

                                      ConfModelStr = "@" & ConfArr(ii) & "@" & SwModel.GetTitle & """"

                                      Str = Replace(Rng(ii, 2), "~", ConfModelStr)

                                      'Stop

                                      SwModel.DeleteCustomInfo2 ConfArr(jj), Rng(ii, 1)

                                    

                                      SwModel.AddCustomInfo3 ConfArr(jj), Rng(ii, 1), 30, Str

                                    

                                      'Str = SwModel.GetCustomInfoValue(ConfArr(jj), Rng(ii, 1))

                                      'Stop

                                      Debug.Print Str

                                      SwModel.CustomInfo2(ConfArr(jj), Rng(ii, 1)) = Str

                                      'Stop

                                  Next jj

               

               

                        Next ii

                        ''

                        For ii = 0 To UBound(ConfArr)

                               Str = "@@" & ConfArr(ii) & "@" & SwModel.GetTitle & """"

                               'Stop

                               SwModel.AddCustomInfo3 ConfArr(ii), "质量", 30, """SW-Mass" & Str

                               SwModel.CustomInfo2(ConfArr(ii), "质量") = """SW-Mass" & Str

                               SwModel.AddCustomInfo3 ConfArr(ii), "材料", 30, """SW-Material" & Str

                               SwModel.CustomInfo2(ConfArr(ii), "材料") = """SW-Material" & Str

                             

                        Next ii

                  

                    SwModel.ForceRebuild3 True

                  

               

              End Sub

               

               

              ''

              Private Sub AddEquation()

                 Dim Xls As Excel.Application, Rng As Range

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

                    Set Rng = Xls.Selection

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                    Set SwApp = Application.SldWorks

                    Set SwModel = SwApp.ActiveDoc

                 Dim SwEqnMgr As EquationMgr, Arr()

                    Set SwEqnMgr = SwModel.GetEquationMgr

                 Dim ConfArr, Str, ConfModelStr

                    ConfArr = SwModel.GetConfigurationNames

                    With SwEqnMgr

                        ReDim Arr(.GetCount)

                        For ii = .GetCount To 0 Step -1

                            Arr(ii) = .Equation(ii)

                            Debug.Print .Equation(ii), .Value(ii), .Suppression(ii)

                            .Delete ii

                        Next ii

                        SwModel.ForceRebuild3 True

                        'Stop

                        For ii = 1 To Rng.Rows.Count

                           Select Case UCase(Rng(ii, 0))

                              Case UCase("Equation")

                                  .Add ii - 1, Rng(ii, 1)

                              Case UCase("CustInfo")

                                  For jj = 0 To UBound(ConfArr)

                                      ConfModelStr = "@@" & ConfArr(ii) & "@" & SwModel.GetTitle & """"

                                      Str = Replace(Rng(ii, 2), "~", ConfModelStr)

                                      'Stop

                                    

                                      SwModel.AddCustomInfo3 ConfArr(jj), Rng(ii, 1), 30, Str

                                    

                                      'Str = SwModel.GetCustomInfoValue(ConfArr(jj), Rng(ii, 1))

                                      'Stop

                                      Debug.Print Str

                                      SwModel.CustomInfo2(ConfArr(jj), Rng(ii, 1)) = Str

                                      'Stop

                                  Next jj

                           End Select

                        Next ii

                        ''

                        For ii = 0 To UBound(ConfArr)

                               Str = "@@" & ConfArr(ii) & "@" & SwModel.GetTitle & """"

                               'Stop

                               SwModel.AddCustomInfo3 ConfArr(ii), "质量", 30, """SW-Mass" & Str

                               SwModel.CustomInfo2(ConfArr(ii), "质量") = """SW-Mass" & Str

                               SwModel.AddCustomInfo3 ConfArr(ii), "材料", 30, """SW-Material" & Str

                               SwModel.CustomInfo2(ConfArr(ii), "材料") = """SW-Material" & Str

                             

                        Next ii

                    End With

                    SwModel.ForceRebuild3 True

                  

               

              End Sub

               

               

               

               

              ''

              Private Sub delAddEquation()

                 Dim Xls As Excel.Application, Rng As Range

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

                    Set Rng = Xls.Selection

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                    Set SwApp = Application.SldWorks

                    Set SwModel = SwApp.ActiveDoc

                 Dim SwEqnMgr As EquationMgr, Arr()

                    Set SwEqnMgr = SwModel.GetEquationMgr

                 Dim ConfArr, Str

                    ConfArr = SwModel.GetConfigurationNames

                    With SwEqnMgr

                        ReDim Arr(.GetCount)

                        For ii = .GetCount To 0 Step -1

                            Arr(ii) = .Equation(ii)

                            Debug.Print .Equation(ii), .Value(ii), .Suppression(ii)

                            .Delete ii

                        Next ii

                        SwModel.ForceRebuild3 True

                        'Stop

                        For ii = 1 To Rng.Rows.Count

                           Select Case UCase(Rng(ii, 0))

                              Case UCase("Equation")

                                  .Add ii - 1, Rng(ii, 1)

                              Case UCase("CustInfo")

                                  For jj = 0 To UBound(ConfArr)

                                      SwModel.AddCustomInfo3 ConfArr(jj), Rng(ii, 1), 30, Rng(ii, 2)

                                      Debug.Print SwModel.GetCustomInfoValue(ConfArr(jj), Rng(ii, 1))

                                      Str = SwModel.GetCustomInfoValue(ConfArr(jj), Rng(ii, 1))

                                      'Stop

                                      SwModel.CustomInfo2(ConfArr(jj), Rng(ii, 1)) = Str

                                  Next jj

                           End Select

                        Next ii

                        ''

                        For ii = 0 To UBound(ConfArr)

                               Str = "@@" & ConfArr(ii) & "@" & SwModel.GetTitle & """"

                               'Stop

                               SwModel.AddCustomInfo3 ConfArr(ii), "质量", 30, """SW-Mass" & Str

                               SwModel.CustomInfo2(ConfArr(ii), "质量") = """SW-Mass" & Str

                               SwModel.AddCustomInfo3 ConfArr(ii), "材料", 30, """SW-Material" & Str

                               SwModel.CustomInfo2(ConfArr(ii), "材料") = """SW-Material" & Str

                             

                        Next ii

                    End With

                    SwModel.ForceRebuild3 True

                  

               

              End Sub

               

               

               

              ,