Book a Demo

Author Topic: Open an elements properties dialog  (Read 5275 times)

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Open an elements properties dialog
« on: October 17, 2013, 02:53:21 am »
Hi,

I've got a vbscript in Sparx that creates an element. I then want to open its properties dialog so the user can populate some tagged values...Can this be done via scripting ? If so how ?

Thanks,

Jon.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Open an elements properties dialog
« Reply #1 on: October 17, 2013, 05:51:10 am »
Use Repository.CustomCommand. I copy/paste from my Scripting book without reformatting (especially the last table):
Quote
In order to open some of the property dialogues in EA you can use this method. To actually do that it is necessary to get hold of the windows handle of the EA application. Unfortunately I can not go into details on how to do that. So in the following examples I simply assume thathwnd holds the number that represents this special handle.

To distinguish between the different property dialogues the CustomCommand uses an identification string (here dlg).

xmlres =
          Respository.CustomCommand(
            "CFormCommandHelper", "ProcessCommand",
            "Dlg=" + dlg + ";id=" + id + ";hwnd=" + hwnd);

Depending ondlg theid parameter must be supplied: dlg id
PKG EaPackage.PackageID ELM EaElement.ElementID ATT EaAttribute.AttributeID OP EaMethod.MethodID
DGM EaDiagram.DiagramID

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Open an elements properties dialog
« Reply #2 on: October 17, 2013, 05:05:23 pm »
Here's the interesting bit from the code in my framework, from the class Model.cs

Code: [Select]
/// <summary>
        /// opens the properties dialog for this item
        /// </summary>
        /// <param name="item">the item to open the properties dialog for</param>
        public void openProperties(UML.UMLItem item)
        {
                //get the type string
                string typeString = string.Empty;
                int itemID = 0;
                if (item is Package)
                {
                        typeString = "PKG";
                        itemID = ((Package)item).packageID;
                }
                else if (item is ElementWrapper)
                {
                        typeString = "ELM";
                        itemID = ((ElementWrapper)item).id;
                }
                else if (item is Attribute)
                {
                        typeString = "ATT";
                        itemID = ((Attribute)item).id;
                }
                else if (item is Operation)
                {
                        typeString = "OP";
                        itemID = ((Operation)item).id;
                }
                else if (item is Diagram)
                {
                        typeString = "DGM";
                        itemID = ((Diagram)item).DiagramID;
                }
// TODO: figure out how to open the properties dialog for a connector.        
//                else if (item is ConnectorWrapper)
//                {
//                        //typeString = "CON";
//                        typeString = "MSG";
//                        itemID = ((ConnectorWrapper)item).id;
//                }
                //open the actual dialog
                if (this.mainEAWindow != null
                    && typeString != string.Empty
                    && itemID != 0)
            {
                        string ret = this.wrappedModel.CustomCommand("CFormCommandHelper", "ProcessCommand", "Dlg=" + typeString + ";id=" + itemID.ToString() + ";hwnd=" + this.mainEAWindow.Handle);
            }
        }

And the bit to get to the main EA windows handle:
Code: [Select]
   /// <summary>
    /// the main EA window to use when opening properties dialogs
    /// </summary>
    public IWin32Window mainEAWindow
    {
            get
            {
                    if //(true)
                            (this._mainEAWindow == null)
                    {
                            List<Process> allProcesses = new List<Process>( Process.GetProcesses());
                                   Process proc = allProcesses.Find(pr => pr.ProcessName == "EA");
                             //if we don't find the process then we set the mainwindow to null
                                   if (proc == null
                                       || proc.MainWindowHandle == null)
                             {
                                     this._mainEAWindow = null;
                             }
                             else
                             {
                                     //found it. Create new WindowWrapper
                                     this._mainEAWindow  = new WindowWrapper(proc.MainWindowHandle);
                             }
                    }
                     return this._mainEAWindow;
            }
    }

This code is used by the EA Navigator to open the properties of an item.

Geert

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: Open an elements properties dialog
« Reply #3 on: October 17, 2013, 07:03:58 pm »
Hi,

Many thanks for the help.

Regards,

Jon.