How to get custom property from drawing to use in filename?

Discussion in 'SolidWorks' started by SW Monkey, Mar 17, 2006.

  1. SW Monkey

    SW Monkey Guest

    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
     
    SW Monkey, Mar 17, 2006
    #1
  2. You can do that with SWup(BB):
    http://markkulehtola.net/swxx.html

    --

    regards

    Markku Lehtola
    Certified SolidWorks Professional (CSWP)

    www.markkulehtola.net
     
    Markku Lehtola, Mar 17, 2006
    #2
  3. SW Monkey

    SW Monkey Guest

    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.
     
    SW Monkey, Mar 17, 2006
    #3
  4. Was it the latest version 1.4? What kind of problem did you have?
    You can read the property values with:

    retval = ModelDoc2.GetCustomInfoValue ( configuration, FieldName )

    replace configuration name with "" when working with drawings. Then just
    add it to the name you already have, like:

    FinalPDFSaveName = NameWithoutSheetName & retval & ".pdf"

    --

    regards

    Markku Lehtola
    Certified SolidWorks Professional (CSWP)

    www.markkulehtola.net
     
    Markku Lehtola, Mar 17, 2006
    #4
  5. SW Monkey

    SW Monkey Guest

    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

    retval = ModelDoc2.GetCustomInfoValue("", Revision)

    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 "

    ' Specify default filter.
    UserForm1.CommonDialog1.FilterIndex = 2

    'Set the default file name
    UserForm1.CommonDialog1.FileName = "V:\Machinery\engineering\Temp\PDF\"
    + FileName + "_" + retval
    'FileName = "C:\xxx.DXF"

    ' Set CancelError is True
    UserForm1.CommonDialog1.CancelError = True

    ' CancelError is True.
    On Error GoTo ErrHandler

    UserForm1.CommonDialog1.ShowSave

    FileName = UserForm1.CommonDialog1.FileName
    Drawing.SaveAs3 FileName, swSaveAsCurrentVersion, swSaveAsOptions
    ErrHandler:
    ' User pressed Cancel button.

    Unload UserForm1
    Exit Sub



    End Sub

    ********END CODE**********
     
    SW Monkey, Mar 18, 2006
    #5
  6. SW Monkey

    Tin Man Guest

    Change
    retval = ModelDoc2.GetCustomInfoValue("", Revision)
    -to-
    retval = Drawing.GetCustomInfoValue("", "Revision")

    Ken
     
    Tin Man, Mar 18, 2006
    #6
  7. 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?

    (Tin Man got the code right)

    --

    regards

    Markku Lehtola
    Certified SolidWorks Professional (CSWP)

    www.markkulehtola.net
     
    Markku Lehtola, Mar 18, 2006
    #7
  8. SW Monkey

    SW Monkey Guest

    Im running SW 2005, SP 3.1

    My macro works correctly now after adding the

    retval = Drawing.GetCustomInfoValue("", "Revision")

    Thanks :)
     
    SW Monkey, Mar 24, 2006
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.