2 Replies Latest reply on Feb 3, 2017 12:57 AM by Nico Bester

    API: Extracting a derived BOM for a .slddrw file (C#)

    Nico Bester

      I am trying to extract the content of a .slddrw derived BOM in a stand-alone C# program.  I have been able to extract the named BOM content of a .sldasm file using the examples that is given in API help.  However it seems as if it is only possible to extract the list of derived BOM's linked to a .slddrw file and not the actual content of one of these derived BOMs.

       

      Derived Bom.jpg

      I hope that someone has tried and succeeded in this before.  I would appreciate it if you can help me with some advice.

       

      Kind regards,

      Nico Bester

        • Re: API: Extracting a derived BOM for a .slddrw file (C#)
          Jim Sculley

          First, get the list of available BOMs, sort them by bill ID and grab the one with the one with the highest ID, which should be the most recent:

          /// <summary>
          /// The official SolidWorks bill view is the BOM extracted by EPDM from the SolidWorks
          /// drawing file. 
          /// </summary>
          /// <param name="drawingFile">the drawing file whose SolidWorks BOM is desired</param>
          /// <returns>an IEdmBomView3 object corresponding to the SolidWorks BOM for the file</returns>
          /// <exception cref="ArgumentException"> if no SolidWorks BOM is found in the file</exception>
          public IEdmBomView3 getOfficialSolidWorksBillView(IEdmFile12 drawingFile)
          {
              EdmBomInfo bomInfo = getOfficialSolidWorksBillInfo(drawingFile);
              IEdmBom bom = (IEdmBom)vault.GetObject(EdmObjectType.EdmObject_BOM, bomInfo.mlBomID);
              IEdmBomView3 bomView = (IEdmBomView3)bom.GetView(0);
              if (bomView == null)
              {
                  throw new ArgumentException("No derived bills were found");
              }
              return bomView;
          }
          
          /// <summary>
          /// Retrieves the BOM info for the BOMs in a SolidWorks drawing.
          /// Since several such bills may be present (due to earlier file versions
          /// or file renaming), the most recent BOM view is assumed to be the correct view.
          /// </summary>
          /// <param name="drawingFile">the drawing file from which BOM info will be obtained</param>
          /// <returns>an EdmBomInfo object representing the 'official' BOM</returns>
          public EdmBomInfo getOfficialSolidWorksBillInfo(IEdmFile12 drawingFile)
          {
              List<int> swBillIDs = new List<int>();
              Array billInfo = Array.CreateInstance(typeof(EdmBomInfo), 0);
              ((IEdmFile12)drawingFile).GetDerivedBOMs(out billInfo);
              foreach (EdmBomInfo info in billInfo)
              {
                  if (info.mbsBomName.ToUpper().Contains("SLDDRW: BILL OF MATERIALS"))
                  {
                      swBillIDs.Add(info.mlBomID);
                  }
              }
              //arrange bills from oldest to newest
              swBillIDs.Sort();
              swBillIDs.Reverse();
              return Array.Find((EdmBomInfo[])billInfo, bi => bi.mlBomID == swBillIDs[0]);
          }
          

          Then, use GetRows and GetColumns from IEdmBomView and GetCellcomputedValue from EdmBomCell to to extract the data.