• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Vault Customization

    Reply
    Contributor
    Posts: 12
    Registered: 04-28-2007

    Creating PDF's from a drawing within the Vault Client

    272 Views, 4 Replies
    01-25-2012 11:45 AM

    Vault Professional 2012.

     

    Do we have access to the batch plot or any printing/plotting functions built into the Vault Client through the API?

     

    Most of our vendors and clients require PDFs. To that end what we do is manually create a PDF from inventor whenever updating and checking in a drawing.

     

    I have developed a Vault Add-In that allows a user to grab the BOM from an item card, or Associated files from an Inventor Assembly. The "BOM" is then displayed in a multi-level grid with all the information pertinent to us. Title, Description, Revision etc.

     

    I can then click on a button and have all of the related DWFs placed into a folder of choice, have them automatically named/renamed according to our standards with little or no input required by the user.

     

    What I would like is to do the same using PDF instead of DWF, thus eliminating the (often missed) manual process of creating the PDF as we update drawings.

    Employee
    Posts: 22
    Registered: 09-09-2007

    Re: Creating PDF's from a drawing within the Vault Client

    02-02-2012 12:35 AM in reply to: desidubajic

    Vault uses DWF as the default format for viewing the drawing, and changing this is not recommended because you may encounter some problems that are not expected and nobody tested those. You can consider to auto-generate the PDF through Inventor API.

     

    EventWatcher is a tool from Inventor SDK. You can use it to view what command is called when updating properties or checking file from Inventor. Two events are useful regrading to this:

    1) UserInputEvents.OnActivateCommand

    2) UserInputEvents.OnTerminateCommand

    And the command names that I found are: 

    VaultCheckinTop, 

    VaultPropertyWriteBack

     

    You can use an Inventor AddIn application to capture those events, similar like EventWatcher, and do your business logic when those commands in your interest are called.

     

    Inventor PDF translator can create the PDF file for you. There are existing sample in Inventor API document.

    Hope this helps. 

    Barbara Han
    Developer Technical Services
    Autodesk Developer Network
    Active Contributor kbo
    Active Contributor
    kbo
    Posts: 32
    Registered: 08-18-2010

    Re: Creating PDF's from a drawing within the Vault Client

    02-02-2012 11:21 AM in reply to: desidubajic

    Here is some code that does the trick?

     

    But read my remarks in the OnTerminate command. and how do we now grab the pdf and upload it to vault?

     

    regards kent boettger

     

    Private Sub m_UserinputEvents_OnActivateCommand(ByVal CommandName As String, ByVal Context As Inventor.NameValueMap) Handles m_UserinputEvents.OnActivateCommand
    
                If (CommandName = "VaultCheckinTop") Then
    
                    MsgBox("You are about to checkin a drawing to vault")
    
                    PublishSinglePDF()
    
                End If
    
            End Sub
    
            Private Sub m_UserinputEvents_OnTerminateCommand(ByVal CommandName As String, ByVal Context As Inventor.NameValueMap) Handles m_UserinputEvents.OnTerminateCommand
    
                If CommandName = "VaultCheckinTop" Then
    
                    'the question here is how do we actually check that the user checked in the drawing? and did no cancel the checkin
                    'here i figure we have to make a call into vault and somehow check that the version number increased.
                    'or is this version number somehow stored in the drawing file. because at this point the pdf is allready created
                    'and we have to go and delete it again if the user canceled the checkin. or can we maybe compare something inside the file before and after the checkin?
    
                End If
    
            End Sub
    
            Public Sub PublishSinglePDF()
    
                On Error Resume Next
    
                m_inventorApplication = GetObject(, "Inventor.Application")
    
                m_Document = m_inventorApplication.ActiveDocument
    
                If m_Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
    
                    MsgBox("No pdf was Created")
    
                    Exit Sub
    
                End If
    
                If m_Document.FileSaveCounter < 1 Then
    
                    MsgBox("You must save the file, before you can create the pdf")
    
                    Exit Sub
    
                Else
    
                    ' Get the PDF translator Add-In.
                    Dim PDFAddIn As TranslatorAddIn
                    PDFAddIn = m_inventorApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    
                    Dim oContext As TranslationContext
                    oContext = m_inventorApplication.TransientObjects.CreateTranslationContext
                    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism 'kFileBrowseIOMechanism
    
                    ' Create a NameValueMap object
                    Dim oOptions As NameValueMap
                    oOptions = m_inventorApplication.TransientObjects.CreateNameValueMap
    
                    ' Create a DataMedium object
                    Dim oDataMedium As DataMedium
                    oDataMedium = m_inventorApplication.TransientObjects.CreateDataMedium
    
                    ' Check whether the translator has 'SaveCopyAs' options
                    If PDFAddIn.HasSaveCopyAsOptions(m_Document, oContext, oOptions) Then
    
                        ' Options for drawings...
    
                        oOptions.Value("All_Color_AS_Black") = 1
    
                        oOptions.Value("Remove_Line_Weights") = 1
    
                        Dim Pdf_File_Name As String
    
                        Pdf_File_Name = m_Document.FullFileName.Substring(0, m_Document.FullFileName.Length - 4)
    
                        oDataMedium.FileName = (Pdf_File_Name & ".pdf")
    
                        'Publish document.
                        Call PDFAddIn.SaveCopyAs(m_Document, oContext, oOptions, oDataMedium)
    
                    End If
    
                End If
    
                If m_Document.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
    
                    MsgBox("You checked in a file to vault, the pfd was created in the local folder where the checked in drawing is")
    
                End If
    
            End Sub

     

    Contributor
    Posts: 12
    Registered: 04-28-2007

    Re: Creating PDF's from a drawing within the Vault Client

    02-15-2012 09:51 AM in reply to: desidubajic
    Thanks for the info. I was thinking that this would have to be done through Inventor. Although I read somewhere here, that you couldn't trap the "check-in" event. I guess I will have to write a one time utility that grabs all of the existing external PDF's and place them in Vault. After that PDF creation will take place within Inventor.
    Mentor
    Posts: 222
    Registered: 07-05-2005

    Re: Creating PDF's from a drawing within the Vault Client

    02-16-2012 04:00 AM in reply to: desidubajic

    This was supplied to me by Steve Bedder but will probably help you (It was written to work with Inventor iLogic):

     

    Public Sub InsertObjectSample()
        Dim doc As Document
        Set doc = ThisApplication.ActiveDocument
        
        ' Verify the active document has been saved.
        If doc.FullFileName = "" Then
            MsgBox "This document must be saved first."
            Exit Sub
        End If
        
        ' Build the filename based on the filename of the active document.
        Dim filename As String
        filename = doc.FullFileName
        filename = Left$(filename, InStrRev(filename, ".")) & "jpg"
        
        ' Make sure the specified file exists.
        If Dir(filename) = "" Then
            MsgBox "The file """ & filename & """ does not exist."
            Exit Sub
        End If
        
        ' Create the embedding.
        Dim oleReference As ReferencedOLEFileDescriptor
        Set oleReference = doc.ReferencedOLEFileDescriptors.Add(filename, kOLEDocumentEmbeddingObject)
     
        ' Set the name in the browser.
        oleReference.DisplayName = Mid$(filename, InStrRev(filename, "\") + 1)
    End Sub

     If you've already captured the check-in event within Inventor, there's no reason why you couldn't get Inventor to also add the created .pdf files as OLE attachments to the Inventor file itself which in turn will attach them to the Inventor file once it's in the Vault - in much the same way as images are attached..

     

    I would advise asking the user if they want to create/attach .pdf files each time as it would get extremely irritating if you had to wait for this to complete every time you checked a file in. 

     

    In fact, you could simply filter for a specific file type and only then prompt the user for .pdf creation.

     

    EDIT: A colleague just asked me what happens to an existing attachment if/when it gets updated by publishing a new version. I guess it would need to be removed and re-attached within Inventor before being returned to the Vault?