<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: 3D PDF (batch) export fails in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529369#M163140</link>
    <description>&lt;P&gt;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&amp;nbsp;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=Application_ScreenUpdating" target="_blank" rel="noopener"&gt;Application.ScreenUpdating&lt;/A&gt;&amp;nbsp;property value to False just before that process begins (maybe before iterating the components), then set it back to True when it is done.&amp;nbsp; 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.&amp;nbsp; There are other similar settings like that too, but that one sounds like the most appropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&amp;nbsp; 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.&amp;nbsp; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Optional ooTemplatePath As String = ""&lt;/LI-CODE&gt;
&lt;P&gt;I think that should be using &lt;A href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.constants.vbnullstring?view=net-8.0" target="_blank" rel="noopener"&gt;vbNullString&lt;/A&gt; instead of """".&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/optional-parameters" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/optional-parameters&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 15:18:48 GMT</pubDate>
    <dc:creator>WCrihfield</dc:creator>
    <dc:date>2024-01-30T15:18:48Z</dc:date>
    <item>
      <title>3D PDF (batch) export fails</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12527636#M163115</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code until now. I added notes what to (un)comment:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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 &amp;amp; "\"
		Dim oNewFileName As String = ooFileName &amp;amp; ".pdf"
		Dim oFullPath As String = oSaveLocation &amp;amp; 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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 21:41:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12527636#M163115</guid>
      <dc:creator>NSmitsCE</dc:creator>
      <dc:date>2024-01-29T21:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: 3D PDF (batch) export fails</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529268#M163135</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14632782"&gt;@NSmitsCE&lt;/a&gt;.&amp;nbsp; I do not currently use 3D PDF's very often, and when I do, it is usually generated manually.&amp;nbsp; However, after reviewing your code, I saw something that may need to be fixed.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; After that line, you are correctly starting the index at zero, which is correct, then filling in the names.&amp;nbsp; But there will be one empty slot in the array, with no String value assigned to it, the way you currently have it.&amp;nbsp; That may, or may not be causing the problems.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 14:38:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529268#M163135</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-01-30T14:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: 3D PDF (batch) export fails</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529294#M163136</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;,&amp;nbsp;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&lt;SPAN&gt;&amp;nbsp;does not solve the problem in this case.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 14:48:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529294#M163136</guid>
      <dc:creator>NSmitsCE</dc:creator>
      <dc:date>2024-01-30T14:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: 3D PDF (batch) export fails</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529369#M163140</link>
      <description>&lt;P&gt;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&amp;nbsp;&lt;A href="https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=Application_ScreenUpdating" target="_blank" rel="noopener"&gt;Application.ScreenUpdating&lt;/A&gt;&amp;nbsp;property value to False just before that process begins (maybe before iterating the components), then set it back to True when it is done.&amp;nbsp; 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.&amp;nbsp; There are other similar settings like that too, but that one sounds like the most appropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&amp;nbsp; 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.&amp;nbsp; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Optional ooTemplatePath As String = ""&lt;/LI-CODE&gt;
&lt;P&gt;I think that should be using &lt;A href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.constants.vbnullstring?view=net-8.0" target="_blank" rel="noopener"&gt;vbNullString&lt;/A&gt; instead of """".&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/optional-parameters" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/optional-parameters&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 15:18:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529369#M163140</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2024-01-30T15:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: 3D PDF (batch) export fails</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529447#M163143</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;. Despite running on the background would still be my first choice, this is an acceptable alternative.&amp;nbsp;That is a great idea, thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also thanks for the comment about the vbNullString, that is useful knowledge.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 15:41:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/3d-pdf-batch-export-fails/m-p/12529447#M163143</guid>
      <dc:creator>NSmitsCE</dc:creator>
      <dc:date>2024-01-30T15:41:13Z</dc:date>
    </item>
  </channel>
</rss>

