Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: pdrane on January 29, 2015, 12:41:50 am

Title: AddNew ConveyedItems Collection for a  Connector
Post by: pdrane on January 29, 2015, 12:41:50 am
I am trying to add and new item to the ConveyedItems collection for a connector does anyone know the VB code for this
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: Tomasz on January 29, 2015, 01:09:22 am
It's C# code:

EA.Connector newConnector = yourElement.Connectors.AddNew("", "Association");//or other types ass "Collaboration" etc.
newConnector.ConveyedItems.AddNew("", "");

( in VB it should be almost the same)
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: qwerty on January 29, 2015, 01:48:07 am
He wants to add a conveyed item, not a new connector. There are several threads with SQL how to find conveyed items. That should give you a clue how to create them.

q.
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: pdrane on January 29, 2015, 02:46:18 am
I can list all the ConveyedItems and get the corresponding element details but I can't find any documentation to for the ConveyedItems.AddNew ("?","?") the only reference I found said used ElementGUID, NULL which isn't the right type for AddNew. Has anyone added new ConveyedItems via code instead of the UI
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: Aaron B on January 29, 2015, 04:29:47 pm
To add a conveyed item to a connector via automation, you need to call AddNew() on the Connector.ConveyedItems.  The first parameter must be the ElementGUID for the EA.Element which is to be referenced as a conveyed item.

E.g.
  Set Connector = [reference to an InformationFlow connector]
  Set Element = [reference for Element to be conveyed]
  Connector.ConveyedItems.AddNew Element.ElementGUID, ""
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: pdrane on January 29, 2015, 08:03:07 pm
Quote
To add a conveyed item to a connector via automation, you need to call AddNew() on the Connector.ConveyedItems.  The first parameter must be the ElementGUID for the EA.Element which is to be referenced as a conveyed item.

E.g.
  Set Connector = [reference to an InformationFlow connector]
  Set Element = [reference for Element to be conveyed]
  Connector.ConveyedItems.AddNew Element.ElementGUID, ""


Thanks I was almost there  :) It now works thanks to your clarity
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: JacekSalamandra on February 27, 2015, 08:36:58 pm
How can i retreive all “Information Items Convedyed” for selected “InformationFlow”? I use "Find in project" sql editor feature.
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: qwerty on February 27, 2015, 11:28:31 pm
From my Inside book (once provided by Helmut Ortmann):


Code: [Select]
SELECT DISTINCT o.ea_guid as CLASSGUID, o.Object_Type as CLASSTYPE,
  o.name As Item, o.Object_Type As ItemType,
  o.stereotype As 'ItemStereotype', "Connector" As ConnectorType,
  c.Name, c.Stereotype
 
FROM t_object o, t_xref xCon, t_xref xFlow, t_connector c, t_connector flow

WHERE
  c.connector_ID = <Search Term> AND c.ea_guid = xCon.Client AND
  flow.ea_guid = xFlow.client AND xCon.Behavior = 'abstraction' AND
  flow.ea_guid IN (
#DB=SQLSVR#s
  substring(x.description,0,39),
  substring(xCon.description,39,39),
  substring(xCon.description,78,39),
  substring(xCon.description,117,39),
  substring(xCon.description,156,39),
  substring(xCon.description,195,39),
  substring(xCon.description,234,39),
  substring(xCon.description,273,39),
  substring(xCon.description,312,39),  
  substring(xCon.description,351,39)
#DB=SQLSVR#    
#DB=Other#
  left(xCon.description,38),
  mid(xCon.description,40,38),
  mid(xCon.description,79,38),
  mid(xCon.description,118,38),
  mid(xCon.description,157,38),
  mid(xCon.description,196,38),
  mid(xCon.description,235,38),
  mid(xCon.description,274,38),
  mid(xCon.description,313,38),  
  mid(xCon.description,352,38)
#DB=Other#  
) AND o.ea_guid IN (
#DB=SQLSVR#s
  substring(x.description,0,39),
  substring(xCon.description,39,39),
  substring(xCon.description,78,39),
  substring(xCon.description,117,39),
  substring(xCon.description,156,39),
  substring(xCon.description,195,39),
  substring(xCon.description,234,39),
  substring(xCon.description,273,39),
  substring(xCon.description,312,39),  
  substring(xCon.description,351,39)
#DB=SQLSVR#    
#DB=Other#
  left(xCon.description,38),
  mid(xCon.description,40,38),
  mid(xCon.description,79,38),
  mid(xCon.description,118,38),
  mid(xCon.description,157,38),
  mid(xCon.description,196,38),
  mid(xCon.description,235,38),
  mid(xCon.description,274,38),
  mid(xCon.description,313,38),  
  mid(xCon.description,352,38)
#DB=Other#  
)

UNION
SELECT DISTINCT o.ea_guid , o.Object_Type ,
  o.name,  o.Object_Type, o.stereotype, "Information Flow",
  c.Name, c.Stereotype
 
FROM t_object o, t_xref x, t_connector c

WHERE
  x.client = c.ea_guid AND
  x.Behavior = 'conveyed' .and
  c.connector_ID = <Search Term> .and
  o.ea_guid IN (
#DB=SQLSVR#s
  substring(x.description,0,39),
  substring(xCon.description,39,39),
  substring(xCon.description,78,39),
  substring(xCon.description,117,39),
  substring(xCon.description,156,39),
  substring(xCon.description,195,39),
  substring(xCon.description,234,39),
  substring(xCon.description,273,39),
  substring(xCon.description,312,39),  
  substring(xCon.description,351,39)
#DB=SQLSVR#    
#DB=Other#
  left(xCon.description,38),
  mid(xCon.description,40,38),
  mid(xCon.description,79,38),
  mid(xCon.description,118,38),
  mid(xCon.description,157,38),
  mid(xCon.description,196,38),
  mid(xCon.description,235,38),
  mid(xCon.description,274,38),
  mid(xCon.description,313,38),  
  mid(xCon.description,352,38)
#DB=Other#  
)

order by 3,4,5

To create the script follow these steps:
• Open the scripting window via View/Scripting.
• Create a new normal group (left icon) and name it e.g. ‘Searches’.
• Add a new VB script (2nd icon) and name it e.g. ‘Information Flow’.
• Double click the new entry to open the editor.
• Copy/Paste the following script into the editor and save the result (the famous diskette5
symbol).
Now when you select the appropriate connector in a diagram just click the run button (4th icon) to execute the script. This will open the search window with the listed resulting conveyed classes.

Code: [Select]
option explicit

!INC Local Scripts.EAConstants-VBScript

sub main()
  dim selectedConnector as EA.Connector
  set selectedConnector = Repository.GetContextObject()

  if selectedConnector is nothing OR
     selectedConnector.ObjectType <> otConnector then
    Session.Prompt "You must select an Information Flow", promptOK
    exit sub
  end if
  dim id
  id = CStr(selectedConnector.ConnectorID)
  Repository.RunModelSearch "Elements on Flow", id, "", ""
end sub

main()
q.
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: Aaron B on March 02, 2015, 10:04:57 am
Or if you are trying to get the conveyed items from a script you could just loop over the Connector.ConveyedItems collection.

Code: [Select]
if theConnector.Type = "InformationFlow" then
      dim conveyedList, i
      
      conveyedList = ""
      
      for i = 0 to theConnector.ConveyedItems.Count - 1
            dim conveyed as EA.Element
            set conveyed = theConnector.ConveyedItems.GetAt(i)
            if Len(conveyedList) > 0 then
                  conveyedList = conveyedList & ", "
            end if
            conveyedList = conveyedList & conveyed.Name
      next
      
      Session.Output "ConveyedItems(" & theConnector.ConveyedItems.Count & ") = { " & conveyedList & " }"
end if
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: JacekSalamandra on March 02, 2015, 11:04:38 pm
Thanks for your replies.
Quote
substring(x.description,0,39),
 substring(xCon.description,39,39)
Shouldn't be only xCon or x in all rows in IN() block?

What if conveyed items is more than e.g.20?
SQL statement return only first 10 items.

VB script seems return all items.

My aim is to create rerport with column Source"."Destination","InformationItemConveyed (DataObject)" for all InformationFlow in selected Package.
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: qwerty on March 02, 2015, 11:29:29 pm
GUIDs have a fixed length so you can use the simple substring. The approach is a compromise. If you want to list all items you need to create an add-in search that uses the API (like Aaron's approach) to return the items as search result.

q
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: JacekSalamandra on March 04, 2015, 12:03:49 am
Is there any simple (I mean witout iteration) way to get a collection of all connectors in a particular package (and subpackages)  from script?
My packages have subpackages, they have own subpackages and so on.
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: Geert Bellekens on March 04, 2015, 01:39:17 am
In theory that should be possible if you use SQL.
The problem with SQL is that is is nearly impossible to write recursive queries.
So probably the fastest way is to write a query that goes a predefined levels deep.
Based on that query you can get the connectors by their ID.

If you search the forum (using top left button) you should find some topic where I posted code for such a query.
Here's one example: http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1285136675/9#9

Geert
Title: Re: AddNew ConveyedItems Collection for a  Connect
Post by: JacekSalamandra on March 24, 2015, 07:44:03 pm
Thank you for your answers. Finally, I used the following script. It is slow but can quite simple to understand and maintain.
Quote
!INC Local Scripts.EAConstants-JScript

/*
 * Script Name:
 * Author: JacekSalamandra
 * Purpose:
 * Date:
 */
 
 function isInArray(ar,value){
 for (var k=0;k<ar.length;k++){
       if (ar[k]==value) return true;
       }
       return false;
       }

function main()
{      
      // start=Date();
      // Session.Output("Start "+start ) ;
      Session.Output("Connector_ID;Type;Direction;Source;Target;Notes;ConveyedItemsCount;ConveyedItem"); // Headers
      var tablica = [];
      var elements as EA.Collection ;
      sql="SELECT * FROM t_object where "
      +" Object_ID in (select Start_Object_Id from t_connector where Connector_Type in ('InformationFlow') ) "
      +" OR "
      +" Object_ID in (select End_Object_Id from t_connector where Connector_Type in ('InformationFlow') ) "
      elements=Repository.GetElementSet(sql,2) ;

      for (var i=0; i<elements.Count; i++) {
            for (var j=0; j<elements.GetAt(i).Connectors.Count; j++) {
                  connectorID = elements.GetAt(i).Connectors.GetAt(j).ConnectorID;
                  if ( (elements.GetAt(i).Connectors.GetAt(j).Type=="InformationFlow") && (isInArray(tablica,connectorID)==false ) ){
                        sqlSuppiler= "SELECT Object_ID,Name FROM t_object where Object_ID=" + elements.GetAt(i).Connectors.GetAt(j).SupplierID;
                        sqlClient="SELECT Object_ID,Name FROM t_object where Object_ID=" + elements.GetAt(i).Connectors.GetAt(j).ClientID;
                        type = elements.GetAt(i).Connectors.GetAt(j).Type;
                        direction = elements.GetAt(i).Connectors.GetAt(j).Direction;
                        source = Repository.GetElementSet(sqlClient,2).GetAt(0).Name;
                        target = Repository.GetElementSet(sqlSuppiler,2).GetAt(0).Name;
                        notes = elements.GetAt(i).Connectors.GetAt(j).Notes;
                        conveyedItemsCount = elements.GetAt(i).Connectors.GetAt(j).ConveyedItems.Count;                                    
                        if (elements.GetAt(i).Connectors.GetAt(j).ConveyedItems.Count==0)      {
                              Session.Output(connectorID +";"+type +";"+direction +";"+source +";"+target+";"+notes+";"+conveyedItemsCount);
                              tablica.push(connectorID);
                        }
                              else {
                                    for (var k=0; k<elements.GetAt(i).Connectors.GetAt(j).ConveyedItems.Count;k++)      {
                                    Session.Output(connectorID +";"+type +";"+direction +";"+source +";"+target+";"+notes+";"+conveyedItemsCount+";"+elements.GetAt(i).Connectors.GetAt(j).ConveyedItems.GetAt(k).Name);
                                    tablica.push(connectorID);                                          
                                    }                                    
                              }
                  }
            }
      }
      end=Date();
      // Session.Output("Table size "+tablica.length);
      // Session.Output("End "+ end + "(start:"+start+" )" ) ;
}
main();