References to more than one version of Autodesk.Inventor.Interop on Inventor CAM (2023) sample iLogic

References to more than one version of Autodesk.Inventor.Interop on Inventor CAM (2023) sample iLogic

Maxim-CADman77
Advisor Advisor
515 Views
2 Replies
Message 1 of 3

References to more than one version of Autodesk.Inventor.Interop on Inventor CAM (2023) sample iLogic

Maxim-CADman77
Advisor
Advisor

I'm studying possibility to write some Inventor CAM-related iLogic-program (I was asked to make it compatible with Inventor 2023, updated to 2023.4.1).
I have installed Inventor CAM 2023 (and updated it to 2023.2).


Firstly I've tried to run the Sample iLogic program contained in InventorHSMAddinAPI.chm


Here is code after some cosmetic improvements:

 

Option Explicit On

AddReference "C:\Program Files\Autodesk\Inventor CAM 2023\R28\Autodesk.InventorHSM.Interop.dll"
Imports Autodesk.InventorHSM.Interop

Sub Main

'' Access the API object
Dim addin As ApplicationAddIn
addin = ThisApplication.ApplicationAddIns.ItemById("{749E667C-2560-416A-A5E7-68B96FF997B1}") ' Inventor CAM '

Dim api As Object
api = addin.Automation

Dim addinApi As InventorHSMAddinAPI
addinApi = addin.Automation

Dim hsmVersion As String
hsmVersion = addinApi.Version

Dim hsmEdition As HSMProductEditionEnum
hsmEdition = addinApi.ProductEdition

' Call MsgBox("HSM Version: " + hsmVersion + vbLf + "HSM Product Edition: " + ProductEditionStr(hsmEdition))

'' Access the available (open) HSMDocuments
Dim hsmDocs As HSMDocuments
hsmDocs = addinApi.HSMDocuments

Dim docVersion As String

Dim hsmDoc As HSMDocument
For Each hsmDoc In hsmDocs
   Logger.Info("hsmDoc.Version: " & hsmDoc.Version)
Next

'' Get HSMDocument for active Inventor document
hsmDoc = hsmDocs.Item(ThisDoc.Document) ' ThisApplication.ActiveDocument)
docVersion = hsmDoc.Version

'' Get collection of all operations and loop through them.
Dim ops As HSMOperations
ops = hsmDoc.AllOperations

Dim op As HSMOperation
For Each op In ops
	Logger.Info(vbTab + "Op: " + op.Name + ", Type - " + op.Strategy)
Next

'' Get information about operations and setups
Dim firstOp As HSMOperation
firstOp = ops.Item(1)
Logger.Info("firstOp.Name: " + firstOp.Name)

Dim allSetups As HSMOperations
allSetups = hsmDoc.Setups

Dim firstSetup As HSMSetup
firstSetup = allSetups.Item(1)
Logger.Info("firstSetup.Name: " & firstSetup.Name)

'' Toolpath generation - entire document (skipping already valid operations)
Dim future As HSMGenerateToolpathFuture
' SkipValid = True

future = hsmDoc.GenerateAllToolpath()
Logger.Info("Gen1: # ops = " + Str(future.NumberOfOperations))
Logger.Info("Gen1: # completed = " + Str(future.NumberCompleted))
Call future.WaitForCompletion


'' Toolpath generation - specific operations (allSetups)
future = hsmDoc.GenerateToolpath(allSetups.GetObjectCollection())

logger.info("Gen2: # ops = " + Str(future.NumberOfOperations))
logger.info("Gen2: # completed = " + Str(future.NumberCompleted))
Call future.WaitForCompletion

'' Post Processing
Dim post As String
post = "C:\Users\Public\Documents\Autodesk\Inventor CAM\Posts\acramatic.cps"

Dim props As NameValueMap
props = addinApi.GetPostProperties(post)

Dim ppInput As HSMPostProcessInput
ppInput = addinApi.CreatePostProcessInput()

ppInput.PostConfiguration = post
ppInput.OutputPath = "c:\temp\ncoutput\test.nc"
ppInput.ProgramName = "0001"
ppInput.ProgramComment = "This is a test"

Dim opsToPostProcess As ObjectCollection
opsToPostProcess = ThisApplication.TransientObjects.CreateObjectCollection()
Call opsToPostProcess.Add(firstSetup)

Call hsmDoc.PostProcess(opsToPostProcess, ppInput)

End Sub


'' Converts HSMProductEditionEnum value to user-readable string.
Function ProductEditionStr(edition As HSMProductEditionEnum) As String

	ProductEditionStr = "Unknown"
	If edition = HSMProductEditionEnum.Express Then
		ProductEditionStr = "Express"
	ElseIf edition = HSMProductEditionEnum.Premium Then
		ProductEditionStr = "Premium"
	ElseIf edition = HSMProductEditionEnum.Ultimate Then
		ProductEditionStr = "Ultimate"
	End If

End Function

 

 

The line

 

future = hsmDoc.GenerateToolpath(allSetups.GetObjectCollection())

 

 

Produces two at once exceptions:

 

The project currently contains references to more than one version of Autodesk.Inventor.Interop, a direct reference to version 27.4.0.0 and an indirect reference (through 'Autodesk.InventorHSM.Interop.HSMDocument.GenerateToolpath') to version 28.0.0.0. Change the direct reference to use version 28.0.0.0 (or higher) of Autodesk.Inventor.Interop.

 

The project currently contains references to more than one version of Autodesk.Inventor.Interop, a direct reference to version 27.4.0.0 and an indirect reference (through 'Autodesk.InventorHSM.Interop.HSMOperations.GetObjectCollection') to version 28.0.0.0. Change the direct reference to use version 28.0.0.0 (or higher) of Autodesk.Inventor.Interop.

 

I then tried to run the rule on the same PC, same sample CAM-document (see attached) from the Inventor 2024.2 (without installing Inventor CAM 2024).

...and there were no exceptions!

But remember? I need the program for Inventor 2023...

I then tried to explicitly add reference to Autodesk.Inventor.Interop 2024 like this:

 

 

AddReference "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_28.2.0.0__d84147f8b4276564\autodesk.inventor.interop.dll"
' AddReference "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_28.0.0.0__d84147f8b4276564\autodesk.inventor.interop.dll"
...
Imports Autodesk.Inventor.Interop

 

 

But this version produced a set of errors like:
'Application' is ambiguous in the namespace 'Inventor'.
'ApplicationAddIn' is ambiguous in the namespace 'Inventor'.
'NameValueMap' is ambiguous in the namespace 'Inventor'.
'ObjectCollection' is ambiguous in the namespace 'Inventor'.

What I'm missing?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
516 Views
2 Replies
Replies (2)
Message 2 of 3

Maxim-CADman77
Advisor
Advisor

The initial code works without exceptions in Inventor 2023 after UNinstalling CAM 2023, installing CAM 2022, updating it to 2022.3.1 and modifying AddReference path like:

 

 

 

AddReference "C:\Program Files\Autodesk\Inventor CAM 2022\R27\Autodesk.InventorHSM.Interop.dll"

 

 

 

PS:
Seems like some general major release number mismatch between Inventor CAM and Inventor itself:

In order to use CAM API in Inventor 2023 Inventor CAM should be not newer then 2022

In order to use CAM API in Inventor 2024 Inventor CAM should be not newer then 2023

 

...

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 3 of 3

Maxim-CADman77
Advisor
Advisor

I dive into Inventor CAM API in hope to automate creation of HSMOperations (from template), but it seems there is no fusion-like Setup.createFromTemplate method.
I also failed to do it in a trick-way like emulate a series of key presses on the Setup BrowserNode because CAM browser (unlike the model browser) is some sort of Active X control and I have no idea on how to get anything from it.
I believe the CAM AddIn/API development was stopped (? in favor of Fusion ?).

PS:
The last Inventor CAM help is 2020...

Please vote for Inventor-Idea Text Search within Option Names

0 Likes