Reply
Solved! Go to solution

Catch event when properties change in the SE API

Hi all,

 

Background:

I'm currently working on an AddIn which should update the Ribbon when I switch sheets in the draft environment. I found out that the command ID 45000 (DetailCommandConstants.DetailToolSelectTool) gets fired when I switch sheets. But it fires _before_ the sheets are actually changed (e.g. Sheet.Name still returns the old name).

 

It would be really nice if all properties in the API would send the PropertyChanged event, which comes with the INotifyPropertyChanged interface. It would simplify the event handling a lot if we could attach to these IMO!

 

The only solution I can see for my problem is to create a thread that checks the Name property of the sheet every 10 milliseconds or so, and then fires an event if it changed. Are there better ideas / solutions to this problem?

 

Regards,

Jonas

6 REPLIES

Re: Catch event when properties change in the SE API

I'm not seeing a way to do what you want as described. Perhaps if you could give more detail about what you're trying to accomplish in the ribbon, we could propose an alternative solution.

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Catch event when properties change in the SE API

Sure, I'll explain:

 

We have a certain set of symbols that are a standard on our drawings. They should always be at the same initial position (but flexible to move if needed). It should be a userfriendly solution to toggle the symbol visibility (and insert symbols if they don't yet exist on the drawing). This is not meant to be global, so each sheet can have different symbols visible.

That's why I need to update the Ribbon each time the sheets are switched, to check for the visibility/existence of the symbols on the current sheet and update the checkboxes accordingly.

Re: Catch event when properties change in the SE API

Update:

 

I'm currently starting a thread that runs a while-loop and sends an event when the ActiveSheet object changed. Works so far, but I get random crashes. Maybe there are some threading access violations going on in the background. It's the "dirty" solution to my problem. I'll let you know when I come up with something better.

Re: Catch event when properties change in the SE API

[ Edited ]

Thank you for the better description of what you're trying to accomplish. With that understanding, I have an alternative solution. See the ISEAddInEvents OnCommandUpdateUI event. 

 

Int32 OnCommandUpdateUI(Int32 CommandID, ref Int32 CommandFlags, out String MenuItemText, ref Int32 BitmapID)
   Member of SolidEdgeFramework.ISEAddInEvents

Summary:
    Occurs when the user interface needs to be updated.

ID:
    1610678274 (0x60010002)

This event gets raised by Solid Edge to give you an opportunity to update your ribbon. I just wrote a test and was able to successfully alter my ribbon's display as each sheet was selected. This is an overly simplistic example but enough to prove the theory.

 

HRESULT CMyAddIn::raw_OnCommandUpdateUI(long nCmdID, long *lCmdFlags, BSTR *MenuItemText, long *nIDBitmap)
{
    SolidEdgeDraft::DraftDocumentPtr pDraftDocument = m_pApplication->ActiveDocument;
    SolidEdgeDraft::SheetPtr pSheet = pDraftDocument->ActiveSheet;
    
    switch (nCmdID)
    {
    case idCheckbox1:
        if (pSheet->Index == 1)
        {
            *lCmdFlags |= SolidEdgeConstants::seCmdActive_Checked;
        }

        break;
    }

    return S_OK;
}

 

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Catch event when properties change in the SE API

[ Edited ]

Hi Jason,

 

Thanks for your help on this so far!

I'm not sure if I understand your examply correctly. I implemented the following:

 

 

 public void OnCommandUpdateUI(int commandID, ref int commandFlags, out string menuItemText, ref int bitmapID)
{
commandFlags = (int)SolidEdgeConstants.SECommandActivation.seCmdActive_Checked;
System.Windows.Forms.MessageBox.Show("Event! ID=" + commandID);

menuItemText = "Test";
}

 

I'm not even sure what I have to do in Solid Edge so that the messagebox in my example shows up.

 

The checkboxes should be an indicator if a symbol is on the drawing or not. It should detect when the user switches sheets and update the Ribbon (check/uncheck the checkbox automatically without the user interacting). I'm not sure if I can accomplish this with your method.

Solution
Solution
Accepted by topic author freijon
‎08-26-2015 04:32 AM

Re: Catch event when properties change in the SE API

[ Edited ]

Just FYI, I'm going to stick with the thread solution. It works pretty well now. The instability was not caused by thread access violations but the server that was busy. Registering the OleMessageFilter solved that problem. The impact on performance is neglible if the sleeping timer is set high enough (500ms). Further solutions are still welcome, but I'll mark the problem with "solved".