代码形式:Inventor内置ilogic工具
兼容版本:Autodesk Inventor 2018
解决的问题:方便自动将工程图保存为PDF文件格式
具体代码如下:
1: oPath = ThisDoc.Path
2: oFileName = ThisDoc.FileName(False) 'without extension
3: oRevNum = iProperties.Value("project", "revision number")
4: oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
5: ("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
6: oDocument = ThisApplication.ActiveDocument
7: oContext = ThisApplication.TransientObjects.CreateTranslationContext
8: oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
9: oOptions = ThisApplication.TransientObjects.CreateNameValueMap
10: oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
11:
12: If oPDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
13: oOptions.Value("All_Color_AS_Black") = 0
14: oOptions.Value("Remove_Line_Weights") = 1
15: oOptions.Value("Vector_Resolution") = 400
16: oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
17: 'oOptions.Value("Custom_Begin_Sheet") = 2'oOptions.Value("Custom_End_Sheet") = 4
18: End If
19:
20:
21: 'get PDF target folder path
22: oFolder = "k:\dwg\pdf\"
23:
24:
25: 'Check for the PDF folder and create it if it does not exist
26: If Not System.IO.Directory.Exists(oFolder) Then
27: System.IO.Directory.CreateDirectory(oFolder)
28: End If
29:
30:
31: 'Set the PDF target file name
32: oDataMedium.FileName = oFolder & "\" & oFileName & _
33: " rev" & oRevNum & ".pdf"
34:
35:
36: 'Publish document
37: oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
38: '------end of iLogic-------