How to get custom property from drawing to use in filename?
Mar 17, 2006 7 Replies
S
SW Monkey
I have a macro that generates a PDF file for a drawing, and saves it to a specific folder on our network. What I want to do is get the custom property "Revision" from the drawing, and put it at the end of the PDF filename.
EX. part TOP4332.sldrw current revision is 1
When saved, it will be TOP4332_01.pdf
Didn't find your answer? Ask the community — no account required.
M
Markku Lehtola
You can do that with SWup(BB):
formatting link
S
SW Monkey
Thanks Markku. I tried SWup(BB) a couple of months ago, and I had some trouble with it.
Could you possibly tell me what code I could use to get the Revision custom prop from the drawing and add it to the end of the filename? Like I said, I have a macro that saves the file as a PDF, and it removes the "-Sheet" from the filename.
M
Markku Lehtola
Was it the latest version 1.4? What kind of problem did you have?
Yep, I tried the latest version. Its Saves as a PDF, but it wont add the property to the end of the file.
Can you take a look at this code please. I cant get the retval = to work correctly.
*******START CODE********* Dim swApp As Object Dim Drawing As Object Dim boolstatus As Boolean Dim longstatus As Long Dim Annotation As Object Dim Gtol As Object Dim DatumTag As Object Dim FeatureData As Object Dim Feature As Object Dim Component As Object
Sub main() Dim FileName As String Dim dotpos As Integer Dim slashpos As Integer Dim dashpos As Integer Dim retval As String
Set swApp = CreateObject("SldWorks.Application") Set Drawing = swApp.ActiveDoc
If Drawing Is Nothing Then MsgBox ("No document loaded") Exit Sub End If
If Drawing.GetType swDocDRAWING Then MsgBox ("This macro only works with drawings.") Exit Sub End If
FileName = Drawing.GetPathName If FileName = "" Then 'model is not saved yet FileName = Drawing.GetTitle dashpos = InStrRev(FileName, "-") 'find dash to remove sheet name from title i.e. " - sheet1" FileName = Mid(FileName, 1, dashpos - 2) Else dotpos = InStrRev(FileName, ".") slashpos = InStrRev(FileName, "\")
If dotpos 0 Then ' if contains a dot (extension exists) then chop off extension FileName = Mid(FileName, slashpos + 1, dotpos - slashpos - 1) Else 'does not contain a dot FileName = Right(FileName, Len(FileName) - slashpos) End If End If
Load UserForm1
'set the filter UserForm1.CommonDialog1.Filter = "All Files (*.*)|*.*|PDF Files (*.pdf)|*.pdf "
No problem here, works ok with SW05sp3.1...SWupBB is not working with SW06sp2.1 because there's a problem in SW API, but I guess that is not the version you are running?