1 Reply Latest reply on Nov 17, 2014 5:27 PM by Daniel Andersson

    K Factor in Custom Properties

    Mike Helsinger

      I recently created a macro that grabs the K Factor from a part file and puts it in Custom Properties using the line:

      KFactor = Chr(34) & "D2@Sheet-Metal2" & Chr(34)

       

      Many thanks to Deepak for helping me get as far as I have.

      I have come to realize that as I work with imported files the tag on the sheet metal feature may vary, generally Sheet-Metal1, Sheet-Metal2, or perhaps Sheet-Metal3.  I'd like to write a macro loop with a feedback that chooses the correctly tagged Sheet-Metal feature for the output.  I've tinkered around but the loop doesn't seem to loop, it just selects the first "K" that's coded without advancing.  I have a feeling it's how the valout translates in the swCustProp.Get4 line.  I've tried different declarations, loop techniques & qualifiers (modifying boolean statements of variables and lengths of a few of my variables) but I'm not cracking it.  Does anyone know a way to get there?  I'm including the code I have been tooling on & a sample part file.  I'm on SW 2014 Premium x64 SP4.0

       

      ******************************************

      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swCustProp As CustomPropertyManager
      Dim K As Integer
      Dim KFactor As String
      Dim valout As String

      Sub main()

      Set swApp = Application.SldWorks
      Set swModel = swApp.ActiveDoc

      If swModel Is Nothing Then
      MsgBox "Make sure there is an open active document"
      Exit Sub
      End If

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

      K = 0
      Do
          K = K + 1
          swCustProp.Delete "K Factor"
          KFactor = Chr(34) & "D2@Sheet-Metal" & K & Chr(34)
          retval = swModel.AddCustomInfo3("", "K Factor", 30, KFactor)
          retval = swCustProp.Get4("K Factor", False, KFactor, valout)
          If Len(KFactor) > 0 Then GoTo Line1
          Loop Until Len(K) > 1

      Line1:
          MsgBox ("K Factor updated")


      End Sub