AddIn Automation Interface problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
HI
I have this error when I try to call the AddIn from the other application:
Unable to cast COM object of type 'System.__ComObject' to interface type 'HInventorServer2013.IAutomation'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{89D1FA61-3CEB-365D-A1F5-9A664F525CCB}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
I tried many different things but nothing works until now.
The AddIn is here:
C:\Users\me_as_user\AppData\Roaming\Autodesk\ApplicationPlugins\HInventorServer2013
Maybe I have to register the DLL generated from the StandardAddInServer?
I don't know what else to do.
Thanks
Paolo
This is for inventor 2013 but i didn't works also for Inventor 2017
Implementation is very easy, nothing fancy:
[GuidAttribute("88095ac1-6393-458d-8327-c168f027da88")]
public class StandardAddInServer : Inventor.ApplicationAddInServer, IAutomation
{
private Inventor.Application _AddInApp;
private string _AddInGuid = "{88095ac1-6393-458d-8327-c168f027da88}";
public StandardAddInServer() {}
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
_AddInApp = addInSiteObject.Application;
}
public void Deactivate()
{
// Release objects.
Marshal.ReleaseComObject(_AddInApp);
_AddInApp = null;
GC.WaitForPendingFinalizers();
GC.Collect();
}
public void ExecuteCommand(int commandID) {}
public object Automation
{
get { return this; }
}
// Interface implementation
public string HI_GetCurrDocument()
{
PartDocument doc;
// Container pippo = new Container();
string text = "";
try
{
doc = _AddInApp.ActiveDocument as Inventor.PartDocument;
text = doc.DisplayName;
// pippo.GetContainer = doc.DisplayName;
}
catch (Exception e)
{
// pippo.GetContainer = e.ToString();
text = e.ToString();
}
return text;
}
public string HI_GetSketchLines()
{
/*
Container test = new Container("ciao da API");
return test;
*/
return "Hello from API";
}
}and this is the call
public CallAddIn()
{
try
{
_InvApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
}
catch
{
Type InvAppType = System.Type.GetTypeFromProgID("Inventor.Application");
_InvApp = System.Activator.CreateInstance(InvAppType) as Inventor.Application;
}
_InvApp.Visible = true;
// hard coding Guid of the AddIn
string AddInGuid = "{88095ac1-6393-458d-8327-c168f027da88}";
ApplicationAddIn InvAddIn = _InvApp.ApplicationAddIns.get_ItemById(AddInGuid.ToUpper());
// make sure addIn is activaded
if (!InvAddIn.Activated)
{
InvAddIn.Activate();
}
// this works - InvAddIn is correct
Debug.Print(InvAddIn.DisplayName);
// version 1 - this give me an error
IAutomation HIapi = (IAutomation) InvAddIn.Automation;
// this give a null object - conversion failed
IAutomation HIapi = InvAddIn.Automation as IAutomation;
}