Book a Demo

Author Topic: Programmatically setting up a Timeline diagram  (Read 4869 times)

OrenBM

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Programmatically setting up a Timeline diagram
« on: August 28, 2014, 08:04:13 pm »
Hi,

I'm trying to find a way for a script (JScript) to create a Timing / Timeline diagram by adding a class to it much as I would manually.  Does anyone know how I can mimic a user activity for this type of scenario?

So when I drag a class on to a diagram I get the choice as to object and what it's timing events might be.

Many thanks
Aklobem

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Programmatically setting up a Timeline diagram
« Reply #1 on: August 28, 2014, 08:33:44 pm »
You'll have to add a DiagramObject and set its's elementID to the class or object you want to use.
Then you'll have to figure out where EA stores the choice of timing events.

The best way to figure that out is to start with an empty model, create the absolute minimum for your scenario and then inspect the database.

I would start with t_diagramObjects

When you know how EA stores it you can do the same in your script either by editing the attributes of your API objects, or if the property is not available, by directly updating the database.

Here's an example of how I add an element to a diagram in my framework: https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/Diagram.cs
        
Code: [Select]
       /// <summary>
        /// adds an element to the diagram
        /// </summary>
        /// <param name="element">the element to add</param>
        /// <returns>the new diagramElement</returns>
            public UML.Diagrams.DiagramElement addToDiagram(UML.Classes.Kernel.Element element)
            {
                  UML.Diagrams.DiagramElement diagramElement = null;
                  //first check whether this element is not already added to this diagram
                  diagramElement = this.diagramObjectWrappers.FirstOrDefault(x=> x.element.Equals(element));
                  if (diagramElement == null)
                  {
                        if (element is EA.ElementWrapper)
                        {
                              //first save the diagram to make sure we don't loos any unsaved changes
                              this.model.saveOpenedDiagram(this);
                              global::EA.DiagramObject newDiagramObject = this.wrappedDiagram.DiagramObjects.AddNew("","") as global::EA.DiagramObject;
                              diagramElement = ((Factory)this.model.factory).createDiagramElement(newDiagramObject) ;
                              diagramElement.element = element;
                              //save the element diagramObject
                              ((DiagramObjectWrapper)diagramElement).save();
                              // now refresh to make sure we see the new element on the diagram
                              this.reFresh();
                        }

                        else if (!(element.owner is UML.Classes.Kernel.Package))
                        {
                              diagramElement = this.addToDiagram(element.owner);
                        }
                  }
                  return diagramElement;
            }

Geert

OrenBM

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Programmatically setting up a Timeline diagram
« Reply #2 on: August 29, 2014, 05:38:02 am »
Hi Geert,

Thanks, I'll give it a go - I was wondering if there is a method within the API that is available.  

I'll work through the DB in the meantime and see where I get to.  

Much appreciated.


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Programmatically setting up a Timeline diagram
« Reply #3 on: August 29, 2014, 03:52:53 pm »
Quote
Hi Geert,

Thanks, I'll give it a go - I was wondering if there is a method within the API that is available.  

I'll work through the DB in the meantime and see where I get to.  

Much appreciated.

Usually there aren't many "functional" methods available in the API. It is not much more then a thin layer on top top the database.
So if you are lucky then you edit whatever property you need using the API, but quite often, certainly if it concerns rather exotic parts of UML, you'll need to resort to editing the database directly (use the hidden operation Repository.Execute(SQLUpdateString))

Geert

OrenBM

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Programmatically setting up a Timeline diagram
« Reply #4 on: August 30, 2014, 09:21:56 pm »
Hi,

Thanks for the feedback - appreciated.  If that's the case - and I get that - is there a data model published anywhere?  This timeline business is not exactly simple - it appears that a new element is generated for the diagram - a timeline element as an instance of the parent - so trying to co-relate elements to timeline instances and then generating additional ones seems a bit hit or miss... is there anywhere that I should be looking for insight?

Regards

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Programmatically setting up a Timeline diagram
« Reply #5 on: August 31, 2014, 01:08:50 am »
You need to stick to my Inside book. Sparx (for understandable reason) did not publish the internals though their API has an official method (SQLquery) to access the database model.

q.