How to fire ApplicationEvents OnActivateDocument when double click a Browser Node in an assembly

How to fire ApplicationEvents OnActivateDocument when double click a Browser Node in an assembly

hrnkilic
Explorer Explorer
587 Views
2 Replies
Message 1 of 3

How to fire ApplicationEvents OnActivateDocument when double click a Browser Node in an assembly

hrnkilic
Explorer
Explorer

Hi.

I am trying to implement an add-in using a C# modeless topmost WPF window for assembly documents.

I can handle the event OnActivateDocument. When I open a document it fires.

But in an assembly; when a sub document was not opened before and was not visible;

when I double click a sub document on the assembly model or when I double click a node / pane of a sub document on built-in browser of the assembly document, then the sub document becomes active in the same window of parent assembly but OnActivateDocument is not firing so I can't run sub routines inside ApplicationEvents_OnActivateDocument method.

BrowserPanesEvents_OnBrowserNodeActivate is not firing on built-in browser panes.

 

So the question is : How can I get active document object (via events) when a sub document is activated in the same window of parent assembly?

Thanks in advance. 

0 Likes
Accepted solutions (1)
588 Views
2 Replies
Replies (2)
Message 2 of 3

bradeneuropeArthur
Mentor
Mentor
Accepted solution

use this 

 

.OnNewEditObject

.OnActivateView

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 3

hrnkilic
Explorer
Explorer

Thank you.

.OnActivateView was a headache for me but .OnNewEditObject really helped.

Regards.

 

public partial class WPFForm : Window
    {
        Inventor.Application inventor;        
        private Inventor.ApplicationEvents m_appEvents;

        public WPFForm(Inventor.Application _inventor)
        {
            InitializeComponent();
            inventor= _inventor;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            m_appEvents = inventor.ApplicationEvents;           
            m_appEvents.OnNewEditObject += new ApplicationEventsSink_OnNewEditObjectEventHandler(ApplicationEvents_OnNewEditObject);
        }
        private void Window_Unloaded(object sender, RoutedEventArgs e)
        {            
m_appEvents.OnNewEditObject -= new ApplicationEventsSink_OnNewEditObjectEventHandler(ApplicationEvents_OnNewEditObject);
          m_appEvents = null;            
        }
 private void ApplicationEvents_OnNewEditObject(Object EditObject, EventTimingEnum BeforeOrAfter , NameValueMap Context,out HandlingCodeEnum HandlingCode)
        {
            /*
            EditObject:	    Object	
                                The new edit object.
                                When the BeforeOrAfter argument is kBefore this is the object that will become the edit object.
                                When the argument is kAfter this is the current edit object.
            BeforeOrAfter:	EventTimingEnum	
                                Input indicating if the event is being fired before (kBefore) or after (kAfter) there is a new edit object.
                                Notification is sent before and after the edit object change is made.
            Context:	    NameValueMap	
                                Input object that can be used to determine the context of why the event fired.
                                When an object is activated for edit within the context of an assembly some additional information 
                                is provided through the Context argument, as described below: 
                                Name = "ActiveDocument", 
                                Value = The AssemblyDocument object that the edit is within the context of .Name = "ActiveEditObject", 
                                Value = The ComponentOccurrence object in the assembly the edit is through.
            HandlingCode:	HandlingCodeEnum
                                Output that indicates how you are handling the event. This argument is ignored for this event.

            Notes
                A scenario that users need to be aware of is when you use this event to monitor opening a drawing document,
                the active edit object (i.e. active sheet in the drawing in this case) will be available 
                but its parent drawing document still not becomes the active document, 
                in this case users need to get the parent drawing document from the Sheet.Parent.

            Remarks
                This event is useful in many cases but is particularly critical when adding additional tabs to the browser.
                This event serves as the notification of when to add the browser tab.
                The OnOpenDocument event is not satisfactory for this case because this event is fired for documents 
                that are opened as a result of being referenced in an assembly.
                In this context, most of the documents will not be directly edited, so adding the browser information is a waste of resources.
                The OnActivateDocument event is also unsatisfactory because when a document is edited in the context of an assembly,
                it is not activated. The assembly remains the active document.
                What does change is the current edit object. The edit object is the container object that is being edited by the end-user.
                For example when an assembly document is opened, the assembly document is the active document and the active edit object.
                If the end-user in-place activates a part in the assembly, the part becomes the active edit object,
                although the assembly is still the active document because the edit is taking place in the context of the assembly.
                If the end-user creates or edits a sketch within the part, the sketch becomes the active edit object.
                Valid objects for edit objects are documents, 2d and 3d sketches, and drawing sheets.
             */

            HandlingCode = Inventor.HandlingCodeEnum.kEventNotHandled;
            try
            {
                if (BeforeOrAfter == Inventor.EventTimingEnum.kBefore)
                {
                    return;
                }
                else if (BeforeOrAfter == Inventor.EventTimingEnum.kAfter)
                {
                    if (EditObject is Inventor.Document)
                    {
                        Inventor.Document document = (Inventor.Document)EditObject;
                        System.Windows.MessageBox.Show(document.DisplayName);
                    }                    
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex) 
            {
                System.Windows.MessageBox.Show("ApplicationEvents_OnNewEditObject :" + System.Environment.NewLine + ex.Message); 
            }
            HandlingCode = Inventor.HandlingCodeEnum.kEventHandled;
        }
}

 

  

Link:

Link to help document

0 Likes