Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic fail

13 REPLIES 13
Reply
Message 1 of 14
julesgf
3093 Views, 13 Replies

iLogic fail

Hi All

 

I have a bit of iLogic I use to export PDFs from IDWs with meaningful file names, this is working in 2017 but not 2018. Throws this error Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))

 

I cant find the problem, partially because I don't understand what the error is alluding to and partially because the API sample is so out of date that it uses the depreciated "SET" http://help.autodesk.com/view/INVNTOR/2018/ENU/?guid=GUID-CD4C38D2-FD05-4A2F-9FA7-C5EC5F845753

 

Any help would be greatly appreciated.

 

SyntaxEditor Code Snippet

'------start Of iLogic-------

'trigger rule For testing
trigger = iTrigger0

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim sSheetNumber As String
Dim sSheetDwgPrefix As String
Dim sDrawTitle As String
Dim iPageNumber As Integer
Dim exportScope As Integer

exportScope = InputBox("Enter sheet# to export (0 for all, high# to cancel)", "iLogic Length", 0)

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet number
iPageNumber = Right(oSheet.Name, sLen -lPos)

'find the sheet name'find the sheet number
oTitleBlock=oSheet.TitleBlock
oTextBoxes=oTitleBlock.Definition.Sketch.TextBoxes
For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
    Select oTextBox.Text
        Case "<Drawing Title>":
            sSheetName = oTitleBlock.GetResultText(oTextBox)
        Case "<Dwg Number>":
            sSheetNumber = oTitleBlock.GetResultText(oTextBox)
        Case "<Drawing Prefix>":
            sSheetDwgPrefix = oTitleBlock.GetResultText(oTextBox)
    End Select
Next

'find the sheet revision
oRevTable = oSheet.RevisionTables.Item(1)
'Iterate through the contents of the revision table.
Dim i As Long
i = oRevTable.RevisionTableRows.Count
' Get the current row.
Dim oRow As RevisionTableRow
oRow = oRevTable.RevisionTableRows.Item(i)

' Iterate through each column in the row.
Dim j As Long
j = 1
Dim oCell As RevisionTableCell
oCell = oRow.Item(j)
Dim sSheetRev As String
sSheetRev = oCell.Text

'set PDF Options
If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_End_Sheet") = iPageNumber
oOptions.Value("Custom_End_Sheet") = iPageNumber
End If

'get PDF target folder path
oFolder = oPath & "\PDF"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & sSheetDwgPrefix & sSheetNumber & " Rev." & sSheetRev & " " & sSheetName & ".pdf"

'Publish document
If exportScope = iPageNumber Or exportScope = 0  Then
    oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

Next
'------end of iLogic-------

 

Tags (1)
13 REPLIES 13
Message 2 of 14
julesgf
in reply to: julesgf

This is probably behind the problem. The Whats New for 2018 includes PDF export changes "The From and To values specified for Sheets in range are no longer session based." So somethings changes in the export add in?

 

Cheers

JF

Message 3 of 14
FProcp
in reply to: julesgf

Was there a solution for this?

I am getting the same error.

Franco
GMT +08:00
Message 4 of 14
julesgf
in reply to: FProcp

Yes I did fix it by removing the "If oPDFAddIn.HasSaveCopyAsOptions(
oDataMedium, oContext, oOptions) Then" and obviously the closing of the If
from this section.

'set PDF OptionsIf oPDFAddIn.HasSaveCopyAsOptions(oDataMedium,
oContext, oOptions) ThenoOptions.Value("All_Color_AS_Black") =
0oOptions.Value("Remove_Line_Weights") =
0oOptions.Value("Vector_Resolution") =
400oOptions.Value("Sheet_Range") =
Inventor.PrintRangeEnum.kPrintSheetRangeoOptions.Value("Custom_Begin_Sheet")
= iPageNumberoOptions.Value("Custom_End_Sheet") = iPageNumberEnd If



0400 223 518
Two Feathers
22 The Boulevard, Ivanhoe, Victoria, 3079
www.twofeathers.com.au
Message 5 of 14
FProcp
in reply to: julesgf

I think this is what you meant?

 

 

 

SyntaxEditor Code Snippet

'------start of iLogic-------
' If the drawing is not at Status "Released", the Title Block layer will NOT appear on pdf
' Title block must be in that layer for this to work
If iProperties.Value("Status", "Design State") <> 3 Then
  ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= False
Else
 ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= True
End If
'
oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oRevNum = iProperties.Value("Project", "Revision Number")
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
oOptions.Value("Sheet_Range") =
Inventor.PrintRangeEnum.kPrintSheetRange
'oOptions.Value("Custom_Begin_Sheet")= iPageNumber
'oOptions.Value("Custom_End_Sheet") = iPageNumber
'End If

'get PDF target folder path
oFolder = Left(oPath, InStrRev(oPath, "\")) & "PDF"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & oFileName & _
" Rev" & oRevNum & ".pdf"

'Publish document
oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
'
ThisDrawing.Document.StylesManager.Layers("Title (ISO)").Visible= True
InventorVb.DocumentUpdate()
'------end of iLogic-------
Franco
GMT +08:00
Message 6 of 14
julesgf
in reply to: FProcp

Mine is now like this

Note the "set PDF options" section

 

SyntaxEditor Code Snippet

'------start Of iLogic-------

'trigger rule For testing
trigger = iTrigger0

oPath = ThisDoc.Path
oFileName = ThisDoc.FileName(False) 'without extension
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById _
("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

'Define the drawing
Dim oDrawing As DrawingDocument
oDrawing = ThisDoc.Document

Dim oSheet As Sheet
Dim lPos As Long
Dim rPos As Long
Dim sLen As Long
Dim sSheetName As String
Dim sSheetNumber As String
Dim sSheetDwgPrefix As String
Dim sDrawTitle As String
Dim iPageNumber As Integer
Dim exportScope As Integer

exportScope = InputBox("Enter sheet# to export (0 for all, high# to cancel)", "iLogic Length", 0)

'step through each drawing sheet
For Each oSheet In oDrawing.Sheets

'find the seperator in the sheet name:number
lPos = InStr(oSheet.Name, ":")
'find the number of characters in the sheet name
sLen = Len(oSheet.Name)
'find the sheet number
iPageNumber = Right(oSheet.Name, sLen -lPos)

'find the sheet name'find the sheet number
oTitleBlock=oSheet.TitleBlock
oTextBoxes=oTitleBlock.Definition.Sketch.TextBoxes
For Each oTextBox In oTitleBlock.Definition.Sketch.TextBoxes
    Select oTextBox.Text
        Case "<Drawing Title>":
            sSheetName = oTitleBlock.GetResultText(oTextBox)
        Case "<Dwg Number>":
            sSheetNumber = oTitleBlock.GetResultText(oTextBox)
        Case "<Drawing Prefix>":
            sSheetDwgPrefix = oTitleBlock.GetResultText(oTextBox)
    End Select
Next

'find the sheet revision
oRevTable = oSheet.RevisionTables.Item(1)
'Iterate through the contents of the revision table.
Dim i As Long
i = oRevTable.RevisionTableRows.Count
' Get the current row.
Dim oRow As RevisionTableRow
oRow = oRevTable.RevisionTableRows.Item(i)

' Iterate through each column in the row.
Dim j As Long
j = 1
Dim oCell As RevisionTableCell
oCell = oRow.Item(j)
Dim sSheetRev As String
sSheetRev = oCell.Text

'set PDF Options
oOptions.Value("All_Color_AS_Black") = 0
oOptions.Value("Remove_Line_Weights") = 0
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintSheetRange
oOptions.Value("Custom_Begin_Sheet") = iPageNumber
oOptions.Value("Custom_End_Sheet") = iPageNumber

'get PDF target folder path
oFolder = oPath & "\PDF"

'Check for the PDF folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
    System.IO.Directory.CreateDirectory(oFolder)
End If

'Set the PDF target file name
oDataMedium.FileName = oFolder & "\" & sSheetDwgPrefix & sSheetNumber & " Rev." & sSheetRev & " " & sSheetName & ".pdf"

'Publish document
If exportScope = iPageNumber Or exportScope = 0  Then
    oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End If

Next
'------end of iLogic-------
Message 7 of 14
Anonymous
in reply to: julesgf

Thank you for this thread, all my pdf creation macros were failing this way after the update and this fixed everything. Cheers.

Message 8 of 14
Anonymous
in reply to: julesgf

Hello to all -

 

I am in the same boat, moved from 2017 to 2018 and iLogic is not working correctly.

 

I get this ERROR MESSAGE when trying to run the below iLogic:

 

Error in rule: Drawing - Save PDF - Print Option 07-05-17, in document: 803-00205.idw

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

Would greatly appreciate it if someone could point out the problem, I am a bit lost right now. Thank you.

 

 

 

 

'this rule outputs all drawing sheets to PDF
'this rule outputs all drawing sheets to DWF, 3D models of first sheet included
Public Sub Main()
    
    
    'Ask to print file
    printerName = "\\JLF-PRINT01\Canon Meadow Lighting_Dept PS3"
    askprint = MessageBox.Show("Print to " & printerName & "?", "Print",MessageBoxButtons.YesNoCancel)
    If askprint = vbYes
        Dim oDrawDoc As Document
        oDrawDoc = ThisApplication.ActiveDocument
        
        Dim oPrintMgr As PrintManager
        oPrintMgr = oDrawDoc.PrintManager
        'specify your printer name
                            '\\JLF-PRINT01\Canon Meadow Lighting_Dept PS3
        oPrintMgr.Printer = printerName
        oPrintMgr.PrintRange = Inventor.PrintRangeEnum.kPrintAllSheets
        oPrintMgr.ColorMode = PrintColorModeEnum.kPrintGrayScale
        oPrintMgr.AllColorsAsBlack = False
        oPrintMgr.Orientation = PrintOrientationEnum.kPortraitOrientation
        oPrintMgr.PaperSize = SizeActiveSheet
        oPrintMgr.SubmitPrint
    Else If askprint = vbCancel
        Goto ErrorHandle
    End If
    
    'Set-Up declarations for DPF and DWF add-ins
    PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
    DWFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
        oDocument = ThisApplication.ActiveDocument
        oContext = ThisApplication.TransientObjects.CreateTranslationContext
        oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
        PDFOptions = ThisApplication.TransientObjects.CreateNameValueMap
        DWFOptions = ThisApplication.TransientObjects.CreateNameValueMap
        PDFOptions = ThisApplication.TransientObjects.CreateDataMedium
        DWFOptions = ThisApplication.TransientObjects.CreateDataMedium
        
        'Define the save path
        Dim fileName As String
        
        filename = ThisDoc.FileName(True)
        
        Prefix = Left(fileName, 3) 'First 3 characters i.e. "803"
        
        FirstSpace = InStr(1, fileName, " ") 'Gets location in strine of the first space
        
        If Not FirstSpace = 0
            PartNumber = Left(fileName, FirstSpace-1) 'Assign everything left of the space to part number
            
        Else 'There is no space
            dot = InStr(1, fileName, ".") 'Gets the location in string of the first "."
        
            PartNumber = Left(fileName, dot-1) 'Assign everything left of the "." to part number    
        End If
    
    'PartNumber = Left(fileName, 9) 'Full Part number i.e. "803-00044"
    'last5 = Right(DNumber, 5) 'Last 5 characters i.e. "00044"

    'Image Library folder names have additional descriptors...
    If Left(Prefix, 3) = "801"
        folderDescription = "Table Lamps"
    Else If Left(Prefix, 3) = "802"
        folderDescription = "Floor Lamps"
    Else If Left(Prefix, 3) = "803"
        folderDescription = "Wall Lamps"
    Else If Left(Prefix, 3) = "804"
        folderDescription = "Ceiling Lamps"
    Else If Left(Prefix, 3) = "809"
        folderDescription = "Shades"
    End If

    PDF_Path = "I:\" & Prefix & " - " & folderDescription & "\PDF"
    DWF_Path = "I:\" & Prefix & " - " & folderDescription & "\DWF"
        
    'Create PDF file
    PDF_File_Name = PartNumber & "-" & iProperties.Value("Project", "Project") & ".pdf"
    'Debug line to show PDF save path
    'MessageBox.Show(PDF_PATH, "PDF Save Path")
    
    If PDFAddIn.HasSaveCopyAsOptions(PDFDataMedium, oContext, PDFOptions) Then
        PDFOptions.Value("All_Color_AS_Black") = 0
        PDFOptions.Value("Remove_Line_Weights") = 0
        PDFOptions.Value("Vector_Resolution") = 4800
        PDFOptions.Value("Gradient_Resolution") = 4800
        PDFOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
        'PDFOptions.Value("Custom_Begin_Sheet") = 2
        'PDFOptions.Value("Custom_End_Sheet") = 4
    End If

    'Set the PDF target file name
    'Shop Drawing
    If ActiveSheet.TitleBlock = "MEADOW SHOP TITLE BLOCK"
        Cloc = InStr(1, fileName, "C") 'Gets location in string of the "C"
        If Cloc = 0
            MFG_Folder = PartNumber & "-C" 'Add "-C" to PartNumber
            PDF_File_Name = ThisDoc.FileName(False) & ".pdf"
        Else
            MFG_Folder = Left(PartNumber, Cloc) 'Crop the end of Shop Drawing Part Number to the "C"
            PDF_File_Name = PartNumber & ".pdf"
        End If
        Shop_PDF_Path = PDF_Path & "\MFG DRAWINGS\" & MFG_Folder
        PDFDataMedium.FileName = Shop_PDF_Path & "\" & PDF_File_Name
        'MessageBox.Show(Shop_PDF_PATH, "PDF Save Path")
    Else
        'MessageBox.Show(PDF_PATH, "PDF Save Path")
        PDFDataMedium.FileName = PDF_Path & "\" & PDF_File_Name
    End If
    
    'Publish PDF document
    Try
        PDFAddIn.SaveCopyAs(oDocument, oContext, PDFOptions, PDFDataMedium)
    Catch
        MessageBox.Show("Error - PDF may be open in another viewer, or destination folder does not exist.", "Problem saving PDF to P", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    
    If ActiveSheet.TitleBlock = "MEADOW SALES TITLE BLOCK" 'Sales Drawing
        'Publish copy with Rev info in Project Directory
        copy_Path = ThisDoc.Path & "/" & PartNumber & " DOCS"
        copy_FileName = PartNumber & "-" & iProperties.Value("Project", "Project") & " Rev " & iProperties.Value("Project", "Revision Number") & ".pdf"
        PDFDataMedium.FileName = copy_Path & "\" & copy_FileName
        PDFAddIn.SaveCopyAs(oDocument, oContext, PDFOptions, PDFDataMedium)
        
        'Create DWF file
        
        'Store and delete Project, Side Mark, & Quantity
        storeProject = iProperties.Value("Project", "Project")
        storeSideMark = iProperties.Value("Custom", "SIDEMARK")
        storeQuantity = iProperties.Value("Custom", "QUANTITY")
        iProperties.Value("Project", "Project") = ""
        iProperties.Value("Custom", "SIDEMARK") = ""
        iProperties.Value("Custom", "QUANTITY") = ""
        InventorVb.DocumentUpdate()
        
        DWF_File_Name = PartNumber & ".dwf"
        
        'Debug line to show DWF save path
        'MessageBox.Show(DWF_PATH, "DWF Save Path"
        
        'askview = MessageBox.Show("Launch the DWF Viewer now?", "Launch DWF Viewer",MessageBoxButtons.YesNo)
        'If askview = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End IF
        launchviewer = 0
        
        If DWFAddIn.HasSaveACopyAsOptions(DWFDataMedium, oContext, DWFOptions)Then    
                DWFOptions.Value("Launch_Viewer") = launchviewer
                DWFOptions.Value("Publish_All_Component_Props") = 1
                DWFOptions.Value("Publish_All_Physical_Props") = 1
                DWFOptions.Value("Password") = 0
                DWFOptions.Value("Publish_3D_Models") = Publish_3D_Models
            
                If TypeOf oDocument Is DrawingDocument Then
                    Dim oSheets As NameValueMap
                    oSheets = ThisApplication.TransientObjects.CreateNameValueMap
                    DWFOptions.Value("Publish_Mode") = DWFPublishModeEnum.kCompleteDWFPublish
                    DWFOptions.Value("Publish_All_Sheets") = 1
                    'Publish the first sheet AND its 3D model
                    Dim oSheet1Options As NameValueMap
                    oSheet1Options = ThisApplication.TransientObjects.CreateNameValueMap
                    oSheet1Options.Add("Name", "Sheet:1")
                    oSheet1Options.Add("3DModel", True)
                    oSheets.Value("Sheet1") = oSheetOptions
            End If
        End If
        
        DWFDataMedium.FileName = DWF_PATH & "\" & DWF_File_Name
        
        Try
            Call DWFAddin.SaveCopyAs(oDocument, oContext, DWFOptions, DWFDataMedium)
        Catch
            MessageBox.Show("Error - DWF may be open in another viewer, or destination folder does not exist.", "Problem saving to DWF to P",
        MessageBoxButtons.OK, MessageBoxIcon.Error)
            'Restore Project, Side Mark, Quantity fields
            iProperties.Value("Project", "Project") = storeProject
            iProperties.Value("Custom", "SIDE MARK") = storeSideMark
            iProperties.Value("Custom", "QUANTITY") = storeQuantity
            InventorVb.DocumentUpdate()
        End Try
            
        If launchviewer = 1 Then ThisDoc.Launch(DWF_PATH & "\" & DWF_File_Name)
            
        'Export copy to project directory
        copy_Path = ThisDoc.Path & "\" & PartNumber & " DOCS"
        copy_FileName = PartNumber & " REV " & iProperties.Value("Project", "Revision Number") & ".dwf"
        DWFOptions.Value("Launch_Viewer") = 0 'Dont launch viewer for the copy
        DWFDataMedium.FileName = copy_Path & "\" & copy_FileName
        Call DWFAddIn.SaveCopyAs(oDocument, oContext, DWFOptions, DWFDataMedium)
            
        'Restore Project, Side Mark, Quantity Fields
        iProperties.Value("Project", "Project") = storeProject
        iProperties.Value("Custom", "SIDE MARK") = storeSideMark
        iProperties.Value("Custom", "QUANTITY") = storeQuantity
        InventorVb.DocumentUpdate()
            
        ErrorHandle:
        If OldDrawing = 1
            MessageBox.Show("Unable to remove Project information - old Title Block format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End If
    End If
End Sub

Message 9 of 14
FProcp
in reply to: Anonymous

I got something working.

It is described in the following discussion:

 

iLogic, save all .idw sheets to PDF

 

 

Franco
GMT +08:00
Message 10 of 14
MattH_Work
in reply to: julesgf

I appreciate I'm answering an old post, but this may be helpful to others...

 

It seems that in 2017 the following line is correct
???= ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

 

But by the time we get to 2020 (changed around 2018 I believe) it should be
???= ThisApplication.ApplicationAddIns.ItemById("{0AC6FD95-2F4D-42CE-8BE0-8AEA580399E4}")

 

Notice the chgange from 6 to 5 in the first block of numbers


MattH
Product Design Collection 2025
Vault Pro 2025
Message 11 of 14
WCrihfield
in reply to: MattH_Work

Also, just to help other out.  Instead of specifying the AddIn by ID, which is not only complicated, but also changes with time, try looping through the AddIns by DisplayName.  Its much easier to read and understand, and continues to work year after year.  For instance:

Dim oPDF_AddIn As TranslatorAddIn
For Each oTransAddIn As TranslatorAddIn In ThisApplication.ApplicationAddIns
	If oTransAddIn.DisplayName = "Translator: PDF" Then
		oPDF_AddIn = oTransAddIn
	End If
Next

Sure its a tiny bit more code, and a tiny bit more processing, but its worth it.

Wesley Crihfield

EESignature

Message 12 of 14
niki
in reply to: WCrihfield

I'm getting an error from specifying AddIn by DisplayName in my Inventor 2022.1.1

 

Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.TranslatorAddIn'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{6ECCBC87-A50D-11D4-8DE4-0010B541CAA8}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Best regards

Niki
Message 13 of 14
WCrihfield
in reply to: niki

Hi @niki.

Apparently I had my wires crossed when I posted that bit of code.  I had several versions of it at the time, and many were a little different from each other.  It should have been formatted like this:

 

Dim oPDF As TranslatorAddIn
For Each oAppAddin As ApplicationAddIn In ThisApplication.ApplicationAddIns
	If oAppAddin.DisplayName = "Translator: PDF" Then
		oPDF = oAppAddin
	End If
Next

 

Because a TranslatorAddIn is a type of (and derived from) an ApplicationAddIn, and therefore only some of the ApplicationAddIns will be a TranslatorAddIn, which caused the error.  However, we simply know that the one we are looking for, and have found is a translator type, so we are able to set the ApplicationAddIn from the loop as the value of a TranslatorAddIn type variable.  I likely didn't standardized this across all my translator codes until shortly after posting that unfortunate mistake here.  I still prefer to find the add-in by its DisplayName myself, but since I'm not sure if the text is the same in all languages, it might not be the most internationally stable technique for everyone.  I'm sure there are lots of ways to do this.  I also used to check the ApplicationAddIn.AddInType (which returned a variation from the ApplicationAddInTypeEnum) before checking its DisplayName, but found that to be unnecessary.

 

Wesley Crihfield

EESignature

Message 14 of 14
niki
in reply to: WCrihfield

Thanks again @WCrihfield

 

I really like when code is robust, consistent and standardized. Thanks again.

Best regards

Niki

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report