0 Replies Latest reply on Jan 25, 2016 6:44 PM by Rick Hombsch

    Auto-Run Macro leading to system being in unstable state message

    Rick Hombsch

      I am trying to auto-run an embedded macro as shown here:

      http://www.cadsharp.com/blog/equation-triggered-macros/

      The macro is used to modify design table values based on custom property inputs. The macro runs and updates the design table as needed however I get the following error (see below). Also sometimes I may get a corrupted design table. The macro I am running is shown below and only runs when the RunMacro custom property is 0. Attached is a simplied version of what I am trying to do however the premise is the same.

       

      Sub main()

       

       

      Dim valOut   As String

      Dim resolvedValOut      As String

      Dim swApp As SldWorks.SldWorks

      Dim swModel As SldWorks.ModelDoc2

      Dim swDesignTable As SldWorks.DesignTable

      Dim CellValue As String

      Dim boolstatus As Boolean

       

      Set swApp = Application.SldWorks

       

      Set swModel = swApp.ActiveDoc

      Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")

       

      'RebuildMacro Variable Used to Only run code on first rebuild

      swCustPropMgr.Get2 "RebuildMacro", valOut, resolvedValOut

      MacroRunValue = valOut

       

      'Get Length Width Height

      swCustPropMgr.Get2 "LENGTH", valOut, resolvedValOut

      Length = valOut

      swCustPropMgr.Get2 "WIDTH", valOut, resolvedValOut

      Width1 = valOut

      swCustPropMgr.Get2 "HEIGHT", valOut, resolvedValOut

      Height = valOut

       

      'If the model is rebuilt for the first time (MacroRunValue = 0)

      If MacroRunValue = 0 Then

       

      'Get Design Table

      Set swDesignTable = swModel.GetDesignTable

      'Edit Design Table

      swDesignTable.EditTable

      'Changes the first data row second colum to the cell value

      swDesignTable.SetEntryValue 1, 0, False, Length

      swDesignTable.SetEntryValue 1, 1, False, Width1

      swDesignTable.SetEntryValue 1, 2, False, Height

       

      'Update Design Table

      boolstatus = swDesignTable.UpdateTable(SwConst.swDesignTableUpdateOptions_e.swUpdateDesignTableAll, True)

      'Set RebuildMacro Custom Property to 1 so macro does not run again

      swCustPropMgr.Set "RebuildMacro", 1

      End If

       

      End Sub