+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Super Member stevsmith's Avatar
    Computer Details
    stevsmith's Computer Details
    Operating System:
    Windows 7 (64bit)
    Computer:
    Dell Precision T3500
    CPU:
    Intel Xeon W3670 (Six Core 3.2GHz, 12MB Cache)
    RAM:
    12 Gb Ram (3x4GB) DDR3
    Graphics:
    2GB NviDia Quadro 4000
    Monitor:
    BenQ G2020HD
    Discipline
    Electro/Mech
    stevsmith's Discipline Details
    Occupation
    Design Draughtsman
    Discipline
    Electro/Mech
    Details
    Hydrogen & Nitrogen Generator Development (LCMS & GC) Product Development Sheet Metal
    Using
    not applicable
    Join Date
    Apr 2008
    Location
    Largs, Scotland
    Posts
    918

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

    Registered forum members do not see this ad.

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

    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.solid...ed-model/15615

    Any help would be much appreciated.

  2. #2
    Super Member stevsmith's Avatar
    Computer Details
    stevsmith's Computer Details
    Operating System:
    Windows 7 (64bit)
    Computer:
    Dell Precision T3500
    CPU:
    Intel Xeon W3670 (Six Core 3.2GHz, 12MB Cache)
    RAM:
    12 Gb Ram (3x4GB) DDR3
    Graphics:
    2GB NviDia Quadro 4000
    Monitor:
    BenQ G2020HD
    Discipline
    Electro/Mech
    stevsmith's Discipline Details
    Occupation
    Design Draughtsman
    Discipline
    Electro/Mech
    Details
    Hydrogen & Nitrogen Generator Development (LCMS & GC) Product Development Sheet Metal
    Using
    not applicable
    Join Date
    Apr 2008
    Location
    Largs, Scotland
    Posts
    918

    Default

    Registered forum members do not see this ad.

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

    Code:
    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

Similar Threads

  1. Replies: 1
    Last Post: 14th Aug 2012, 12:35 pm
  2. custom linetype (invalid number - bad continuation) error
    By samla02 in forum AutoCAD Drawing Management & Output
    Replies: 16
    Last Post: 17th Nov 2010, 12:47 am
  3. Filename field references xref filename
    By jcaberglund in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 1
    Last Post: 26th Jan 2010, 06:53 pm
  4. Proporties macro??
    By Huibert in forum AutoCAD General
    Replies: 0
    Last Post: 9th Jul 2008, 09:04 am
  5. ..Print a large number of dwg
    By snip in forum AutoCAD General
    Replies: 3
    Last Post: 6th Dec 2004, 04:28 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts