PDFs with Revisions

PDFs with Revisions

donaldleigh
Advocate Advocate
529 Views
4 Replies
Message 1 of 5

PDFs with Revisions

donaldleigh
Advocate
Advocate

Hi all

 

Can someone please help me out

 

I have the following code but would like to have the Revision Number added to the end of PDF file name only if the revision number is 1 or above

 

Our Company likes to add the revision numbers to the end of PDF files after the 1st Rev (which is Rev 0)

 

 SyntaxEditor Code Snippet

Dim oDoc As Inventor.Document
For Each oDoc In ThisApplication.Documents.VisibleDocuments
     If (oDoc.documenttype = kDrawingDocumentObject) Then 'Found a drawing
     'find the postion of the last backslash in the path
    oFNamePos = InStrRev(oDoc.fullfileName, "\", -1)   
    'get the file name with the file extension
    oName = Right(oDoc.fullfileName, Len(oDoc.fullfileName) - oFNamePos)
    'get the path of the folder containing the file
    oPath = Left(oDoc.fullfileName, Len(oDoc.fullfileName) - Len(oName))
     'get the file name (without extension)
    oShortName = Left(oName, Len(oName) - 4)
    oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
    ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
    
    If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
    'oOptions.Value("All_Color_AS_Black") = 0
    'oOptions.Value("Remove_Line_Weights") = 0
    oOptions.Value("Vector_Resolution") = 600
    oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
    'oOptions.Value("Custom_Begin_Sheet") = 2
    'oOptions.Value("Custom_End_Sheet") = 4
    End If
    
    'get PDF target folder path
    oFolder = oPath & "\PDF"
    
    'Check for the PDF folder and create it if it does not exist
    If Not System.IO.Directory.Exists(oFolder) Then
        System.IO.Directory.CreateDirectory(oFolder)
    End If
    
    'Set the PDF target file name
    oDataMedium.FileName = oFolder & "\" & oShortName & ".pdf"

    
    On Error Goto handlePDFLock
    
    'Publish document
    oPDFAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMedium)
      End If
Next oDoc

'Show message box
MessageBox.Show("PDF(s) exported to: " & oFolder , "iLogic") 
'--------------------------------------------------------------------------------

Exit Sub

handlePDFLock:MessageBox.Show("At least one PDF could not be saved, " _
& "most likely someone else has it open.", _
"No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next

Cheers

Donald 

0 Likes
Accepted solutions (2)
530 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor
Accepted solution
    oRevNum = oDoc.PropertySets("Inventor Summary Information")("Revision Number").Value
If oRevNum <> 0 Then
oShortName = Left(oName, Len(oName) - 4) & "-"& oRevNum
Else
oShortName = Left(oName, Len(oName) - 4)
End if

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 5

rhasell
Advisor
Advisor

Hi

 

I use the revision number slightly differently.

 

Try the following in a IF...Else , perhaps combined with the above suggestion.

 

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oDocument = ThisApplication.ActiveDocument
	oFolder ="d:\data\1 EXPORT"
	oDataMedium.FileName =oFolder & "\" & oFileName & "[" & oRevNum & "]" & ".pdf"
Reg
2026.1
0 Likes
Message 4 of 5

rhasell
Advisor
Advisor
Accepted solution

Hi

 

I played with MechMachines code. (I am by no means a programmer, I am a wizard at copy and paste)

 

All work perfectly, I would change the

If oRevNum <> 0 Then

to

If oRevNum <> "" Then

Because when I switched to Revision "A" the code failed.

 

In my workplace, we change the Revisions, at various stages of the build.

 

Reg
2026.1
0 Likes
Message 5 of 5

donaldleigh
Advocate
Advocate

Thanks everyone

0 Likes