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: 

Run an addin from iLogic

8 REPLIES 8
Reply
Message 1 of 9
AlexFielder
1992 Views, 8 Replies

Run an addin from iLogic

Hi All,

 

I've hunted around the forums and couldn't see anything that specifically relates to this problem so here goes:

 

Is it possible to run an addin from iLogic?

 

Specifically the Design Checker (DC) addin that recently graduated to the Exchange store?

 

The reason I ask this is that we want to use the DC to provide feedback to our client on Inventor datasets we've inherited that we didn't create.

 

Currently I can run the check in each part/sub-assembly but if the assemblies are large it could easily take days to complete this.

 

Unless of course I've been a bit thick and overlooked some way of making the DC addin do this by itself? (I sincerely hope not but it's been a long day so anything is possible...)

 

Thanks,

 

Alex.

8 REPLIES 8
Message 2 of 9

If the add-in has been already installed, you can access programmatically all registered add-ins and perform a Activate/Deactivate. You cannot however control the add-in itself unless it exposes specifically an interface that allows you to do so.

 

The VBA code below illustrates how to iterate the add-ins collection to activate them. The best way to access a specific add-in is to use its ClientId:

 

Public Sub ActivateAddins()

    Dim iter As ApplicationAddIn
    
    For Each oAddInIter In ThisApplication.ApplicationAddIns
        Debug.Print "Addin: " & iter.DisplayName & " ID: " & iter.ClientId
        iter.activate
    Next
    
    'Dim addin As ApplicationAddIn
    'Set addin = ThisApplication.ApplicationAddIns.ItemById("ADDIN_ID")

End Sub

 

Here is a link to a post that illustrates how to expose an interface to control your add-in:

 

http://adndevblog.typepad.com/manufacturing/2012/07/connecting-an-inventor-addin-from-an-external-ap...

 

I hope it helps,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 9

Hi Philippe,

 

That snippet is useful, thanks.

 

It does however contain an error and with my addition of filtering to just the addin called "*CHECKER*" now looks like this:

 

Public Sub ActivateAddins()

    Dim iter As ApplicationAddIn
    
    For Each iter In ThisApplication.ApplicationAddIns
        If UCase(iter.DisplayName) Like "*CHECKER*" Then
            Debug.Print "Addin: " & iter.DisplayName & " ID: " & iter.ClientId
            iter.Activate
        End If
    Next
    
    'Dim addin As ApplicationAddIn
    'Set addin = ThisApplication.ApplicationAddIns.ItemById("ADDIN_ID")

End Sub

So in theory that could be called from an iLogic rule such as this:

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
Imports System.IO

Public Sub Main
DesignCheckerResultsFromAssembly()
End Sub
Public Sub DesignCheckerResultsFromAssembly()
    ' Set reference to active document.
    ' This assumes the active document is an assembly
    Dim oDoc As Inventor.AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    Dim oSubDoc As Inventor.Document
	
    ' Get assembly component definition
    Dim oCompDef As Inventor.ComponentDefinition
    oCompDef = oDoc.ComponentDefinition
	If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
    	' Get all occurrences from component definition for Assembly document
    	Dim oCompOcc As ComponentOccurrence
    	For Each oCompOcc In oCompDef.Occurrences
        	' Check if it's child occurrence (leaf node)
        	If oCompOcc.SubOccurrences.Count = 0 Then
				'PART!
				oSubDoc = CType(oCompOcc.Definition.Document, Document)
				BeginRunDesignChecker(oSubDoc)
        	Else
				'ASSEMBLY!
            	oSubDoc = CType(oCompOcc.Definition.Document, Document)
				BeginRunDesignChecker(oSubDoc)
            	Call processAllSubOcc(oCompOcc) ' subassembly
        	End If
    	Next
    End If
End Sub

Public Function GetRootFolder(ByVal path As String) As String
Dim filepath As String = path
Dim directoryName As String 
Dim i As Integer = 0

	While i < 2
		directoryName = System.IO.Path.GetDirectoryName(filepath)
		filepath = directoryName
		If i = 1
			filepath = directoryName + "\"  ' this will preserve the previous path
		End If
		i = i + 1
	End While
Return filepath
End Function

' This function is called for processing sub assembly.  It is called recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence)
    
    Dim oSubCompOcc As ComponentOccurrence
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        ' Check if it's child occurrence (leaf node)
        If oSubCompOcc.SubOccurrences.Count = 0 Then
            'PART!
			oSubDoc = CType(oSubCompOcc.Definition.Document, Document)
			BeginRunDesignChecker(oSubDoc)
        Else
            oSubDoc = CType(oSubCompOcc.Definition.Document, Document)
			BeginRunDesignChecker(oSubDoc)
            Call processAllSubOcc(oSubCompOcc)
        End If
    Next
End Sub

Private Sub BeginRunDesignChecker(ByVal oDoc as Inventor.Document)
	Dim projectRootFolder= GetRootFolder(oDoc.FullFileName)
	If Not projectRootFolder.Contains("Content Center Files") Then
			RunDesignChecker(oDoc)
	End If

End Sub
Private Sub RunDesignChecker(ByVal oDoc as Inventor.Document)
	Public Sub ActivateAddins()

    Dim iter As ApplicationAddIn
    
    For Each iter In ThisApplication.ApplicationAddIns
        If UCase(iter.DisplayName) Like "*CHECKER*" Then
            iter.Activate
			exit for
        End If
    Next
End Sub
End Sub

 and it would run the checker for each occurence within a top-level assembly? (Or do anything else the user desires should someone else wish to copy this code)

 

(I haven't tested this yet so I've no idea whether it will crash & burn!)

 

Thanks,

 

Alex.

Message 4 of 9
AlexFielder
in reply to: AlexFielder

I've now refined my iLogic code so it looks like this:

 

Imports Inventor.ViewOrientationTypeEnum
Imports Inventor.DrawingViewStyleEnum
'Imports Autodesk.InventorDesignChecker.Main
Imports System.IO
AddReference "C:\ProgramData\Autodesk\ApplicationPlugins\Autodesk Design Checker.bundle\Contents\Windows\InventorDesignChecker.Main.dll"
Public Sub Main
DesignCheckerResultsFromAssembly()
End Sub
Public Sub DesignCheckerResultsFromAssembly()
    ' Set reference to active document.
    ' This assumes the active document is an assembly
    Dim oDoc As Inventor.AssemblyDocument
    oDoc = ThisApplication.ActiveDocument
    Dim oSubDoc As Inventor.Document
	
    ' Get assembly component definition
    Dim oCompDef As Inventor.ComponentDefinition
    oCompDef = oDoc.ComponentDefinition
	If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
    	' Get all occurrences from component definition for Assembly document
    	Dim oCompOcc As ComponentOccurrence
    	For Each oCompOcc In oCompDef.Occurrences
        	' Check if it's child occurrence (leaf node)
        	If oCompOcc.SubOccurrences.Count = 0 Then
				'PART!
				oSubDoc = CType(oCompOcc.Definition.Document, Document)
				BeginRunDesignChecker(oSubDoc)
        	Else
				'ASSEMBLY!
            	oSubDoc = CType(oCompOcc.Definition.Document, Document)
				BeginRunDesignChecker(oSubDoc)
            	Call processAllSubOcc(oCompOcc) ' subassembly
        	End If
    	Next
    End If
End Sub

Public Function GetRootFolder(ByVal path As String) As String
Dim filepath As String = path
Dim directoryName As String 
Dim i As Integer = 0

	While i < 2
		directoryName = System.IO.Path.GetDirectoryName(filepath)
		filepath = directoryName
		If i = 1
			filepath = directoryName + "\"  ' this will preserve the previous path
		End If
		i = i + 1
	End While
Return filepath
End Function

' This function is called for processing sub assembly.  It is called recursively
' to iterate through the entire assembly tree.
Private Sub processAllSubOcc(ByVal oCompOcc As ComponentOccurrence)
    
    Dim oSubCompOcc As ComponentOccurrence
    For Each oSubCompOcc In oCompOcc.SubOccurrences
        ' Check if it's child occurrence (leaf node)
        If oSubCompOcc.SubOccurrences.Count = 0 Then
            'PART!
			oSubDoc = CType(oSubCompOcc.Definition.Document, Document)
			BeginRunDesignChecker(oSubDoc)
        Else
            oSubDoc = CType(oSubCompOcc.Definition.Document, Document)
			BeginRunDesignChecker(oSubDoc)
            Call processAllSubOcc(oSubCompOcc)
        End If
    Next
End Sub

Private Sub BeginRunDesignChecker(ByVal oDoc as Inventor.Document)
	Dim projectRootFolder= GetRootFolder(oDoc.FullFileName)
	If Not projectRootFolder.Contains("Content Center Files") Then
			RunDesignChecker(oDoc)
	End If

End Sub
Private Sub RunDesignChecker(ByVal oDoc as Inventor.Document)
    Dim iter As ApplicationAddIn
    
    For Each iter In ThisApplication.ApplicationAddIns
        If UCase(iter.DisplayName) Like "*CHECKER*" Then
            iter.Activate
			If odoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then
				Dim partmgr As Autodesk.InventorDesignChecker.Main.dfmPartManager = New Autodesk.InventorDesignChecker.Main.dfmPartManager(oDoc, ThisApplication, True)
				partmgr.activate()
				partmgr.ExecuteAllChecks()
				Exit For
			Else
				Dim assyMgr As Autodesk.InventorDesignChecker.Main.dfmAssyManager = New Autodesk.InventorDesignChecker.Main.dfmAssyManager(oDoc, m_inventorApplication, True)
				assyMgr.activate()
                assyMgr.ExecuteAllChecks()
				Exit For
			End If
        End If
    Next
End Sub

 But even though it "runs" it doesn't appear to affect the DesignChecker results at all.

 

From my own investigations (as suggested by Philippe) in order to get the "correct" interface I added the InventorDesignChecker.Main.dll as a reference inside a Visual Studio project and having peeked at the internals of it using Reflector I think I'm executing the addin correctly, but it just doesn't make any difference to the overall Check/Failed Check count.

 

Can anyone shed any light on why that might be?

 

What would be excellent would be the addition of the source code for this addin to the Exchange Apps package. At least then I (and anyone else) could build it/step through the addin in a debugger to see what it does and when.

 

Thanks,

 

Alex.

Message 5 of 9

Hi Alex,

 

Sorry what is that "Autodesk.InventorDesignChecker.Main.dfmPartManager" object that you are creating? I'm not familliar with DesignChecker add-in, sorry if I'm missing something here... Is that an Autodesk add-in?

 

Thanks,

Philippe.

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 6 of 9

Hi Philippe,

 

Yes, the Design Checker I am referring to is an Autodesk-developed addin; I believe Rocky Zhang is the developer - at least, his contact details are on the readme for it.

 

I've looked into this a bit further from my end and I believe I'm correct in saying that the addin needs to have an Automation() Subroutine in order to be callable from another application (be it either iLogic, VBA or .NET) - which it currently does not expose (having looked at the tool using reflection).

 

Your post here states the above I think?

Message 7 of 9

An addin needs to expose an interface through the Automation property as described in the blog post in order for an application to invoke methods on that addin object. However one dll could expose some static methods or objects that can be instanciated and used without the Automation.

 

I am not sure here because what you are dealing with isn't a supported API, there might be some features of Design Checker that are exposed, but there is no documentation about it anywhere.

 

I am checking with Rocky if he is able to help you in this regards.

 

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 8 of 9

Thanks Philippe, this will be a big help if it is possible - the few times I have run Design Checker manually, it's quite time consuming on even a relatively simple assembly.

 

What would be nice is the ability to modify the Report Viewer template that the reporting function uses - perhaps to include some form of sub-report, but that's outside the scope of this thread so I will start another topic when I get a chance.

Message 9 of 9

Hi Alex,

 

Rocky said he will look into it, he's been busy so far, sorry for the delay. This isn't really a supported topic, so as far as I'm concerned I don't have access to the source and have not seen any related question in the past.

 

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

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

Post to forums  

Autodesk Design & Make Report