Ok!
Sorry about the funky indenting in the code below. It's not the way I entered it, it's just the way it's displaying.
Here's one way that compiles and runs.
Data doesn't get changed.
Syntax gleaned from the sample cs automation file.
Same results with or without the commented out lines:
void SetAuthorElements(EA.Package Package)
{
for( short idx = 0; idx < Package.Elements.Count; idx++ )
{
if (((EA.Element)Package.Elements.GetAt(idx)).Type
== "Requirement"
)
{
ListAdd(((EA.Element)Package.Elements.GetAt(idx)).Name );
ListAdd(((EA.Element)Package.Elements.GetAt(idx)).Author);
((EA.Element)Package.Elements.GetAt(idx)).Author
= "John Doe";
// ((EA.Element)Package.Elements.GetAt(idx)).Update();
// ((EA.Element)Package.Elements.GetAt(idx)).Refresh();
ListAdd(((EA.Element)Package.Elements.GetAt(idx)).Author);
}
}
}
Here's an attempt to cast it into a RequirementClass object.
Why? If nothing else, once I cast it I don't have to type all the mess above just to reference something! Plus, the above approach didn't work, so...
void SetAuthorElements(EA.Package Package)
{
// Won't compile.
//EA.RequirementClass rc = new EA.RequirementClass();
EA.RequirementClass rc; // will try this instead.
for( short idx = 0; idx < Package.Elements.Count; idx++ )
{
if (((EA.Element)Package.Elements.GetAt(idx)).Type
== "Requirement")
{
ListAdd(((EA.Element)Package.Elements.GetAt(idx)).Name );
ListAdd(((EA.Element)Package.Elements.GetAt(idx)).Author);
rc = (EA.RequirementClass)Package.Elements.GetAt(idx);
ListAdd(Indent + rc.Name);
//ListAdd(Indent + rc.Author); // Won't compile.
// Will worry about changing something later!
}
}
}
The above blows up with a "Specified cast is not valid." error message.
Oddly, it also blows up if I try to cast it to an ElementClass, which I thought out to work since it can cast to the Element interface.
Now, I'm also new to C#, so it's certainly possible I'm doing a "stupid newbie" trick for God and everybody to laugh at.