7 Replies Latest reply on May 29, 2017 3:57 PM by Norbert Gal

    BOM column Hide/Show API VB.NET

    Norbert Gal

      Hi,

       

      I have a BOM table what contains hidden columns. I'd like get the title and visibility informations of all columns.

      This is a sample part of my code below.

      My problem is that I get empty string from GetColumnTitle and False from  ColumnHidden  when I tried to get this informations on a hidden column.

      What do I wrong?

       

      Dim BomFeature As SldWorks.BomFeature

      Dim BomTableAnn As SldWorks.BomTableAnnotation

      Dim TableAnn As SldWorks.TableAnnotation

       

      '--gets the BomFeature object with help of other Function

      BomFeature = GetFirstBom()

      BomTableAnn = BomFeature.IGetTableAnnotations(1)

      TableAnn = BomTableAnn

       

      maxRow = BomTableAnn.RowCount - 1

      maxCol = TableAnn.TotalColumnCount '--gets the column count even if there is hidden columns

       

      For c = 0 To maxCol - 1

      Debug.Print("Title: {0}", TableAnn.GetColumnTitle(c))

      Debug.Print("Hidden: {0}", TableAnn.ColumnHidden(c))

      Next

        • Re: BOM column Hide/Show API VB.NET
          Norbert Gal

          I forgot to say the BOM is in Assembly.

          Now I tried to put the BOM into a Drawing, and it is working in this case.

          But why doesn't works in Assembly?

          • Re: BOM column Hide/Show API VB.NET
            Patrik MacHalec

            Hi Norbert,

            did you try GetTableAnnotations() instead of IGetTableAnnotations()

             

            From help of IGetTableAnnotations()

            Return Value:

            • VBA, VB.NET, C#, and C++/CLI: Not supported

             

            Are you sure that your BomTableAnn is not equal to nothing?

              • Re: BOM column Hide/Show API VB.NET
                Norbert Gal

                Hi,

                I've tried GetTableAnnotations, but in this case I got 'System.InvalidCastException' error when I try to set it's result to variable BomTableAnn (SldWorks.BomTableAnnotation).

                If I use BomTableAnn As Object that is OK, but in this case later I can't use it's properties and funtions.

                 

                With IGetTableAnnotations everything works fine except this Asm Bom column show/hide, and yes I checked BomTableAnn is not equal to nothing.

              • Re: BOM column Hide/Show API VB.NET
                Patrik MacHalec

                Hi,

                I do not know if you can use "index" in method GetTableAnnotations(). There is no index option in help.

                BomTableAnn = BomFeature.IGetTableAnnotations(1)

                 

                Try this procedure below. I did not test it.

                 

                Dim vTableArr As Object

                Dim vTable As Object

                Dim swTable As TableAnnotation

                vTableArr = swBomFeat.GetTableAnnotations

                 

                For Each vTable In vTableArr

                            swTable = vTable

                          .. do job with swTable

                Next vTable

                • Re: BOM column Hide/Show API VB.NET
                  Patrik MacHalec

                  Hi Norbert,

                  it works for me.

                  ColumnCount will change everytime when you hide or unhide column.

                   

                   

                   

                  public void HideColumn()
                  {
                      IModelDoc2 swModel = null;
                      IFeature swFeat = null;
                      BomFeature swBomFeat = null;
                      object[] tables = null;
                      TableAnnotation swTable = null;

                      swModel = (IModelDoc2)iSwApp.ActiveDoc;
                      swFeat = swModel.FirstFeature();

                      while (swFeat != null)
                      {
                          if (swFeat.GetTypeName2() == "BomFeat")
                          {
                              swBomFeat = (BomFeature)swFeat.GetSpecificFeature2();
                              Console.WriteLine("number of ann : " + swBomFeat.GetTableAnnotationCount());
                              tables = swBomFeat.GetTableAnnotations();
                              foreach (var table in tables)
                              {
                                  swTable = (TableAnnotation)table;
                                  Console.WriteLine("number of columns visible " + swTable.ColumnCount);
                                  Console.WriteLine("number of columns " + swTable.TotalColumnCount);

                                  for (int i = 0; i < swTable.TotalColumnCount; i++)
                                  {
                                      if (i > 0)
                                      {
                                          Console.WriteLine(swTable.GetColumnTitle(i));
                                          swTable.ColumnHidden[i] = true;
                                      }
                                  }
                              }
                              break;
                          }
                          swFeat = swFeat.GetNextFeature();
                      }
                  }

                   

                   

                  • Re: BOM column Hide/Show API VB.NET
                    Norbert Gal

                    It works thank you.
                    I check ColumnCount before and after I set ColumnHidden(i) to false, and if it is different I know the column was hidden
                    Btw I wonder why is this so complicated, but at least there is some method