Trouble with script & multiple elements

132 views
Skip to first unread message

motivatedgorilla

unread,
Feb 13, 2014, 3:06:00 PM2/13/14
to sparx-enterprise-archite...@googlegroups.com
I have the script below that works well for defining a relationship for a single element however I need to loop through a SQL query for all elements that the source element links to however am unsure how to do so. Can someone please help?


Code:
var selectedPackage as EA.Package;
    selectedPackage = Repository.GetTreeSelectedPackage();

    Repository.EnsureOutputVisible( "Script" );
    Session.Output( "JScript ConnectorExample" );
    Session.Output( "=======================================" );
         
    if ( selectedPackage != null )
    {
          // Create client and supplier classes under the selected package
          var client as EA.Element;
          var supplier as EA.Element;
          var clientID, supplierID;
         
              client= Repository.GetElementByID(9675)
              client.Update();
              supplier = Repository.GetElementByID(9676)
              supplier.Update();
           
              clientID = 9675;
          supplierID = 9676;

          selectedPackage.Elements.Refresh();
         
          // Get the connectors collection on the client element
          var connectors as EA.Collection;
          connectors = client.Connectors;
         
          // Create a new connector and set the appropriate details
          var c as EA.Connector;
          c = connectors.AddNew( "", "Realization" );

          c.ClientID = clientID;
          c.SupplierID = supplierID;
          c.Direction( "Source -> Destination" );

         
          // Save the connector!
          c.Update();
    }
    else
    {
          Session.Prompt( "No package selected!", 0 );
    }
   
    Session.Output( "Done!" );

[original message]

qwerty

unread,
Feb 13, 2014, 3:28:00 PM2/13/14
to sparx-enterprise-archite...@googlegroups.com
You don't need SQL in that case. Just iterate through SourceElem.Connectors and find Repository.GetElementByID(Connector.SupplierID) (or .ClientID depending how your connectors are oriented).

q.

[original message]

motivatedgorilla

unread,
Feb 13, 2014, 5:18:00 PM2/13/14
to sparx-enterprise-archite...@googlegroups.com
That's what I am unsure i.e. iterating through the connectors. Do you have an example?
[original message]

qwerty

unread,
Feb 14, 2014, 7:42:00 AM2/14/14
to sparx-enterprise-archite...@googlegroups.com
I'm no JScripter but
Code:
con = Elem.Connectors.GetAt(0);
e1 = Repository.GetElementByID(con.ClientID);
should work.

q.

[original message]

motivatedgorilla

unread,
Feb 13, 2014, 8:19:00 PM2/13/14
to sparx-enterprise-archite...@googlegroups.com

707664737578010 wrote:
I'm no JScripter but
Code:
con = Elem.Connectors.GetAt(0);
e1 = Repository.GetElementByID(con.ClientID);
should work.

q.


Thanks qwerty. I'm not wanting to iterate through the connectors. I want to iterate through an array e.g. var testdestination = [9676,1234,9899]; which would then feed into Repository.GetElementByID(testdestination[i])
[original message]

qwerty

unread,
Feb 14, 2014, 5:14:00 AM2/14/14
to sparx-enterprise-archite...@googlegroups.com
Hm. Then what is the issue?

q.

[original message]

motivatedgorilla

unread,
Feb 16, 2014, 1:24:00 PM2/16/14
to sparx-enterprise-archite...@googlegroups.com

6F697B6C6A671E0 wrote:
Hm. Then what is the issue?

q.


The issue is supplier = Repository.GetElementByID(testdestinationelement[i]);. I get an "Internal application" error despite the value being an integer.
[original message]

qwerty

unread,
Feb 16, 2014, 2:36:00 PM2/16/14
to sparx-enterprise-archite...@googlegroups.com
Hmm. That could have a couple of reasons. Have you tried with supplying a simple integer. And then by first passing the array contents to an integer before passing that to the Get method?

q.

[original message]

motivatedgorilla

unread,
Feb 16, 2014, 2:48:00 PM2/16/14
to sparx-enterprise-archite...@googlegroups.com

6F697B6C6A671E0 wrote:
Hmm. That could have a couple of reasons. Have you tried with supplying a simple integer. And then by first passing the array contents to an integer before passing that to the Get method?

q.


Yes. I was able to resolve the issue although it makes no sense. I needed to include quotation marks around the integer in the array e.g. "2".

[original message]

qwerty

unread,
Feb 16, 2014, 2:56:00 PM2/16/14
to sparx-enterprise-archite...@googlegroups.com
The values are some Win32 objects (variants). No idea how to create a dedicated integer in your language, but coercing from a nice string seems to work then.

q.

[original message]

motivatedgorilla

unread,
Feb 16, 2014, 3:12:00 PM2/16/14
to sparx-enterprise-archite...@googlegroups.com

585E4C5B5D50290 wrote:
The values are some Win32 objects (variants). No idea how to create a dedicated integer in your language, but coercing from a nice string seems to work then.

q.


What do you mean by "The values are some Win32 objects (variants)"?
[original message]

qwerty

unread,
Feb 16, 2014, 6:05:00 PM2/16/14
to sparx-enterprise-archite...@googlegroups.com
Maybe I was mislead by he way it's treated in Perl where the arguments are passed via Win32 OLE objects (variants). In Perl it does not matter whether you use a string or a number. Both will be converted the right way. But IIRC the parameters are generally passed as objects, not as primitives. To be honest, I'm not very sure how parameters are passed to the API of EA.

q.

[original message]
Reply all
Reply to author
Forward
0 new messages