Jump to content

Print to PDF (Filename and Rev Number from custom proporties)


stevsmith

Recommended Posts

(The description has been stolen because it describes exactly what im looking for ) :D

 

I have a macro that I use to generate a pdf of an open drawing. My drawing

filename is simply the part number. I want to Macro to append a revision

to the end of the filename before saving as a pdf. I carry the current rev

in a custom propety in the model. I have a note on my sheet format that

references this to diplay the rev in the title block.

 

I can't seem to use part.getcustominfo2 because it looks in the custom

property area of the drawing (which is empty) instead of referencing from the model

 

I do not know how to access the properties of the referenced model like my

notes do ($PRPSHEET:REV).

 

Any ideas how to do this?

 

 

Sub pdfmaker1()

Dim swApp As Object

Dim Part As Object

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

 

Dim swModel As SldWorks.ModelDoc2

 

Dim WholeFilename As String

Dim Prefix As String

Dim MyFilename As String

Dim MyPath As String

Dim CurrentRev As String

Dim LastParenPosition As Integer

Dim PDFName As String

 

Set swModel = swApp.ActiveDoc

WholeFilename = swModel.GetPathName

 

CurrentRev = swModel.GetCustomInfoValue("", "Revision")

 

If CurrentRev = "--" Then CurrentRev = "-Rev0" Else CurrentRev = "-Rev" & CurrentRev

 

LastParenPosition = InStrRev(Prefix, "\")

 

MyFilename = Right(WholeFilename, Len(WholeFilename) - LastParenPosition)

 

If Len(MyFilename) = 0 Then MsgBox ("Drawing not saved yet")

If Len(MyFilename) = 0 Then End

 

MyFilename = Left(MyFilename, Len(MyFilename) - 7) + CurrentRev + ".pdf"

 

Set Part = swApp.ActiveDoc

Part.EditSketch

swApp.ActiveDoc.ActiveView.FrameState = 1

Part.SaveAs2 MyFilename, 0, True, False

Part.EditSketch

 

MsgBox MyFilename + " saved as a pdf"

End Sub

 

My collegue found this link which asks the same question but our knowlege of VB is non existent.

 

http://compgroups.net/comp.cad.solidworks/api-get-custom-prop-from-referenced-model/15615

 

Any help would be much appreciated.

Link to comment
Share on other sites

It's ok folks I managed to get a code for it.

 

Dim swApp           As SldWorks.SldWorks
Dim swModel         As SldWorks.ModelDoc2
Dim swDraw          As SldWorks.DrawingDoc
Dim swCustProp      As CustomPropertyManager
Dim valOut          As String
Dim valOut1         As String
Dim valOut2         As String
Dim resolvedValOut  As String
Dim resolvedValOut1 As String
Dim resolvedValOut2 As String
Dim Filepath        As String
Dim FileName        As String
Dim ConfigName      As String

Sub main()
Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc
' Check to see if a drawing is loaded.
If (swDraw Is Nothing) Or (swDraw.GetType <> swDocDRAWING) Then
' If no model currently loaded, then exit
Exit Sub
End If
Set swView = swDraw.GetFirstView
Set swView = swView.GetNextView
Set swModel = swView.ReferencedDocument
ConfigName = swView.ReferencedConfiguration
Set swCustProp = swModel.Extension.CustomPropertyManager(ConfigName)
swCustProp.Get2 "NewPartNo", valOut, resolvedValOut                 'Change the custom property name here
swCustProp.Get2 "AssyDescription", valOut1, resolvedValOut1         'Change the custom property name here
swCustProp.Get2 "CurrentRev", valOut2, resolvedValOut2              'Change the custom property name here
Filepath = "C:\Drawings\"
FileName = Left(swDraw.GetTitle, Len(swDraw.GetTitle) - 9)
swDraw.SaveAs (Filepath + resolvedValOut + " - " + resolvedValOut1 + " - Rev" + resolvedValOut2 + ".PDF")   'Change the custom property text here
MsgBox resolvedValOut + " - " + resolvedValOut1 + " - Rev" + resolvedValOut2 + "   Saved as a PDF"
End Sub

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...