Export part document to 3d pdf with API in c#

Export part document to 3d pdf with API in c#

manasi_patilESZTV
Contributor Contributor
661 Views
2 Replies
Message 1 of 3

Export part document to 3d pdf with API in c#

manasi_patilESZTV
Contributor
Contributor

The error occurs at line 31 when attempting to export a part document to a 3D PDF using the API in C#.

 

public void Export3DPdf()
        {
            Inventor.Application InvApp = mApp;

            Inventor.ApplicationAddIn  PDFAddin = null ;

            foreach (ApplicationAddIn appAddin in mApp.ApplicationAddIns )
            {
                if (appAddin.ClassIdString == "{3EE52B28-D6E0-4EA4-8AA6-C2A266DEBB88}")
                {
                    PDFAddin =  appAddin;
                    break;
                }
            }

            dynamic pdfConvertor3d = PDFAddin.Automation;

            Document oDoc = mApp.ActiveDocument;
            // Create a NameValueMap object
            Inventor.NameValueMap oOptions = InvApp.TransientObjects.CreateNameValueMap();
            
            oOptions.Value["FileOutputLocation"] = @"c:\temp\3DPDF.pdf";
            oOptions.Value["ExportAllProperties"] = true;
            oOptions.Value["GenerateAndAttachSTEPFile"] = true ;
            oOptions.Value["ExportTemplate"] = @"C:\Users\Public\Documents\Autodesk\Inventor 2025\Templates\Sample Part Template.pdf";
            oOptions.Value["VisualizationQuality"] = AccuracyEnum.kHigh;

            String[] sDesignViews = new string[] { "Front", "Top" }; 
            oOptions.Value["ExportDesignViewRepresentations"] = sDesignViews;

            pdfConvertor3d.Publish(oDoc, oOptions);

        }

 

0 Likes
662 Views
2 Replies
Replies (2)
Message 2 of 3

earl_cody
Contributor
Contributor

Hi @manasi_patilESZTV,

 

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=ExportToPDF3D_Sample 

 

I was able to get a 3D PDF working by changing/verifying a few things with the NameValueMap. I have Inventor 2024.

 

The export template file path was slightly different from the one given in the example documentation where the template 3D PDF is further housed in the "en-US" folder (at least on my machine):

//oOptions.Value["ExportTemplate"] = @"C:\Users\Public\Documents\Autodesk\Inventor 2024\Templates\Sample Part Template.pdf";
oOptions.Value["ExportTemplate"] = @"C:\Users\Public\Documents\Autodesk\Inventor 2024\Templates\en-US\Sample Part Template.pdf";

 

I also removed the "Master" view name from the namevaluemap and just kept the "View1". I see that you changed those names in your code so you already know, but in case someone else is looking here:

//String[] sDesignViews = new string[] { "Master", "View1" };
String[] sDesignViews = new string[] { "View1" };

 

I also dialed down the dialed down the quality and turned off generating a STEP file. Maybe you'll experience this too, but during the program run, Inventor switched to the background for about a minute, and then came back in the taskbar (I watched in the Windows Task Manager). Maybe these tweaks will help with the issue happening on your end.

 

Best,

Cody

 

All together C#:

static void Export3DPdf()
{
    Inventor.Application InvApp = //

    Inventor.ApplicationAddIn PDFAddin = null;

    foreach (ApplicationAddIn appAddin in InvApp.ApplicationAddIns)
    {
        if (appAddin.ClassIdString == "{3EE52B28-D6E0-4EA4-8AA6-C2A266DEBB88}")
        {
            PDFAddin = appAddin;
            break;
        }
    }

    dynamic pdfConvertor3d = PDFAddin.Automation;

    Document oDoc = InvApp.ActiveDocument;

    // Create a NameValueMap object
    Inventor.NameValueMap oOptions = InvApp.TransientObjects.CreateNameValueMap();

    oOptions.Value["FileOutputLocation"] = @"c:\temp\3DPDF.pdf";
    oOptions.Value["ExportAllProperties"] = true;
    oOptions.Value["GenerateAndAttachSTEPFile"] = false;
    //oOptions.Value["ExportTemplate"] = @"C:\Users\Public\Documents\Autodesk\Inventor 2024\Templates\Sample Part Template.pdf";
    oOptions.Value["ExportTemplate"] = @"C:\Users\Public\Documents\Autodesk\Inventor 2024\Templates\en-US\Sample Part Template.pdf";
    oOptions.Value["VisualizationQuality"] = AccuracyEnum.kLow;

    //String[] sDesignViews = new string[] { "Master", "View1" };
    String[] sDesignViews = new string[] { "View1" };
    oOptions.Value["ExportDesignViewRepresentations"] = sDesignViews;

    pdfConvertor3d.Publish(oDoc, oOptions);
}

 

Screenshot 2024-04-24 152912.png 

0 Likes
Message 3 of 3

jmacapagal2CD9H
Contributor
Contributor
0 Likes