Book a Demo

Author Topic: Import text of linked URL into element note  (Read 2987 times)

JoGo

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Import text of linked URL into element note
« on: September 08, 2008, 05:04:56 pm »
Hi.  I'd like to write a c# program that will iterate through all the elements in a diagram.  if the element contains 1 (or more) files (and the 1st file is of type Web Address, then the program will UPDATE THE ELEMENT NOTE TO BE THE SAME AS THE WEB ADDRESS. [in fact ultimately the program will open and parse teh web address, get the relevant text and update the element note to that - that's my own challenge tho.]


thoughts?

Eric Johannsen

  • EA User
  • **
  • Posts: 43
  • Karma: +0/-0
  • Model Driven Business[ch0174]
    • View Profile
Re: Import text of linked URL into element note
« Reply #1 on: September 11, 2008, 10:17:20 am »
I just wrote this code without testing it (what's the saying... "that is left as an exercise to the reader") :-) but this should be pretty close to what you want:

Code: [Select]
private void IterateDiagram(EA.Repository rep, EA.Diagram diag)
{
    foreach (EA.DiagramObject diagObj in diag.DiagramObjects)
    {
        EA.Element elem = rep.GetElementByID(diagObj.ElementID);

        StringBuilder sb = new StringBuilder();
        foreach (EA.File file in elem.Files)
        {
            if (file.Type == "Web Address")
            {
                // You need to provide GetAddressContent()
                sb.AppendLine(GetAddressContent(file.Name));
            }
        }
        if (sb.Length > 0)
        {
            // Found at least one
            elem.Notes = sb.ToString();
            elem.Update();
        }
    }
}