Book a Demo

Author Topic: Change DiagramObject Background color  (Read 4968 times)

hln

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Change DiagramObject Background color
« on: June 12, 2013, 11:59:45 pm »
I used EA_OnPostNewDiagramObject event to change BCol of DiagramObject when dragging element and dropping into diagram.
My code:
[highlight]public bool EA_OnPostNewDiagramObject(EA.Repository repository, EA.EventProperties eventProperties)
        {
            EA.EventProperty property = eventProperties.Get(0);
            EA.Diagram diagram = repository.GetCurrentDiagram();
            foreach (EA.DiagramObject dObject in diagram.DiagramObjects)
            {
                dObject.Style = "bCol=255";
                //int top = dObject.top;
                //int bottom = dObject.bottom;
                //int left = dObject.left;
                //int right = dObject.right;
                //int sequence = dObject.Sequence;
                 dObject.Update();
            }
            return true;
        }[/highlight]

My problem: BCol is changed but DiagramObject is located in incorrectly position.
Is there any way to get dropped position in this event?
Is there the best way to change BCol in my usecase?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Change DiagramObject Background color
« Reply #1 on: June 13, 2013, 12:26:37 am »
Once the object is created it should have a position. If that is not defined when EA fires the OnPostNew  event then this is a bug and should be reported.

q.

hln

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Change DiagramObject Background color
« Reply #2 on: June 13, 2013, 01:43:36 am »
Position is correct if I don't call DiagramObject.Update()

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 DiagramObject Background color
« Reply #3 on: June 13, 2013, 03:54:36 pm »
So what you are saying is that OnPostNewDiagramObject the diagramObject that you retrieve from the database has a different position then the diagramObject that is stored in the memory of EA's GUI.

The problem with diagramObjects is that their actual positions are not written to the database until you explicitly ask EA to save the diagram.

So ideally you should be able to access the DiagramObject that is used by EA's GUI to be able to get the actual correct values.

Now the problem is that you con't have access to that object. The only thing EA give you to work with is the ObjectID of the Object the DiagramObject is referencing.

So I think the only thing you can do is make sure the cached memory object of the DiagramObject is the same as the one that you retrieve from the database.
To do you you need to save the current diagram with Repository.SaveDiagram (long DiagramID) before you loop the diagram to get its diagramObjects.

So my code would look something like this:

Code: [Select]
public bool EA_OnPostNewDiagramObject(EA.Repository repository, EA.EventProperties eventProperties)
       {
           EA.EventProperty property = eventProperties.Get(0);
           EA.Diagram diagram = repository.GetCurrentDiagram();
               Repository.SaveDiagram (diagram.DiagramID);
           foreach (EA.DiagramObject dObject in diagram.DiagramObjects)
           {
                     if (dObject.ElementID == (int)property.Value)
                     {
                dObject.Style = "bCol=255";
                dObject.Update();
                        }
           }
           return true;
       }

Geert

hln

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Change DiagramObject Background color
« Reply #4 on: June 13, 2013, 04:23:50 pm »
Thanks Geert, it works