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

Autodesk Inventor 工程图一键导出为PDF(示例代码)

最近有导出PDF图纸的需求,于是翻了下API文档,原来文档是vba的,下面的代码稍作修改适配了VB.net。适合一键导出pdf到当前文档所在地址。仅供参考。如果需要批量导出,则需要另外增加一些代码。

    Public Sub PublishPDF()
        ' Get the PDF translator Add-In.
        Dim PDFAddIn As TranslatorAddIn
        PDFAddIn = g_inventorApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

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

        Dim oContext As TranslationContext
        oContext = g_inventorApplication.TransientObjects.CreateTranslationContext
        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

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

        ' Create a DataMedium object
        Dim oDataMedium As DataMedium
        oDataMedium = g_inventorApplication.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

            '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

        'Set the destination file name
        oDataMedium.FileName = Microsoft.VisualBasic.Left(oDocument.FullFileName, Len(oDocument.FullFileName) - 4) & ".pdf"

        'Publish document.
        Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
    End Sub
赞(3) 打赏
未经允许不得转载:酷居科技 » Autodesk Inventor 工程图一键导出为PDF(示例代码)

评论 抢沙发

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

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

酷居科技联系我们

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

支付宝扫一扫打赏

微信扫一扫打赏