Message 1 of 1
Sketch export failed to initialize translator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Got quite a long one here, but I have an addon I have compiled in Visual Studio, and both of the following scripts work great, unless "PrintUpdate" is run before "dxfUpdate".
Here is a link to the GitHub page if you want to test the addon yourself: Release v1.4.6.0 · Bmassner/Doyle-AddIn · GitHub
"PrintUpdate" obviously only runs on .idw
After running "PrintUpdate" and I switch back to a sheet metal part I get the "Sketch export failed to initialize translator" error as well as this in VS:
System.Runtime.InteropServices.COMException
HResult=0x80004005
Message=Class not registered
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Object[] aArgs, Boolean[] aArgsIsByRef, Int32[] aArgsWrapperTypes, Type[] aArgsTypes, Type retType)
at Inventor.DataIO.WriteDataToFile(String Format, String FileName)
at Doyle_Addin.dxfUpdate.runDxfUpdate(Application ThisApplication) in C:\Users\Test2\dxfUpdate.vb:line 103
I have to restart inventor to reenable the translator.
Imports Inventor
Module dxfUpdate
Sub runDxfUpdate(ThisApplication As Inventor.Application)
Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
Dim oFactory As iPartFactory = oDef.iPartFactory
Dim oRow As iPartTableRow
'Check if part is a factory
If oDef.IsiPartFactory = True Then
'Go through all rows
For Each oRow In oFactory.TableRows
oFactory.DefaultRow = oRow
Dim partMaterial As String = oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Material").Value.ToString
MsgBox(partMaterial)
Dim partAppearance As String = oPartDoc.ActiveAppearance.Name.ToString
MsgBox(partAppearance)
If oDef.FlatPattern.FlatBendResults.Count = 0 And (oDef.FlatPattern.RangeBox.MaxPoint.Z - oDef.FlatPattern.RangeBox.MinPoint.Z) > (oDef.Thickness.Value + 0.003) Then
MsgBox("Invalid")
Else
MsgBox("Valid")
End If
'Get part number
Dim PN As String = oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value.ToString
'Set data write output format
Dim oFormat As String = "FLAT PATTERN DXF?AcadVersion=2018" _
+ "&BendDownLayer=DOWN&BendDownLayerColor=255;0;0" _
+ "&BendUpLayer=UP&BendUpLayerColor=255;0;0" _
+ "&OuterProfileLayer=OUTER&OuterProfileLayerColor=0;0;255" _
+ "&InteriorProfilesLayer=INNER&InteriorProfilesLayerColor=0;0;0" _
+ "&ArcCentersLayer=POINT&ArcCentersLayerColor=255;0;255" _
+ "&TangentLayer=RADIUS&TangentLayerColor=255;255;0"
'Set output path
Dim oFileName As String = "X:\" & PN & ".dxf"
'Make a flat pattern if one doesn't exist and refold
If oDef.HasFlatPattern = False Then
Try
oDef.Unfold()
oDef.FlatPattern.ExitEdit()
Catch ex As Exception
MsgBox("Failed to create flat pattern")
Return
End Try
End If
'Create dxf
Try
oDef.DataIO.WriteDataToFile(oFormat, oFileName)
Catch ex As Exception
MsgBox("DXF failed to generate")
Return
End Try
Next
'Reset to first member
oRow = oFactory.TableRows.Item(1)
oFactory.DefaultRow = oRow
Dim Total As Integer = oFactory.TableRows.Count
MsgBox("Created " & Total)
Else
'All same as above, for non-iparts
Dim PN As String = oPartDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value.ToString
Dim oFormat As String = "FLAT PATTERN DXF?AcadVersion=2018" _
+ "&BendDownLayer=DOWN&BendDownLayerColor=255;0;0" _
+ "&BendUpLayer=UP&BendUpLayerColor=255;0;0" _
+ "&OuterProfileLayer=OUTER&OuterProfileLayerColor=0;0;255" _
+ "&InteriorProfilesLayer=INNER&InteriorProfilesLayerColor=0;0;0" _
+ "&ArcCentersLayer=POINT&ArcCentersLayerColor=255;0;255" _
+ "&TangentLayer=RADIUS&TangentLayerColor=255;255;0"
Dim oFileName As String = "X:\" & PN & ".dxf"
If oDef.HasFlatPattern = False Then
oDef.Unfold()
oDef.FlatPattern.ExitEdit()
End If
Try
oDef.DataIO.WriteDataToFile(oFormat, oFileName)
Catch ex As Exception
MsgBox("Check to see if you are connected to the X Drive and try again")
Return
End Try
End If
End Sub
End Module
Imports Inventor
Module PrintUpdate
Public Sub RunPrintUpdate(ThisApplication As Inventor.Application)
' Check if current document is a drawing, show error if not
If ThisApplication.ActiveDocument.DocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("ONLY FOR USE IN DRAWING DOCUMENTS", "Ilogic")
Return
End If
' Set reference to active document
Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
' Get referenced model document type (part or assembly)
Dim refDocType As Inventor.DocumentTypeEnum = oDDoc.ReferencedDocuments(1).DocumentType
Dim oFilePath As String = "P:\"
Dim FileName As String
Dim PN As String = oDDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value.ToString
Dim DocName As String = oDDoc.DisplayName
' Check if document name matches part number
If DocName <> (PN & ".idw") Then
MsgBox("DOCUMENT NAME IS DIFFERENT FROM PART NUMBER")
Return
End If
' Count sheets
Dim SheetCount As Integer = oDDoc.Sheets.Count
' Always export PDF
If String.IsNullOrEmpty(oFilePath) Then
MsgBox("This file has not yet been saved and doesn't exist on disk!" & vbCrLf & "Please save it first", 64, "Formsprag iLogic")
Return
End If
FileName = PN & ".pdf"
Dim pdfPath As String = oFilePath & "\" & FileName
Dim oPDFAddin As Inventor.TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oDocument As Inventor.Document = ThisApplication.ActiveDocument
Dim oContext As Inventor.TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim oDataMedium As Inventor.DataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Set PDF options
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 4800
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
' Set PDF target file name
oDataMedium.FileName = pdfPath
Try
' Publish document
oPDFAddin.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
ExportFirstPageAsImage(pdfPath, oFilePath & "\" & PN & ".jpg")
Catch
MsgBox("Failed to Export PDF (Someone might have this file open)", MsgBoxStyle.OkOnly)
Return
Finally
If oContext IsNot Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(oContext)
If oOptions IsNot Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(oOptions)
If oDataMedium IsNot Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(oDataMedium)
' Do NOT release oPDFAddin
End Try
' If referenced document is a part, convert PDF to JPG and then delete the PDF
If refDocType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
Try
ExportFirstPageAsImage(pdfPath, oFilePath & "\" & PN & ".jpg")
' Delete the PDF after conversion
If IO.File.Exists(pdfPath) Then
IO.File.Delete(pdfPath)
End If
Catch ex As Exception
MsgBox("Failed to convert PDF to JPG: " & ex.Message, MsgBoxStyle.OkOnly)
End Try
End If
End Sub
End Module