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: 

Can someone tell me whats wrong with this simple add-in??

3 REPLIES 3
Reply
Message 1 of 4
SMachado
372 Views, 3 Replies

Can someone tell me whats wrong with this simple add-in??

HI!

when i hit the created add-in button, the inventor display a error, and i'm not understanding why.
can someone check this for me?

THANKS.



Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32

Namespace Num_desenhos
GuidAttribute("aca8e62a-a403-47b9-ab48-e313ebf86673")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer

' Inventor application object.
Private m_inventorApplication As Inventor.Application
Private WithEvents m_ButtonDef As ButtonDefinition
Private m_ClientID As String

#Region "ApplicationAddInServer Members"

Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate

' This method is called by Inventor when it loads the AddIn.
' The AddInSiteObject provides access to the Inventor Application object.
' The FirstTime flag indicates if the AddIn is loaded for the first time.

' Initialize AddIn members.
m_inventorApplication = addInSiteObject.Application

' TODO: Add ApplicationAddInServer.Activate implementation.
' e.g. event initialization, command creation etc.

m_ClientID = AddInGuid(GetType(StandardAddInServer))

Dim oUIManager As UserInterfaceManager = m_inventorApplication.UserInterfaceManager

Dim controldefs As ControlDefinitions
controldefs = m_inventorApplication.CommandManager.ControlDefinitions

m_ButtonDef = controldefs.AddButtonDefinition("Numera desenhos", "AddIn_numera_desenhos", CommandTypesEnum.kQueryOnlyCmdType, m_ClientID, "Adiciona app para numerar desenhos", "Numera desenhos")

If firstTime = True Then

If oUIManager.InterfaceStyle = InterfaceStyleEnum.kClassicInterface Then

Dim commandbars As CommandBars
commandbars = m_inventorApplication.UserInterfaceManager.CommandBars
Dim commandbar As CommandBar
commandbar = commandbars.Add("addins_nm", "AuAddin_nm", CommandBarTypeEnum.kRegularCommandBar, m_ClientID)
commandbar.Visible = True
commandbar.Controls.AddButton(m_ButtonDef)

End If
End If


End Sub

Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate

' This method is called by Inventor when the AddIn is unloaded.
' The AddIn will be unloaded either manually by the user or
' when the Inventor session is terminated.

' TODO: Add ApplicationAddInServer.Deactivate implementation

' Release objects.
Marshal.ReleaseComObject(m_inventorApplication)
m_inventorApplication = Nothing

System.GC.WaitForPendingFinalizers()
System.GC.Collect()

End Sub

Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation

' This property is provided to allow the AddIn to expose an API
' of its own to other programs. Typically, this would be done by
' implementing the AddIn's API interface in a class and returning
' that class object through this property.

Get
Return Nothing
End Get

End Property

Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand

' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.

End Sub

#End Region

#Region "COM Registration"

' Registers this class as an AddIn for Inventor.
' This function is called when the assembly is registered for COM.
_
Public Shared Sub Register(ByVal t As Type)

Dim clssRoot As RegistryKey = Registry.ClassesRoot
Dim clsid As RegistryKey = Nothing
Dim subKey As RegistryKey = Nothing

Try
clsid = clssRoot.CreateSubKey("CLSID\" + AddInGuid(t))
clsid.SetValue(Nothing, "Num_desenhos")
subKey = clsid.CreateSubKey("Implemented Categories\{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}")
subKey.Close()

subKey = clsid.CreateSubKey("Settings")
subKey.SetValue("AddInType", "Standard")
subKey.SetValue("LoadOnStartUp", "1")

'subKey.SetValue("SupportedSoftwareVersionLessThan", "")
subKey.SetValue("SupportedSoftwareVersionGreaterThan", "12..")
'subKey.SetValue("SupportedSoftwareVersionEqualTo", "")
'subKey.SetValue("SupportedSoftwareVersionNotEqualTo", "")
'subKey.SetValue("Hidden", "0")
'subKey.SetValue("UserUnloadable", "1")
subKey.SetValue("Version", 2)
subKey.Close()

subKey = clsid.CreateSubKey("Description")
subKey.SetValue(Nothing, "Num_desenhos")

Catch ex As Exception
System.Diagnostics.Trace.Assert(False)
Finally
If Not subKey Is Nothing Then subKey.Close()
If Not clsid Is Nothing Then clsid.Close()
If Not clssRoot Is Nothing Then clssRoot.Close()
End Try

End Sub

' Unregisters this class as an AddIn for Inventor.
' This function is called when the assembly is unregistered.
_
Public Shared Sub Unregister(ByVal t As Type)

Dim clssRoot As RegistryKey = Registry.ClassesRoot
Dim clsid As RegistryKey = Nothing

Try
clssRoot = Microsoft.Win32.Registry.ClassesRoot
clsid = clssRoot.OpenSubKey("CLSID\" + AddInGuid(t), True)
clsid.SetValue(Nothing, "")
clsid.DeleteSubKeyTree("Implemented Categories\{39AD2B5C-7A29-11D6-8E0A-0010B541CAA8}")
clsid.DeleteSubKeyTree("Settings")
clsid.DeleteSubKeyTree("Description")
Catch
Finally
If Not clsid Is Nothing Then clsid.Close()
If Not clssRoot Is Nothing Then clssRoot.Close()
End Try

End Sub

' This property uses reflection to get the value for the GuidAttribute attached to the class.
Public Shared ReadOnly Property AddInGuid(ByVal t As Type) As String
Get
Dim guid As String = ""
Try
Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
guid = "{" + guidAttribute.Value.ToString() + "}"
Finally
AddInGuid = guid
End Try
End Get
End Property

#End Region

Private Sub m_ButtonDef_OnExecute(ByVal Context As Inventor.NameValueMap) Handles m_ButtonDef.OnExecute

Dim form As Form1
form = New Form1
form.InventorDocument = m_inventorApplication.ActiveDocument




form.Show()






End Sub
End Class

End Namespace
3 REPLIES 3
Message 2 of 4
SMachado
in reply to: SMachado

Hi!

I really need help, i dont know what is going on.
Inventor returns the following error:

is not possible to associate the COM object of type 'Inventor._DocumentClass' type of interface'Inventor. AssemblyDocument'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '(xxxxxx)' failed with the following error:
No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Message 3 of 4
Anonymous
in reply to: SMachado

Can you post the StandardAddInServer.vb file. I tried to paste your code in
to a new one, but it comes in all as one line.

--
KWiKMcad
Kent Keller
"SMachado" wrote in message news:6384920@discussion.autodesk.com...
Hi!

I really need help, i dont know what is going on.
Inventor returns the following error:

is not possible to associate the COM object of type
'Inventor._DocumentClass' type of interface'Inventor. AssemblyDocument'.
This operation failed because the QueryInterface call on the COM component
for the interface with IID '(xxxxxx)' failed with the following error:
No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE)).
Message 4 of 4
SMachado
in reply to: SMachado

Hi Kent!

I have solved the problem, it was a problem on the form load event


thanks.

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

Post to forums  

Autodesk Design & Make Report