7 Replies Latest reply on Jan 15, 2018 4:43 PM by Rey Bustamante

    Design Tables - Model not Updating

    Rey Bustamante

      Hi everyone,

       

      We're looking to automate changes to Design Tables. We have an assembly with a Design Table, and multiple children have their own Design Tables.

       

      We have a C# program that takes in a list of parameter values, and iterates through the assembly's BOM, opening Design Tables if they exist  for the file and modifying values in the process.

       

      Our problem is the changes made to the Design Table programmatically do not cause the same changes as if the tables were modified manually. Worse still, looking at examples online everyone's strategy for doing this looks to be different, and the SolidWorks API reference for these functions don't seem quite right (for example, UpdateModel() is a simplified version of UpdateTable() according to the documentation, yet they result in a different-looking model).

       

      Here's a basic overview of our logic:

       

                          //Open Design Table

                          IModelDoc2 model = _swApp.ActivateDoc3(model.GetPathName(), false, (int)swRebuildOnActivation_e.swRebuildActiveDoc, ref errors);

                          model.Extension.SelectByID2("Design Table", "DESIGNTABLE", 0, 0, 0, false, 0, null, 0);

                          model.InsertFamilyTableEdit();

                          IDesignTable swDesignTable = model.GetDesignTable();

                          swDesignTable.Attach();

                          swDesignTable.EditTable();

       

                          dynamic worksheetTemp = swDesignTable.Worksheet;

                          var worksheet = (worksheetTemp as Excel.Worksheet);

                    

                          //*Iterate through the worksheet, modifying required values using the Excel API*

       

                          //Close Design Table

                          swDesignTable.Detach();

                          model.CloseFamilyTable();

                          swDesignTable.UpdateTable((int)swDesignTableUpdateOptions_e.swUpdateDesignTableAll, true);

                          swDesignTable.UpdateModel();

       

      This seems excessive but gives the closest results to a manual change, using only Attach()/Detach() or EditTable2()/UpdateModel() requires us to open and close the Design Table a second time for the changes to "take".

       

      Does anyone have any ideas? Is there a definitive set of functions to call to properly update Design Tables? Any help is appreciated.

        • Re: Design Tables - Model not Updating
          Mr Omkar Deshpande

          Hi,

           

          I am not sure, but maybe we should not use IDesignTable::Attach & IDesignTable::EditTable2 in same code (As per documentation). This might be causing the problem.

          Also, use EditTable2 (New Window as Boolean) & assign it directly to your excel worksheet

          2017 SOLIDWORKS API Help - EditTable2 Method (IDesignTable)

          Try removing Attach & Detach methods from your code.

          • Re: Design Tables - Model not Updating
            Andrew Johnson

            Hi Rey,

            I'm sorry I don't have a good answer to your question, but I just thought I'd put my experience out there for the record.

             

            When working with Design Tables via the API we had lots of trouble with SolidWorks freezing, crashing, and updates not being made correctly (as you are seeing now). It got to the point where we decided to work directly with configuration properties instead. Design Tables have always caused headaches for me, even working with them directly (not via API).

             

            Best of luck to you.

            • Re: Design Tables - Model not Updating
              Rey Bustamante

              Omkar and Andrew - thank you for the replies, we are stuck using Design Tables for the foreseeable future, and we do update a lot (100+) of values. It's good to know other people are dealing with similar issues in SolidWorks.

               

              I've tried removing the Attach()/Detach(), and assigning the return from EditTable2:

               

               

                                  //Open Design Table

                                  IModelDoc2 model = _swApp.ActivateDoc3(model.GetPathName(), false, (int)swRebuildOnActivation_e.swRebuildActiveDoc, ref                     errors);

                                  model.Extension.SelectByID2("Design Table", "DESIGNTABLE", 0, 0, 0, false, 0, null, 0);

                                  model.InsertFamilyTableEdit();

                                  IDesignTable swDesignTable = model.GetDesignTable();

               

                                  var worksheet = (swDesignTable.EditTable2(false) as Excel.Worksheet);

                            

                                  //*Iterate through the worksheet, modifying required values using the Excel API*

               

                                  //Close Design Table

                                  model.CloseFamilyTable();

                                  worksheet = null     //SW API reference says to free variable assigned from EditTable2() function

                                  swDesignTable.UpdateTable((int)swDesignTableUpdateOptions_e.swUpdateDesignTableAll, true);

                                  swDesignTable.UpdateModel();

               

               

              Removing Attach()/Detach() doesn't seem to affect the configured model, however if I remove InsertFamilyTableEdit and CloseFamilyTable it is slightly affected so I've kept them in.

               

              Like I mentioned before I'm hoping there's an accepted, standard way to do this as there looks to be a lot of overlap in the API - e.g. Attach()/Detach() has been superceded by EditTable2()/UpdateModel(), but what is the difference? As well, after configuring the Design Tables we have to open and close the Design Table of the top level assembly to get everything to "take", either manually or through the API. I tried having us open/close the Design Table an extra time for every modified Design Table, but this didn't result in everything being configured correctly.

                • Re: Design Tables - Model not Updating
                  Mr Omkar Deshpande

                  This is what works for me always (in vb.net though)

                   

                  swModel = swApp.ActiveDoc

                  If swModel.Extension.HasDesignTable Then

                      swDesTable = swModel.GetDesignTable

                      xlSheet = swDesTable.EditTable2(True)

                      'Your code to update excel

                      swDesTable.UpdateTable(swDesignTableUpdateOptions_e.swUpdateDesignTableAll, True)

                  End If

                   

                  Where,

                   

                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.ModelDoc2

                  Dim swDesTable As SldWorks.DesignTable

                  Dim xlSheet As Excel.Worksheet

                   

                  I neither use Attach/Detach, nor I use InsertFamilyTable/CloseFamilyTable

                  Try if this helps you...

                    • Re: Design Tables - Model not Updating
                      Rey Bustamante

                      Hi Omkar,

                       

                      Are you configuring multiple Design Tables or just a single table? Our original code did just use EditTable2 and UpdateTable, but unfortunately that way seems to start having issues when dealing with multiple levels of Design Tables.

                       

                      Is your Excel logic using the Excel API or the SolidWorks Design Table functions (e.g. swDesignTable.SetEntryValue() and swDesignTable.GetEntryValue())? I wanted to use the SolidWorks Design Table functions but they don't seem to work as far as I can tell. GetEntryText()/GetEntryValue() works for retrieving the values, but when I want to modify values SetEntryText()/SetEntryValue() don't throw any exceptions yet nothing is modified.

                       

                      Instead I am modifying the cells using the Excel API in this manner:

                      //*Iterate through the Excel worksheet column by column, looking for matching column headers*

                      worksheet.Cells[4, col].Value2 = *value*;

                       

                      Thanks again for your help.

                        • Re: Design Tables - Model not Updating
                          Mr Omkar Deshpande

                          Rey Bustamante wrote:

                           

                          Are you configuring multiple Design Tables or just a single table? Our original code did just use EditTable2 and UpdateTable, but unfortunately that way seems to start having issues when dealing with multiple levels of Design Tables.

                           

                          Not 'Multiple levels of Design Tables', but yes, my code works for multiple parts with design tables.


                          Is your Excel logic using the Excel API or the SolidWorks Design Table functions (e.g. swDesignTable.SetEntryValue() and swDesignTable.GetEntryValue())? I wanted to use the SolidWorks Design Table functions but they don't seem to work as far as I can tell. GetEntryText()/GetEntryValue() works for retrieving the values, but when I want to modify values SetEntryText()/SetEntryValue() don't throw any exceptions yet nothing is modified.

                           

                          Instead I am modifying the cells using the Excel API in this manner:

                          //*Iterate through the Excel worksheet column by column, looking for matching column headers*

                          worksheet.Cells[4, col].Value2 = *value*;

                           

                          Yes, I use Excel API.

                           

                          But, it never happened to me that,  SetEntryText is not working but worksheet.Cells()... is working.

                          Initially neither was working for me, as i had forgot to set IDesignTable::Updatable to False (that *Block model to update design table* option)

                          though.

                           

                          Are you saving the model after closing design table?

                          Have you tried using Rebuild or ForceRebuild after closing design table?