1 Reply Latest reply on Jun 3, 2015 10:42 AM by Todd Carpenter

    SetEntryValue/GetEntryValue C#

    Todd Carpenter

      I don't seem to be able to get this to work.  I'm not quite sure what I'm doing wrong, the code executes with no errors or warnings, but it doesn't seem change anything:

      namespace DesignTables.csproj
      {
          public partial class SolidWorksMacro
          {
              public void Main()
              {
                  IModelDoc2 swDoc = null;
                  IDesignTable dt = default(IDesignTable);
                  bool boolstatus = false;
      
      
                  swDoc = ((IModelDoc2)(swApp.ActiveDoc));
                  dt = (IDesignTable)swDoc.GetDesignTable();
      
      
                  boolstatus = dt.Attach();
      
      
                  dt.EditTable2(true);
      
      
                  dt.SetEntryValue(3, 2, false, "3");
                  dt.UpdateTable(2, true);
                  dt.UpdateModel();
                  
                  string msg = "|" + dt.GetEntryText(2, 1) + "|";
                  Debug.Print(msg);
                  dt.Detach();
      
      
                  swDoc.ForceRebuild3(false); 
              }
      
      
              /// <summary>
              ///  The SldWorks swApp variable is pre-assigned for you.
              /// </summary>
              public SldWorks swApp;
          }
      }
      

       

      Any help would be appreciated...

       

      Thanks

        • Re: SetEntryValue/GetEntryValue C#
          Todd Carpenter

          In case this helps someone else out...

           

          I'm either doing something wrong, or the SetEntry and GetEntry don't work.  To get around this, I added a reference to Microsoft Excel and used this method:

           

                      boolstatus = dt.Attach();
          
                      Worksheet ws = (Worksheet)dt.Worksheet;
          
                      Range rng = (Range)ws.Cells[3, 2];
          
                      rng.Value2 = 3;
          
                      dt.UpdateTable(2, true);
                      dt.UpdateModel();
                      dt.Detach();
          

           

          This works for updating the spreadsheet and the models

           

          HTH

          Todd