蒹葭苍苍,白露为霜。
所谓伊人,在水一方。

Autodesk inventor 将文档转为PDF的代码示例

下面这个示例演示了如何使用Inventor内置的PDF插件来将打开的模型或者工程图保存PDF文件。代码样本来自官方的帮助文件。增加包含了vb.net 和python的写法

代码样本

vba
Public Sub PublishPDF()
    ' 获取PDF翻译插件。
    Dim PDFAddIn As TranslatorAddIn
    Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    ' 设置一个引用到活动文档(要发布的文档)。
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' 创建一个NameValueMap对象
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' 创建一个DataMedium对象
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' 检查翻译器是否有'SaveCopyAs'选项
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        ' 绘图选项...
        oOptions.Value("All_Color_AS_Black") = 0

        ' 其他可选设置
        'oOptions.Value("Remove_Line_Weights") = 0
        'oOptions.Value("Vector_Resolution") = 400
        'oOptions.Value("Sheet_Range") = kPrintAllSheets
        'oOptions.Value("Custom_Begin_Sheet") = 2
        'oOptions.Value("Custom_End_Sheet") = 4
    End If

    ' 设置目标文件名
    oDataMedium.FileName = "c:\temp\test.pdf"

    ' 发布文档。
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
vb.net
Public Sub PublishPDF()
    ' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    ' Set a reference to the active document (the document to be published).
    Dim oDocument As Document = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
        ' Options for drawings...
        oOptions.Value("All_Color_AS_Black") = 0
    End If

    ' Set the destination file name
    oDataMedium.FileName = "c:\temp\test.pdf"

    ' Publish document.
    PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
python
def PublishPDF():
    # Get the PDF translator Add-In.
    PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    # Set a reference to the active document (the document to be published).
    oDocument = ThisApplication.ActiveDocument

    oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = 'kFileBrowseIOMechanism'

    # Create a NameValueMap object
    oOptions = ThisApplication.TransientObjects.CreateNameValueMap()

    # Create a DataMedium object
    oDataMedium = ThisApplication.TransientObjects.CreateDataMedium()

    # Check whether the translator has 'SaveCopyAs' options
    if PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions):
        # Options for drawings...
        oOptions.Value["All_Color_AS_Black"] = 0

    # Set the destination file name
    oDataMedium.FileName = "c:\\temp\\test.pdf"

    # Publish document.
    PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

# Call the function
PublishPDF()
赞(0) 打赏
未经允许不得转载:酷居科技 » Autodesk inventor 将文档转为PDF的代码示例

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

锦瑟无端五十弦,一弦一柱思华年

酷居科技联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏