STP Translator functionality different to DXF & PDF?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to set up iLogic functions to export from a drawing to STP, DXF, DWG (AutoCAD) & PDF.
The STP code works well & it allows me to create a new sub-folder, to the folder automatically loaded using the code below:
Imports System.Windows.Forms
'
Dim dialog = New FolderBrowserDialog()
dialog.SelectedPath = ExportPath
If dialog.ShowDialog() = DialogResult.OK Then
'sub called here
End If
Here's the full code for the STP export:
Imports System.Windows.Forms
Public Sub Main
Dim drawingDoc As Inventor.DrawingDocument = ThisDoc.Document
Dim strSaveAsSuff As String = " Rev " & iProperties.Value("Custom", "c_Revision_Nº")
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path
' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
MsgBox("This file has not yet been saved and doesn't exist on disk!")
Return
End If
' Browse for location to save file
Dim dialog = New FolderBrowserDialog()
dialog.SelectedPath = ExportPath
If dialog.ShowDialog() = DialogResult.OK Then
For Each sht As Sheet In drawingDoc.Sheets
Dim oView As DrawingView = sht.DrawingViews.Item(1)
' export part if part, export assembly if assembly
Dim refDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
If refDoc.DocumentType = kPartDocumentObject Then
'ExportToStepFile(refDoc, dialog.SelectedPath)
ExportToStepFile(refDoc, dialog.SelectedPath, strSaveAsSuff)
Else If refDoc.DocumentType = kAssemblyDocumentObject Then
'ExportToStepFile(refDoc, dialog.SelectedPath)
ExportToStepFile(refDoc, dialog.SelectedPath, strSaveAsSuff)
End If
Next 'sheet
End If
End Sub
Public Sub ExportToStepFile(docToExport As Document, selectedFolderPath As String, selectedSuffix as String)
' Get the STEP translator Add-In.
Dim stepTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim translatorContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim translatorOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim newFilename as string = doctoexport.displayname.replace(".ipt","").replace(".iam","")
Dim expPATH as string = selectedFolderPath & "\STP"
newfilename = newfilename & selectedsuffix
if doctoexport.documenttype = kassemblydocumentobject then newfilename = newfilename &".iam" else newfilename = newfilename & ".ipt"
If stepTranslator.HasSaveCopyAsOptions(docToExport, translatorContext, translatorOptions) Then
translatorOptions.Value("ApplicationProtocolType") = 3
translatorContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim translatorData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
translatorData.FileName = expPATH & "\" & System.IO.Path.ChangeExtension(newFilename, ".stp")
stepTranslator.SaveCopyAs(docToExport, translatorContext, translatorOptions, translatorData)
End If
End Sub
Trying to replicate the STP code for DXF or PDF results in an error, seemingly with the syntax in line 59 of the STP code.
translatorData.FileName = expPATH & "\" & System.IO.Path.ChangeExtension(newFilename, ".stp")
The original code that I found on this forum was:
translatorData.FileName = selectedFolderPath & "\" & System.IO.Path.ChangeExtension(docToExport.DisplayName, ".stp")
Ignoring the differences in the final set of (....), which I don't think have any bearing on the issue, the issue seems to be with "expPATH" vs "selectedFolderPath".
As can be seen in the STP code (line 48), I've created "expPATH" to append the desired folder to that returned on line
9, "Dim ExportPath As String = ThisDoc.Path".
See also line 19, "dialog.SelectedPath = ExportPath".
When I run the DXF code below using "expPATH" - (line 41), it fails with Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).
When I run the DXF code below using "selectedFolderPath" - (line 42), it works.
DXF Export code:
Imports System.Windows.Forms
Public Sub Main
Dim drawingDoc As Inventor.DrawingDocument = ThisDoc.Document
' Get current location of this file
Dim ExportPath As String = ThisDoc.Path
' Check that this file has been saved and actually exists on disk
If String.IsNullOrEmpty(ExportPath) Then
MsgBox("This file has not yet been saved and doesn't exist on disk!")
Return
End If
' Browse for location to save file
Dim dialog = New FolderBrowserDialog()
dialog.SelectedPath = ExportPath
If dialog.ShowDialog() = DialogResult.OK Then
For Each sht As Sheet In drawingDoc.Sheets
ExportToDXF(drawingDoc, dialog.SelectedPath)
Next 'sheet
End If
End Sub
Public Sub ExportToDXF(docToExport As Document, selectedFolderPath As String)
' Get the STEP translator Add-In.
Dim dxfTranslator As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
Dim translatorContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim translatorOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim expPATH as string = selectedFolderPath & "\DXF"
If dxfTranslator.HasSaveCopyAsOptions(docToExport, translatorContext, translatorOptions) Then
strIniFile = "\\ARKBUILDSERVWSE\Shared Folders\ARK CAD\Customisation\Inventor\Configuration\ARKexportdxf.ini"
translatorOptions.Value("Export_Acad_IniFile") = strIniFile
translatorContext.Type = kFileBrowseIOMechanism
Dim translatorData As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
'translatorData.FileName = expPATH & "\" & System.IO.Path.ChangeExtension(docToExport.DisplayName, ".dxf")
translatorData.FileName = selectedFolderPath & "\" & System.IO.Path.ChangeExtension(docToExport.DisplayName, ".dxf")
dxfTranslator.SaveCopyAs(docToExport, translatorContext, translatorOptions, translatorData)
End If
End Sub
I have the same problem with PDF export.
I appreciate that the STP code is working with model files via drawing views, but I can't see how this would affect the function.
Is this something to do with the way the translators work, or have I missed something else?