Book a Demo

Author Topic: How to change the size of an element in a diagram  (Read 4598 times)

patson

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
How to change the size of an element in a diagram
« on: April 18, 2010, 07:00:19 am »
Hi
I created (in C# using Automation Interface) a diagram and added an element on this diagram. Now I want to change the position and the size of this element in the diagram view. I try unsucessfully to do it with the Attribute Bottom, Top, Right and Left of the class DiagramObjets.
Somebody can help me please!
Regards

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to change the size of an element in a diag
« Reply #1 on: April 19, 2010, 04:33:39 pm »
Did you remember to call update() on both the diagramObject as the Diagram?

Geert

MagnusH

  • EA User
  • **
  • Posts: 63
  • Karma: +0/-0
    • View Profile
Re: How to change the size of an element in a diag
« Reply #2 on: April 19, 2010, 10:25:23 pm »
Hi,

This code works for me (in Perl but it's almost the same...)
Code: [Select]
   my $Fix = Win32::GUI::MessageBox(0, "Do you want to update the size of the selected element?", "Info", 4);
    if ($Fix eq 6)
    {
      $DiagramObject->{Top} = int($self->DOTopTextField()->Text());
      $DiagramObject->{Bottom} = int($self->DOBottomTextField()->Text());
      $DiagramObject->{Left} = int($self->DOLeftTextField()->Text());
      $DiagramObject->{Right} = int($self->DORightTextField()->Text());
      $DiagramObject->Update();
      $Diagram->{DiagramObjects}->Refresh();
      # Reload diagram
      $self->EAApp()->Repository()->ReloadDiagram($Diagram->{DiagramID});
    }    

As Geert wrote you should call update but I also call Refresh on the DiagramObjects collection. I don't know if this is necessary. And after that reload the diagram.

// Magnus

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to change the size of an element in a diag
« Reply #3 on: April 19, 2010, 10:35:59 pm »
Quote
As Geert wrote you should call update but I also call Refresh on the DiagramObjects collection. I don't know if this is necessary. And after that reload the diagram.

// Magnus

The refresh() is only necesarry if add or remove elements to the DiagramObjects collection, and you need the diagram.DiagramObjects collection later on.

Geert

patson

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: How to change the size of an element in a diag
« Reply #4 on: April 20, 2010, 06:05:16 am »
Hi,
Thanks for the answer. I do the same things as Magnus but it does´nt work.
After the execution the both class joeClass1 and joeClass2 appear at the same position in the diagram view. I want to change the size of one class.

Here is my code in C#.


                    Object obj2 = collectionElements.GetByName("joeClass1");
                    Object obj3 = collectionElements.GetByName("joeClass2");

                    EA.Element element2 = (EA.Element)obj2;
                    EA.Element element3 = (EA.Element)obj3;

                    EA.Collection collectionDiagramObjects = diagram1.DiagramObjects;
                    Object obj4 = collectionDiagramObjects.AddNew("", "");
                    EA.DiagramObject dobj2 = (EA.DiagramObject)obj4;
                    dobj2.bottom = 2 * dobj2.bottom;
                    dobj2.right = 2 * dobj2.right;
                    dobj2.ElementID = element2.ElementID;
                    if(!dobj2.Update())
                    {
                        MessageBox.Show("Error");
                        return;
                    }
                    collectionDiagramObjects.Refresh();


                    Object obj5 = collectionDiagramObjects.AddNew("", "");
                    EA.DiagramObject dobj3 = (EA.DiagramObject)obj5;
                    dobj3.ElementID = element3.ElementID;

                    if (!dobj3.Update())
                    {
                        MessageBox.Show("Error");
                        return;
                    }
                    collectionDiagramObjects.Refresh();

                    Repository.OpenDiagram(diagram1.DiagramID);


patson

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: How to change the size of an element in a diag
« Reply #5 on: April 20, 2010, 06:59:54 am »
I have found it.
When I have to add an existing element in a new diagram and then change the size of this element in the diagram, I have to change at first the size of the existing element before adding it to the collectionDiagramObjects.
Thanks for our Help
pat