- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi.
I have an issue trying to export 3D PDF files in batch. When I go through all occurrences in an assembly trying to export all single components (parts and assemblies) to 3D PDF, the 3D PDF creation fails.
I think I also figured out why. It seems that a (to be exported) component must be opened visible to let the 3D PDF creation succeed. The problem is, I want the process to run invisible.
This is my code until now. I added notes what to (un)comment:
Sub Main
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
For Each oOcc As ComponentOccurrence In oCompDef.Occurrences
Dim oOccDoc As Document = oOcc.Definition.Document 'Comment for working code
' Dim oOccDoc As Document = ThisApplication.Documents.Open(oOcc.Definition.Document.FullFileName) 'Uncomment for working code
Export3DPDF(oOccDoc, "C:\TEMP", "Testfile", AccuracyEnum.kHigh)
' oOccDoc.Close 'Uncomment for working code
Next
End Sub
Sub Export3DPDF(ooModelDocument As Document, ooSaveFolder As String, ooFileName As String, ooAccuracy As AccuracyEnum, Optional ooTemplatePath As String = "") 'TEmplate optional???
'Get the 3D PDF Add-In.
Dim oPDFAddIn As ApplicationAddIn
Dim oAddin As ApplicationAddIn
For Each oAddin In ThisApplication.ApplicationAddIns
If oAddin.ClassIdString = "{3EE52B28-D6E0-4EA4-8AA6-C2A266DEBB88}" Then
oPDFAddIn = oAddin
Exit For
End If
Next
If oPDFAddIn Is Nothing Then
' MessageBox.Show("Inventor 3D PDF Addin not loaded.")
Exit Sub
End If
'Get PDF Converter
Dim oPDFConvertor3D
oPDFConvertor3D = oPDFAddIn.Automation
' Create a NameValueMap object as Options
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
Dim oSaveLocation As String = ooSaveFolder
If oSaveLocation.EndsWith("\") = False Then oSaveLocation = oSaveLocation & "\"
Dim oNewFileName As String = ooFileName & ".pdf"
Dim oFullPath As String = oSaveLocation & oNewFileName
' Options
oOptions.Value("FileOutputLocation") = oFullPath
oOptions.Value("ExportAnnotations") = 1
oOptions.Value("ExportWokFeatures") = 0
oOptions.Value("GenerateAndAttachSTEPFile") = False
oOptions.Value("VisualizationQuality") = ooAccuracy
oOptions.Value("ExportAllProperties") = True
oOptions.Value("ExportTemplate") = ooTemplatePath
oOptions.Value("LimitToEntitiesInDVRs") = True
oOptions.Value("ViewPDFWhenFinished") = False
' Set the design views to export
Dim oCompDef As ComponentDefinition = ooModelDocument.ComponentDefinition
Dim oRepsManager As RepresentationsManager = oCompDef.RepresentationsManager
Dim oDesignViewReps As DesignViewRepresentations = oRepsManager.DesignViewRepresentations
Dim oDesignViewRepsList(oDesignViewReps.Count) As String
Dim oCounter As Integer = 0
For Each oDesignView As DesignViewRepresentation In oDesignViewReps
oDesignViewRepsList(oCounter) = oDesignView.Name
oCounter += 1
Next
oOptions.Value("ExportDesignViewRepresentations") = oDesignViewRepsList
'Publish document.
oPDFConvertor3D.Publish(ooModelDocument, oOptions)
End Sub
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @NSmitsCE. I do not currently use 3D PDF's very often, and when I do, it is usually generated manually. However, after reviewing your code, I saw something that may need to be fixed. Near the end, where you are creating an array of strings to hold the DVR (DesignViewRepresentation) names, you are making the array too large by one. Remember, that array's are Zero based (not 1 based), but the DVR's collection is 1 based (not zero based), so when setting the size of the array, you should have specified DVR's.Count - 1, not just DVRs.Count. After that line, you are correctly starting the index at zero, which is correct, then filling in the names. But there will be one empty slot in the array, with no String value assigned to it, the way you currently have it. That may, or may not be causing the problems.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @WCrihfield, thanks for your response. The fact that you found that means that you read it well. Decrementing the count is indeed an improvement to be theoretically correct, but unfortunately does not solve the problem in this case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Just guessing at possible workarounds here, but maybe if each document really needs to be visibly opened for it to work, then maybe you could just avoid that process from changing your screen by setting the Application.ScreenUpdating property value to False just before that process begins (maybe before iterating the components), then set it back to True when it is done. It is very important to make sure it gets set back to True though, so you may want to use something like Try...Catch statement, where if something goes wrong in the Try portion, the Catch portion could be used to set it back. There are other similar settings like that too, but that one sounds like the most appropriate.
Also, I am just assuming that you do not have any of the components suppressed, and do not have more than one component referencing the same document? Because if you did have some suppressed, you would want to filter those out because accessing the ComponentOccurrence.Definition property of a suppressed component will cause an error. And if two or more components reference the same document, then it would try to process the same document multiple times, and may also be trying to overwrite an existing 3D PDF file.
And another little detail...at the end of the definition line of your 'Export3DPDF' Sub routine, you are setting the 'default' value of that optional String type variable with an empty string, using double quotes.
Optional ooTemplatePath As String = ""
I think that should be using vbNullString instead of """".
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @WCrihfield. Despite running on the background would still be my first choice, this is an acceptable alternative. That is a great idea, thanks.
Also thanks for the comment about the vbNullString, that is useful knowledge.