Reading custom properties and saving as a pdf

I have tried to write a vb script/macro to create a pdf of a drawing and name it the part number and revision.

I can get every thing to work but not together. There are two scripts below.

I use this line in a vb script/macro and it works fine in the lower maco but not in the top one:

CheckPartNum = dwgDoc.CustomInfo2("", "PartNo")

I use this line in a vb script/macro and it works fine in the top script but not in the lower one

longstatus = Part.SaveAs3(PDFfilename, 0, 0)

I keep running into the same issue that either one or the other works, but never both.

This is a a vb script from word (just so i could try other part of the script out) I have this script tied to button.  Everything is good till i get to the line marked below and I get the following error message: "Run-time error '424': Object required. If i manially set those variables to something everything works fine.  I have used the same line in another marco to read custom properties and it works fine.

What am I missing?  The only reason I am doing this is that PDMworks enterprise has an error when trying to read rev value from the DB and the task scheduler doesn't read the file properties to name the pdf correctly.

---------------------------------------------------------------------------------------------------------------------------------------------------------------- 

Public CheckPartNum As String   ' this will be populated with the part number value from the custom properties of the file opened

Public CheckCurRev As String    ' this will be populated with the rev value from the custom properties of the file opened

Public PDFfilename As String    ' this will become the path and filename of the PDF file

Public PDFpath As String    ' path for pdf files to be deposited into

Public SW_Drawing As String ' path and filename of solidworks drawing to be opened

Public boolstatus As Boolean

Public longstatus As Long, longwarnings As Long

Dim swApp As Object

Dim Part As Object

Public Visible As Boolean

Public swDocDRAWING As Integer

Public val As String

Public valout As String

Private Sub CommandButton1_Click()

    Call make_PDF

 

End Sub

Sub make_PDF()

SW_Drawing = "C:\\Users\\whagen\\Desktop\\86511#3.SLDDRW"

 

Set swApp = CreateObject("SldWorks.Application")

 

swApp.Visible = True

 

Set Part = swApp.OpenDoc6(SW_Drawing, 3, 0, "", longstatus, longwarnings)

 

swApp.ActivateDoc2 "86511#3 - Sheet1", False, longstatus

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

myModelView.FrameLeft = 0

myModelView.FrameTop = 0

Set myModelView = Part.ActiveView

'myModelView.FrameState = swWindowState_e.swWindowMaximized

Set myModelView = Part.ActiveView

'myModelView.FrameState = swWindowState_e.swWindowMaximized

Part.ViewZoomtofit2

Call CheckProps

       

PDFpath = "C:\\Users\\whagen\\Desktop\\" ' enter the path where you want to PDF file to be saved

MsgBox ("Operation Completed!" + " " + PDFpath)

PDFfilename = PDFpath + CheckPartNum + "#" + CheckCurRev + ".pdf" 'creates the path and filename of the pdf file to be saved

MsgBox ("Operation Completed!" + " " + PDFfilename)

longstatus = Part.SaveAs3(PDFfilename, 0, 0)

Set Part = Nothing

swApp.ExitApp

Set swApp = Nothing

End Sub

Sub CheckProps()

' Get custom properties

CheckPartNum = dwgDoc.CustomInfo2("", "PartNo") ' get current Part Number      Stop script stops here

CheckCurRev = dwgDoc.CustomInfo2("", "Revision") ' get current Revision     

'  CheckPartNum = "123456" ' get current Part Number

'  CheckCurRev = "ABC" ' get current Revision

End Sub

Thinking that I don't have much of clue as to what I am doing I come up with the following macro that I run within SW

'See CustProp form for file information.

 

Public swApp As Object

Public CurrentDoc As Object

Public IniList As String

 

Public ConfigNum As Long

Public ConfigNames As Variant

Public ConfigCount As Long

   

Public PartNo As String

Public CurReV As String

 

Public CheckPartNum As String

Public CheckCurRev As String

   

Public longstatus As Long

Public longwarnings As Long

 

Public Const swCustomInfoText = 30

Public Const swViewAnimationSpeed = 38

Const swDocPART = 1

Const swDocASSEMBLY = 2

Const swDocDRAWING = 3

Sub CheckProps()

 

' Get custom properties

  CheckPartNum = CurrentDoc.CustomInfo2("", "PartNo") ' get current PN  This works fine here

  CheckCurRev = CurrentDoc.CustomInfo2("", "Revision") ' get current Revision This works fine here

 

MsgBox ("Operation Completed!" + " " + CheckPartNum + " " + CheckCurRev)

 

PDFpath = "C:\\Users\\whagen\\Desktop\\" ' enter the path where you want to PDF file to be saved

MsgBox ("Operation Completed!" + " " + PDFpath)

 

PDFfilename = PDFpath + CheckPartNum + "#" + CheckCurRev + ".pdf" 'creates the path and filename of the pdf file to be saved

MsgBox ("Operation Completed!" + " " + PDFfilename)

 

longstatus = Part.SaveAs3(PDFfilename, 0, 0) Now this doesn't works

 

Set Part = Nothing

 

swApp.ExitApp

 

Set swApp = Nothing

 

End Sub

 

Sub Main()

 

Set swApp = CreateObject("SldWorks.Application")

Set CurrentDoc = swApp.ActiveDoc

Set Part = swApp.ActiveDoc

   

' No document loaded error handler

  If Part Is Nothing Then

      MsgBox "No document loaded!", vbCritical

      End

  Else

  End If

 

Part.ClearSelection2 True

 

Call CheckProps

 

End Sub

SolidworksApi macros