Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Inventor C# Listener

Anonymous

Inventor C# Listener

Anonymous
Not applicable

I am using Inventor api with C#. I want create a listener for Inventor 2016. For example Let alert (message.box) when opened save as dailog or etc.

0 Likes
Reply
Accepted solutions (1)
1,966 Views
11 Replies
Replies (11)

Jef_E
Collaborator
Collaborator

Sounds cool and what is the question here?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

Anonymous
Not applicable

I said. How can I listen Inventor API with C# ? Can you give me sample codes or tricks.

0 Likes

Jef_E
Collaborator
Collaborator

Hmm does not seem like you said that..

 

I want to..

How to..

 

what version of Inventor are you using? there are enough sample in the API to do this I think. I don't have C# code to show for.. only VB.NET if you can translate it?

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

tolgay.hickiran
Advisor
Advisor

I'd love to see that Jef


Some worthwhile ideas
Copy Design should rename ilogic Rules too!
Why Nastran In-CAD doesn't have an SDK?IMPLEMENTED!

Tolgay Hickiran
Founding Partner
SignatureSignature

website
emailskypelinkedinyoutubeemail

0 Likes

nmunro
Collaborator
Collaborator

Inventor ships with an event watcher tool. Install the developer tools and look for EventWatcher.exe

        


https://c3mcad.com

0 Likes

Anonymous
Not applicable

I am using Inventor 2016 Premium. Yes Jef_E, I can translate vb to c#. If you give me any sample I be to happy.

0 Likes

Jef_E
Collaborator
Collaborator
Accepted solution

As stated by @nmunro

 

I attached a zip file with the event watcher from Autodesk written in vb.net

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

Anonymous
Not applicable

Can you compile your sended project ? I see that in developer tools but was giving compile error as your sended.

0 Likes

Jef_E
Collaborator
Collaborator

Change the target framework..



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes

Anonymous
Not applicable

İrfan Şahin dostum;

Did you translate Mr. Jef's VB codes to C#?

 

I just need handling of OnDocumentActive, but not as addin; I'm trying to make an executable application. May you help me?

Thanks in advance to everybody.

 

using System;
using Inventor;

namespace WpfInventor45
{
    public interface IApplicationEventsLib
    {
        ApplicationEvents ApplicationEvents { get; }
        
        ApplicationEventsSink_OnActivateDocumentEventHandler OnActivateDocumentDelegate
        {
            get;
            set;
        }
        
        void Deactivate();

        void I_Need_This(Inventor._Document DocumentObject, Inventor.EventTimingEnum BeforeOrAfter, Inventor.NameValueMap Context, ref Inventor.HandlingCodeEnum HandlingCode);
    }

    public class ApplicationEventsLib : IApplicationEventsLib
    {
        private readonly Application inventorApp;

        public ApplicationEventsLib(Application inventorApp)
        {
            this.inventorApp = inventorApp;
            ApplicationEvents = this.inventorApp.ApplicationEvents;
            Activate();
        }

        public ApplicationEventsSink_OnActivateDocumentEventHandler OnActivateDocumentDelegate
        {
            get; set;
        }
        
        public ApplicationEvents ApplicationEvents { get; private set; }

        public void I_Need_This(Inventor._Document DocumentObject, Inventor.EventTimingEnum BeforeOrAfter, Inventor.NameValueMap Context, ref Inventor.HandlingCodeEnum HandlingCode)
        {
            if ((BeforeOrAfter == Inventor.EventTimingEnum.kAfter))
                Console.WriteLine("Code here!!");
        }

        private void Activate()
        {
// I'm Getting error: No overload for .. matches delegate.. OnActivateDocumentDelegate = new ApplicationEventsSink_OnActivateDocumentEventHandler(I_Need_This);
ApplicationEvents.OnActivateDocument += OnActivateDocumentDelegate; } public void Deactivate() { ApplicationEvents.OnActivateDocument -= OnActivateDocumentDelegate; OnActivateDocumentDelegate = null; } } }
0 Likes

Anonymous
Not applicable

In VB using ByRef works, but in C# it does not!

I found the solution: out in, ref out  Smiley Happy

 

For the ones like me in yesterday..

using Inventor; //autodesk.inventor.interop

private Inventor.Application m_App = null;
private Inventor.ApplicationEvents m_ApplicationEvents = null;

private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
//Inventor.Application application = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application"); m_App = InitializeInventor(true, true); if (m_App != null) { m_ApplicationEvents = m_App.ApplicationEvents; m_App.ApplicationEvents.OnActivateDocument += ApplicationEvents_OnActivateDocument; m_App.ApplicationEvents.OnQuit += ApplicationEvents_OnQuit; } else System.Environment.Exit(0); } catch { } } void ApplicationEvents_OnQuit(EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode) { switch (BeforeOrAfter) { case EventTimingEnum.kBefore: //Do Something; HandlingCode = HandlingCodeEnum.kEventNotHandled; break; default: HandlingCode = HandlingCodeEnum.kEventNotHandled; break; } } //Use out instead of ref void ApplicationEvents_OnActivateDocument(_Document DocumentObject, EventTimingEnum BeforeOrAfter, NameValueMap Context, out HandlingCodeEnum HandlingCode) { HandlingCode = HandlingCodeEnum.kEventNotHandled; //This line is Important if ((BeforeOrAfter == Inventor.EventTimingEnum.kBefore)) { //Do Something } }

Tags:

"Inventor Application Events"

"Handling Inventor Events Using C#"

"Inventor OnActvateDocument"

"ApplicationEventsSink_OnActivateDocumentEventHandler"

 

0 Likes