2 Replies Latest reply on Oct 12, 2012 8:07 AM by John Phillips

    BOM and Balloon Macro Issues

    John Phillips

      Hello All,


      I am very new to macros.  I am having problems with a section of my macro code.  At one point, a BOM table is generated from the current view.  I can get it to generate correctly for a PartsOnly and Indented BOM, but the table shows up blank when I try a TopLevelOnly BOM.  See the code below...


      Dim AnchorType         As Long

          Dim BomType            As Long

          Dim Configuration      As String

          Dim TableTemplate      As String

          Dim swBOMAnnotation    As SldWorks.BomTableAnnotation

          Dim swBOMFeature       As SldWorks.BomFeature


          AnchorType = swBOMConfigurationAnchor_TopLeft

          BomType = swBomType_TopLevelOnly

          TableTemplate = "C:\Program Files\SolidWorks Corp\SolidWorks\lang\english\bom-standard.sldbomtbt"

          Configuration = ""

          Set swBOMAnnotation = swView.InsertBomTable3(False, 0.104293835860446, 0.20955, AnchorType, BomType, Configuration, TableTemplate, False)

          Set swBOMFeature = swBOMAnnotation.BomFeature



      I have another issue where I am trying to get it to autoballoon the current view and it seems to miss some of the balloons.  See code below...


      Dim boolstatus As Boolean


          boolstatus = swModel.ActivateView("Drawing View1")

          boolstatus = swModel.Extension.SelectByID2("Drawing View1", "DRAWINGVIEW", 9.20724224417876E-02, 0.147008710805877, 0, False, 0, Nothing, 0)


          Dim vNotes As Variant

          Dim autoballoonParams As Object


          Set autoballoonParams = swModel.CreateAutoBalloonOptions()

          autoballoonParams.Layout = 1

          autoballoonParams.ReverseDirection = False

          autoballoonParams.IgnoreMultiple = False

          autoballoonParams.InsertMagneticLine = False

          autoballoonParams.LeaderAttachmentToFaces = False

          autoballoonParams.Style = 1

          autoballoonParams.Size = 2

          autoballoonParams.UpperTextContent = 1

          autoballoonParams.UpperText = """"

          autoballoonParams.Layername = "-None-"

          autoballoonParams.ItemNumberStart = 1

          autoballoonParams.ItemNumberIncrement = 1

          autoballoonParams.ItemOrder = 0

          vNotes = swModel.AutoBalloon5(autoballoonParams)

          swModel.ClearSelection2 True


      I'm still learning, so any steps in the right direction will be helpful. Thanks for your help.

        • Re: BOM and Balloon Macro Issues
          Keith Rice



          Welcome to the forums.


          For your first question, in the API Help remarks for IView::InsertBomTable3, it says you need to use IBomFeature::GetConfigurations and IBomFeature::SetConfigurations with top-level only BOMs. See this example and you'll see how it works: Insert BOM Table Example (VBA)


          For your second question, are you expecting it to balloon components that aren't visible? Otherwise, if it is not ballooning visible components, could you please attach the pack and go .zip for a SIMPLE example drawing for me to look at? (By "simple" I mean nothing but a single sheet containing a single drawing view of the assembly in question. No additional sheets, view, or anything that isn't necessary for examining the problem. Thanks.)


          You seem to be doing good for an API beginner. I commend you. If you're still in the stage of copying and pasting existing macros, and you really want to understand what the code means, I'd recommend you check out the resources at the site in my signature. Also, you might find this blog post helpful: 7 Mistakes New SolidWorks API Programmers Make


          Hope this helps.



          Video Tutorials for the SolidWorks API

            • Re: BOM and Balloon Macro Issues
              John Phillips



              Thanks for your response.  I actually figured out the BOM issue shortly after my post.  I also feel like I am getting close on the ballooning issue as well and I am going to keep trying a little longer.  If I can't get it to work properly I will attach an example.


              Thank you for those links, they are very helpful, especially for a beginner.  As I move forward with learning API I will probably have more issues and probably post some of those later.  Thanks for your help.