Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - TheMintRubber

Pages: [1]
1
Hi,

I am creating an EA addin written in WPF.

I have to select an item in the EA diagram when the user clicks on a item in my plugin. I have the item's guid, but I can't find a way to select the element in EA.

I have found the Diagram.SelectedObjects.AddNew(string name, string type), but I don't know how to get the name and type by my guid.

So, is there a way to select an item in the opened Diagram using the item's guid?

Thanks.

2
Hi,

I am using WPF to write an Enterprise Architect addin.

I need to react when a user selects an item in the project browser. Is there an event for this?

I've already found the broadcast event page, but I couldn't find anything in there. http://www.sparxsystems.com/enterprise_architect_user_guide/10/automation_and_scripting/broadcastevents.html.

I also know there is the EARepository.GetTreeSelectedItem() method, that returns the item selected in the project browser, but I would have to add a timer and call this method every 500 ms or so, so this is not a good idea.

Any ideas?

Thanks,
Doru.

3
Hi,


@Helmut Ortmann: That is available only in EA 13, I have to target EA 12, so I can't use it.

Using qwerty's answer, I've made the following implementation:

Code: [Select]
   

        [DllImport("ole32.dll")]
        public static extern int GetRunningObjectTable(int reserved, out UCOMIRunningObjectTable prot);

        [DllImport("ole32.dll")]
        public static extern int CreateBindCtx(int reserved, out UCOMIBindCtx ppbc);

        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

        private const int SW_RESTORE = 9;
        [DllImport("user32.dll")]
        private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

        [DllImport("user32.dll")]
        private static extern bool IsIconic(IntPtr hWnd);

        public static List<EAAppInstance> GetEAInstances()
        {
            List<EAAppInstance> result = new List<EAAppInstance>();

            Hashtable runningObjects = GetRunningObjectTable();

            IDictionaryEnumerator rotEnumerator = runningObjects.GetEnumerator();
            while (rotEnumerator.MoveNext())
            {
                string candidateName = (string)rotEnumerator.Key;

                if (!candidateName.ToUpper().Contains("EA"))
                    continue;

                EA.App eaApplication = rotEnumerator.Value as EA.App;

                if (eaApplication == null)
                    continue;

                // Remember the process Id so we can Show that window to the user
                int processId = int.Parse(candidateName.Split(':')[1]);

                result.Add(new EAAppInstance(eaApplication, processId));
            }

            return result;
        }

        [STAThread]
        public static Hashtable GetRunningObjectTable()
        {
            Hashtable result = new Hashtable();

            int numFetched;
            UCOMIRunningObjectTable runningObjectTable;
            UCOMIEnumMoniker monikerEnumerator;
            UCOMIMoniker[] monikers = new UCOMIMoniker[1];

            GetRunningObjectTable(0, out runningObjectTable);
            runningObjectTable.EnumRunning(out monikerEnumerator);
            monikerEnumerator.Reset();

            while (monikerEnumerator.Next(1, monikers, out numFetched) == 0)
            {
                UCOMIBindCtx ctx;
                CreateBindCtx(0, out ctx);

                string runningObjectName;
                monikers[0].GetDisplayName(ctx, null, out runningObjectName);

                object runningObjectVal;
                runningObjectTable.GetObject(monikers[0], out runningObjectVal);

                result[runningObjectName] = runningObjectVal;
            }

            return result;
        }

Thanks to all for your replies,
Doru.

4
Quote
Hehe. Was about to point to http://sparxsystems.com/forums/smf/index.php/topic,30896.msg224335.html#msg224335

I've found the problem from @qwerty's answer:

I had a background EA Process that didn't had any Repository loaded.

Thank you all for the help.

Is there any way to get an instance of the EA.App class for all EA Processes? Or I am stuck in handling just the first opened EA instance?

5
Quote
Don't know if it helps, but C++ looks like

CLSID clsid;
CLSIDFromProgID(L"EA.App", &clsid);
IUnknown *pUnk = NULL;
IDispatch *pDisp = NULL;
HRESULT hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk); if(SUCCEEDED(hr)) {
 hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp);
}

Hi qwerty,

I've seen the c++ code in your book. I guess I can make a wrapper for that c++ code to be used in C#, but I was hoping for no workarounds, and just get a proper C# version.

6
Hi,

I am trying to open a diagram in an already opened instance of Enterprise Architect.

I've found this code in vb, in here, that gets a reference to a currently running instance of Enterprise Architect:

Dim App as EA.App
Set App = GetObject(,"EA.App")
MsgBox App.Repository.Models.Count

Does anyone have the equivalent code in C#?

I've already tryied, and failed, to use:

System.Runtime.InteropServices.Marshal.GetActiveObject("EA.App");

or

var type = System.Type.GetTypeFromProgID("EA.App");
var app = (EA.App)System.Activator.CreateInstance(type);

Both of these return a new instance instead of the existing one.

Thanks,
Doru Foaltin

7
Hi,

We have a scenario where we have to open diagrams in EA from Web Links in windows. We've implemented this by creating a launcher application that can react when a user clicks on a link in it's browser. This launcher will create an .eap file with the following content, and open it:

EAConnectString:C:\EA-Modell_Version 3.eap
OpenActions:$diagram://{1E38C463-B3F3-4f23-AE31-99FAEC99FFBA}

When this file is opened for the first time, EA will start and open the diagram with the given id.

My problem is that, when the user clicks on the link for the second time, you receive this message from EA:

The selected project is already opened!
The Desktop Version Enterprise Architect only allows single use of project files.


This also happens when the user clicks the link for the first time, but he was already working in the same file.

Is there any way to detect that an EA instance is already opened for the given file? And is there a way to just open the diagram in that instance of EA?

Regards,
Doru Foaltin.


Pages: [1]