Book a Demo

Author Topic: How to access element in Diagram.selectedObjects  (Read 4410 times)

pdelporte

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
How to access element in Diagram.selectedObjects
« on: July 09, 2007, 03:09:03 am »
I am writing an add-in to be able to change the status of selected elememts in a diagram. I can easly see the number of selected elements, but I cannot get a reference to the selected elements in order to change some of their attributes.

Does anyone know how I can access those elements ?

Code: [Select]

prj = Repository.GetProjectInterface();
// get the selected package

EA.Diagram diagram = Repository.GetCurrentDiagram();

// What type of object should I use instead of Object obj ?
foreach (Object obj in diagram.SelectedObjects)
{
  // the following convetion does not work !!!
  EA.Element elem = (EA.Element)obj;
  Console.WriteLine(elem.Name);
                       
}


Thx,
Pierre

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to access element in Diagram.selectedObjec
« Reply #1 on: July 09, 2007, 03:17:26 am »
Pierre,

Perhaps you need to work your way down the reference 'chain' from the selected object to the element it represents.

I believe the SelectedObjects call returns a list of DiagramObjects, not a list of elements.

David
No, you can't have it!

pdelporte

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: How to access element in Diagram.selectedObjec
« Reply #2 on: July 09, 2007, 03:35:43 am »
Great, I found the solution :

Code: [Select]

prj = Repository.GetProjectInterface();
// get the selected package

EA.Diagram diagram = Repository.GetCurrentDiagram();

foreach (EA.DiagramObject dObj in diagram.SelectedObjects)
{
  EA.Element elem = Repository.GetElementByID(dObj.ElementID);
  Console.WriteLine(elem.Name);
                       
}


Thx for the quick help.

Yours,
Pierre

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to access element in Diagram.selectedObjec
« Reply #3 on: July 09, 2007, 03:39:47 am »
Yes Pierre,

That's just what I was thinking. Thanks for the feedback; it helps everyone to know the solutions that work.

David
No, you can't have it!