10 Replies Latest reply on Jun 8, 2018 10:49 AM by Christian Chu

    Macro not combining custom properties

    Fraser Port

      Hi,

      I have been using the macro below (originally from Deepak Gupta to add the @drawing revison to PDFs which works perfectly. Now Im trying to combine it with a minor revison property (from the drawing called MINOR REVISION).

      The result now only add the minor revision property to the file name.

       

      How do I combine the two properties?

      Thanks.

       

       

      Sub main()

       

      Set swApp = Application.SldWorks

      Set swModel = swApp.ActiveDoc

       

      If swModel Is Nothing Then End

       

      DateiMitPfad = swModel.GetPathName()

      If DateiMitPfad = "" Then

          MsgBox ("Please Save First!")

          swModel.Save

      End If

       

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

      swCustPrpMgr.Get3 "REVISION", False, "", Value

       

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

      swCustPrpMgr.Get3 "MINOR REVISION", False, "", Value

       

      sFilePath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))

       

      FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

      FileName = Left(FileName, InStrRev(FileName, ".") - 1)

       

      sFilePath = sFilePath

       

      If Value = "" Then

      FileName = sFilePath & FileName

      Else

      FileName = sFilePath & FileName & "_rev" & Value

      End If

       

      swModel.SaveAs2 FileName + ".PDF", 0, True, False

       

      End Sub

        • Re: Macro not combining custom properties
          Ivana Kolin

          Sub main()

           

          Set swApp = Application.SldWorks

          Set swModel = swApp.ActiveDoc

           

          If swModel Is Nothing Then End

           

          DateiMitPfad = swModel.GetPathName()

          If DateiMitPfad = "" Then

              MsgBox ("Please Save First!")

              swModel.Save

          End If

          dim majorrev as string

          dim minorev as string

           

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

          swCustPrpMgr.Get3 "REVISION", False, "", majorrev

           

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

          swCustPrpMgr.Get3 "MINOR REVISION", False, "", minorev

           

          sFilePath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))

           

          FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

          FileName = Left(FileName, InStrRev(FileName, ".") - 1)

           

          sFilePath = sFilePath

           

          If Value = "" Then

          FileName = sFilePath & FileName

          Else

          FileName = sFilePath & FileName & "_rev" & majorrev & minorev

          End If

           

          swModel.SaveAs2 FileName + ".PDF", 0, True, False

           

          End Sub

          • Re: Macro not combining custom properties
            Solid Air

            Think about it.  You set variable Value to REVISION then set variable Value to MINOR REVISION.  What do you think Value equals when your done?

             

            The reason Ivana's code fails is because Value is always = ""; it was replaced by majorrev and minorev

             

            My recommendation is to change the second Value to a different name (for simplicity Value2)  and change your FileName statement to:

             

            FileName = sFilePath & FileName & "_rev" & Value & Value2

             

            Probably will not be formatted to your liking but you get the idea.

              • Re: Macro not combining custom properties
                Fraser Port

                I had tried that originally but it had the error: Variable not defined.

                So combining the above answers, I got it to work by doing what Solid Air suggested but modified the line 'Dim Value2 As String' as suggested by Ivana Kolin.

                Im not API inclined so thanks for all the suggestions. Below is the final macro for anyone else trying to do this.

                 

                 

                Sub main()

                 

                Set swApp = Application.SldWorks

                 

                Set swModel = swApp.ActiveDoc

                 

                If swModel Is Nothing Then End

                 

                DateiMitPfad = swModel.GetPathName()

                 

                If DateiMitPfad = "" Then

                 

                    MsgBox ("Please Save First!")

                 

                    swModel.Save

                 

                End If

                 

                Dim Value2 As String

                 

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

                 

                swCustPrpMgr.Get3 "REVISION", False, "", Value

                 

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

                 

                swCustPrpMgr.Get3 "MINOR REVISION", False, "", Value2

                 

                sFilePath = Left(swModel.GetPathName, InStrRev(swModel.GetPathName, "\"))

                 

                FileName = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)

                 

                FileName = Left(FileName, InStrRev(FileName, ".") - 1)

                 

                sFilePath = sFilePath

                 

                If Value = "" Then

                 

                FileName = sFilePath & FileName

                 

                Else

                 

                FileName = sFilePath & FileName & "_rev" & Value & Value2

                 

                End If

                 

                swModel.SaveAs2 FileName + ".PDF", 0, True, False

                 

                End Sub