Book a Demo

Author Topic: Change Appearance/Show Labels on Ports from Object Model  (Read 3971 times)

drjmansell

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Change Appearance/Show Labels on Ports from Object Model
« on: December 22, 2020, 09:50:42 am »
We have now hundreds of ports in a model and want to turn on the "Show Labels" option for all of them.  Can I access this from the object model?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change Appearance/Show Labels on Ports from Object Model
« Reply #1 on: December 22, 2020, 10:23:04 am »
Yes, that's possible. You need to
Code: [Select]
SELECT t_diagramobjects.Instance_ID, t_diagramobjects.ObjectStyle from t_diagramobjects
INNER JOIN t_object ON t_object.Object_ID = t_diagramobjects.Object_ID
WHERE t_object.Object_Type = "Port"
and modify objectStyle so it contains a CSV entry "HDN=1;". If there's already a HDN=0 just alter the 0 to 1 else append the afforementioned string. Then write back the change with
Code: [Select]
Repository.Exectute("UPDATE t_diagramobjects SET ObjectStyle='<modified string>' WHERE Instance_ID = <theInstanceID>"). You could also do this for only certain diagrams by including the diagramId in the SELECT statement.

q.
« Last Edit: December 22, 2020, 10:28:33 am by qwerty »

drjmansell

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Change Appearance/Show Labels on Ports from Object Model
« Reply #2 on: December 23, 2020, 02:12:02 am »
Thanks for the information!  Can this be done via the object model in a language like C#?  I notice that I don't have access to the repository.execute command, but there is a r.ExecutePackageBuildScript() function. 

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Change Appearance/Show Labels on Ports from Object Model
« Reply #3 on: December 23, 2020, 02:14:51 am »
I notice that I don't have access to the repository.execute command, but there is a r.ExecutePackageBuildScript() function.
You do, it's just not documented, so it's invisible for intellisense in VS

Geert

drjmansell

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Change Appearance/Show Labels on Ports from Object Model
« Reply #4 on: December 23, 2020, 02:47:09 am »
I think I figured it out!  Here is my code for the next person:

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Collection elements = r.GetElementSet("", 0);
                msg("Found This Many Elements: " + elements.Count.ToString());

                //make scan all elements
                int portcnt= 0;
                List<EA.Element> ports = new List<Element>();
                List<int> diagrams = new List<int>();
                for (int i = 0; i < elements.Count; i++)
                {
                    EA.Element e1 = elements.GetAt((short)i);

                    for (int j=0;j<e1.Diagrams.Count;j++)
                    {
                        try
                        {
                            EA.Diagram d = e1.Diagrams.GetAt((short)j);
                            if (!diagrams.Contains(d.DiagramID)) diagrams.Add(d.DiagramID);
                        }
                        catch (Exception ee) { msg("Error:" + ee.Message); }
                    }
                }

                //diagrams
                msg("Found Diagrams:" + diagrams.Count.ToString());
                for(int i=0;i<diagrams.Count;i++)
                {
                    EA.Diagram d = r.GetDiagramByID(diagrams);
                    string style = d.ReadStyle("Show Element Property String");
                    for(int j=0;j<d.DiagramObjects.Count;j++)
                    {
                        EA.DiagramObject do1 = d.DiagramObjects.GetAt((short)j);
                        EA.Element e2 = r.GetElementByID(do1.ElementID);
                        if (e2.Type.Contains("Port"))
                        {
                            if (do1.Style.Contains("HDN=1"))
                            {
                                string s = do1.Style;
                                s = s.Replace("HDN=1", "HDN=0");
                                do1.Style = s;
                                do1.Update();
                            }
                            else
                            {
                                string s = do1.Style;
                                if (!s.Contains("HDN=0"))
                                {
                                    s += ";HDN=0";
                                    do1.Style = s;
                                    do1.Update();
                                }
                            }
                        }
                    }
                }
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ee)
            {
                Cursor.Current = Cursors.Default;
            }



qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change Appearance/Show Labels on Ports from Object Model
« Reply #5 on: December 23, 2020, 07:54:56 am »
HDN=0 means it's NOT hidden.

q.