Book a Demo

Author Topic: Retrive resources c# add-in doesn't work.  (Read 3340 times)

Roberto_il_vecchio

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Retrive resources c# add-in doesn't work.
« on: November 28, 2014, 12:50:25 am »
in my c# extension there is the code;
        MessageBox.Show(Repository.Resources.Count.ToString(),"Resources");
      foreach (EA.IDualResource res in Repository.Resources ) {
            MessageBox.Show( res.Name);
      }

and running i get the message that the count is 0. then

From Setting | Project types | People Tab= Resources, I create a resourece with the role inside the role list
In this way I get the message with the count of 1, but then the error:
Unable to cast COM object of type "System._ComObject' to inteface type "EA.IDualResource"
(i get the error with EA.Resource)

How can i retrive it, in a exstension?

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Retrive resources c# add-in doesn't work.
« Reply #1 on: November 28, 2014, 09:40:11 am »
Repository.Resources is a collection of type EA.ProjectResource.  EA.Resource (IDualResource) is used for assignment of a resource to an Element (Element.Resources).

Try changing your code to:

Code: [Select]
foreach (EA.ProjectResource res in repository.Resources)

Roberto_il_vecchio

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Retrive resources c# add-in doesn't work.
« Reply #2 on: November 28, 2014, 06:48:26 pm »
Thank you! It's workshttp://www.sparxsystems.com/yabbfiles/Templates/Forum/default/smiley.gif