8 Replies Latest reply on Aug 15, 2017 5:58 AM by Yong Ning

    Equation in BOM

    Di Anne

      Hi SW Community,

       

      I am currently creating a macro for BOM.

      And I have this problem on how to create equation.

      As you can see below, I need to sum up the total weight of each part.

       

       

      Does anyone knows how to do this?

       

      Thank you in advance.

       

      Regards,

      DiAnne

          • Re: Equation in BOM
            Di Anne

            Hi Artem,

             

            I'm creating a macro from c#  and it seems that it doesn't support swTable.Text.

             

            Below is the equation I used when I create it manually.

            How should I do it API?

            {0} "Total Equation ="  SUM(G2:G11)  "kg";

             

            Thanks.

             

            DiAnne

              • Re: Equation in BOM
                Artem Taturevych

                C# doesn't support parameters in properties. So you should use get/set methods. Something like

                 

                swTable.set_Text("EQUATION");

                  • Re: Equation in BOM
                    Di Anne

                    I see.

                     

                    But can you help me how will I do this equation {0} "Total Equation ="  SUM(G2:G11)  "kg" ?

                     

                    Thank you in advance.

                      • Re: Equation in BOM
                        Artem Taturevych
                        swTable.set_Text(1, 4, "=\"TOTAL: \" SUM(G2:G11) \"kg\"");
                        
                          • Re: Equation in BOM
                            Di Anne

                            Thanks.

                            • Re: Equation in BOM
                              Yong Ning

                              Equation in BOM | SOLIDWORKS Forums  https://forum.solidworks.com/message/576416

                              This code don't use

                              swTable.set_Text(1, 4, "=\"TOTAL: \" SUM(G2:G11) \"kg\"");

                               

                              Search key word is " set_Text " in SOLIDWORKS API Help??

                               

                              help ,in Solidworks 2012 API , result is not found?

                                • Re: Equation in BOM
                                  Yong Ning

                                  Sub del4()

                                     

                                      Dim Xls As Excel.Application, Rng As Range

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

                                           Set Rng = Xls.Selection

                                      Dim ColCount

                                           ColCount = Rng.Columns.Count

                                      Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                           Set SwApp = Application.SldWorks

                                           Set SwModel = SwApp.ActiveDoc

                                      Dim SwDraw As DrawingDoc, SwSheet As Sheet

                                           Set SwDraw = SwModel

                                           Set SwSheet = SwDraw.GetCurrentSheet

                                      Dim SwSelMgr As SelectionMgr

                                           Set SwSelMgr = SwModel.SelectionManager

                                      Dim Conf, SwConf As Configuration

                                      Dim vCustInfo, CustInfo

                                      Dim ii, jj, Str, Tmp

                                           Tmp = RngSheetChangeBOM(SwModel, SwSelMgr, SwSheet, Rng)

                                      

                                           '

                                         

                                          

                                  End Sub

                                   

                                   

                                  ''

                                  Function RngSheetChangeBOM(SwModel As ModelDoc2, SwSelMgr As SelectionMgr, SwSheet As Sheet, Rng As Range)

                                      ''

                                          

                                      Dim Tmp, Str

                                          

                                      Dim SwAnn As Annotation

                                      Dim SwTabAnn As TableAnnotation

                                      Dim SwBOMTab As BomTableAnnotation

                                      Dim SwBOMFeat As BomFeature

                                     

                                      Dim TextFormat As TextFormat

                                           Str = SwSheet.GetName & "BOM"

                                           Tmp = SwModel.Extension.SelectByID2(Str, "BOMFEATURE", 0, 0, 0, False, 0, Nothing, 0)

                                           Set SwBOMFeat = SwModel.SelectionManager.GetSelectedObject5(1)

                                           Set SwBOMTab = SwBOMFeat.GetTableAnnotations(0)

                                   

                                   

                                           Set SwTabAnn = SwBOMTab

                                           With SwTabAnn

                                              cc = .ColumnCount - Rng.Columns.Count

                                              ''

                                              If cc > 0 Then

                                                 For jj = .ColumnCount To .ColumnCount - cc Step -1

                                                     .DeleteColumn (jj)

                                              Next jj

                                              ElseIf cc < 0 Then

                                                     .InsertColumn swTableInsertPosition_After, .ColumnCount, "aa" & jj '

                                              End If

                                              ''

                                           End With

                                           With SwBOMTab

                                               For jj = 1 To Rng.Columns.Count

                                                   Debug.Print "  Column(" & jj & ") = " & .GetColumnCustomProperty(jj),

                                                   Debug.Print SwTabAnn.GetColumnTitle(jj)

                                                   .SetColumnCustomProperty jj - 1, Rng(0, jj)

                                                   SwTabAnn.SetColumnWidth jj - 1, Rng(-1, jj) / 1000, 0

                                                   SwTabAnn.SetColumnTitle jj - 1, Rng(1, jj)

                                               Next jj

                                           End With

                                           ''

                                           With SwTabAnn

                                               ''

                                               For ii = 0 To .RowCount

                                                   .SetRowHeight ii, 5 / 1000, 0

                                               Next ii

                                               Set SwAnn = .GetAnnotation

                                               .AnchorType = Rng(-2, 3)

                                               Set TextFormat = .GetTextFormat

                                               TextFormat.TypeFaceName = "ºÚÌå"

                                               .SetTextFormat False, TextFormat

                                           End With

                                          

                                           ''

                                           xx = Rng(-2, 1) / 1000

                                           yy = Rng(-2, 2) / 1000

                                           zz = 0

                                          

                                           SwAnn.SetPosition xx, yy, zz

                                          

                                  End Function