Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Geert Bellekens

Pages: 1 ... 477 478 [479] 480 481 ... 560
7171
That's because ActivityInitial is not a valid object type.

it should be a StateNode, and you should then set it's subtype to indicate that it is an initial node.

Try this (untested)
Code: [Select]
' ID 1117 below belongs to an activitydiagram
sub main
      dim dgm as EA.Diagram
      set dgm = Repository.GetDiagramByID(1117)
      
      dim pck as EA.Package
      set pck = Repository.GetPackageByID(dgm.PackageID)
      
      dim elt as EA.Element
'      set elt = pck.Elements.AddNew("MyAction","Action")
      set elt = pck.Elements.AddNew("Start","StateNode")
        elt.Subtype = 100 'for ActivityInitial
      elt.Update()
      
      dim dgmObject as EA.DiagramObject
      set dgmObject = dgm.diagramObjects.AddNew( "", "" )
      dgmObject.ElementID( elt.ElementID )
      dgmObject.Update()

end sub

Geert

7172
There's indeed no security permission for scripting.

On the other had you should consider that you will never be able to stop malicious users from doing something wrong with the model.

If they are savvy enough to know how to use the scripting in EA you won't  stop them by disabling it. Then they would just write an add-in, or an external script. Hell, you can even use Excell's built-in VBA editor to access EA and execute scripts :o.

So all you can do is politely ask people to behave according to the rules, (and use version control and backups in case that backfires ;D)

If on the other hand you want people to only have read-only access, you should indeed use EA-Lite, but most importantly, use a "real" database and set the security on the database level.

Geert

7173
I don't think there's something to export that baseline, but if you would export the package to xmi, wouldn't that have the same endresult?

If not, there have been a couple of posts lately about exporting/importing baselines. It includes getting the blob from t_document, base64 decoding, and then unzipping it.


Geert

7174
Automation Interface, Add-Ins and Tools / Re: Adding new DB interface
« on: October 15, 2012, 06:38:04 pm »
Look into MDG technologies and Code Generation Templates.

Geert

7175
Danny,

In case of sequence diagrams, it works differently then with regular diagrams.

For sequence diagrams you need to set the diagramID on the connector to determine on which diagram it shows.

For all other diagrams, if both the source and the target element are shown on a diagram EA will automatically show every connector between those two on the diagram. (unless you specifically hide it)

Geert

7176
You have to add connectors to either the source or the target element.
Something like
Code: [Select]
mySourceElement.Connectors.AddNew("name","type");
Geert

7177
Danny,

There are basically two ways to use SQL when working on scripts/add-ins.

You should use Repository.SQLQuery() for all operations that select data from the model without changing it
Examples from https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EAWrappers/Model.cs
Code: [Select]
   /// generic query operation on the model.
    /// Returns results in an xml format
    public XmlDocument SQLQuery(string sqlQuery){
      XmlDocument results = new XmlDocument();
      results.LoadXml(this.wrappedModel.SQLQuery(sqlQuery));
      return results;
    }
usage example:
Code: [Select]
   internal List<Operation>getOperationsByQuery(string SQLQuery)
    {
      // get the nodes with the name "OperationID"
      XmlDocument xmlOperationIDs = this.SQLQuery(SQLQuery);
      XmlNodeList operationIDNodes = xmlOperationIDs.SelectNodes("//OperationID");
      List<Operation> operations = new List<Operation>();
      
      foreach( XmlNode operationIDNode in operationIDNodes )
      {
            int operationID;
            if (int.TryParse(operationIDNode.InnerText,out operationID))
            {
              Operation operation = this.getOperationByID(operationID) as Operation;
                if (operation != null)
                {
                         operations.Add(operation);
                }    
            }
 
      }
      return operations;
    }
and usage of that operation:
Code: [Select]
   /// <summary>
    /// gets the parameter by its GUID.
    /// This is a tricky one since EA doesn't provide a getParameterByGUID operation
    /// we have to first get the operation, then loop the pamarameters to find the one
    /// with the GUID
    /// </summary>
    /// <param name="GUID">the parameter's GUID</param>
    /// <returns>the Parameter with the given GUID</returns>
    public ParameterWrapper getParameterByGUID (string GUID)
    {
          
                //first need to get the operation for the parameter
                string getOperationSQL = @"select p.OperationID from t_operationparams p
                                                          where p.ea_guid = '" + GUID +"'";
                //first get the operation id
                List<Operation> operations = this.getOperationsByQuery(getOperationSQL);
                if (operations.Count > 0)
                {
                      // the list of operations should only contain one operation
                      Operation operation = operations[0];
                      foreach ( ParameterWrapper parameter in operation.ownedParameters) {
                            if (parameter.ID == GUID)
                            {
                                  return parameter;
                            }
                      }
                }
          //parameter not found, return null
          return null;
    }
If you want to change data however you need to use the undocumented (and unsupported) operation Repository.Execute()
Again in the same Model class I have
Code: [Select]
   internal void executeSQL(string SQLString)
    {
          this.wrappedModel.Execute(SQLString);
    }
which is used by
https://github.com/GeertBellekens/Enterprise-Architect-Add-in-Framework/blob/master/EAAddinFramework/EASpecific/WorkingSet.cs
Code: [Select]
           /// <summary>
            /// copy the workingset tot the given user
            /// </summary>
            /// <param name="user">the user to copy the working set to</param>
            /// <param name="overwrite">if true then the first workingset found with the same name
            /// for the given user will be overwritten</param>
            public void copyToUser(User user, bool overwrite)
            {
                  if (overwrite)
                  {
                        //check if a workingset with the same name already exists
                        WorkingSet workingSetToOverwrite = this.model.workingSets.Find(w =>
                                                                            w.user != null
                                                                            && w.user.login == user.login
                                                                            && w.name == this.name);
                        if (workingSetToOverwrite != null)
                        {
                              workingSetToOverwrite.delete();
                        }
                  }
                  string insertQuery = @"insert into t_document (DocID,DocName, Notes, Style,ElementID, ElementType,StrContent,BinContent,DocType,Author,DocDate )
                                                select '"+Guid.NewGuid().ToString("B")+@"',d.DocName, d.Notes, d.Style,
                                                d.ElementID, d.ElementType,d.StrContent,d.BinContent,d.DocType,'" + user.fullName + @"',d.DocDate from t_document d
                                                where d.DocID like '"+this.ID+"'";
                  this.model.executeSQL(insertQuery);

            }

Geert

7178
Yes, Sequence diagrams are an exception.

In order to copy a sequence diagram you actually have to copy each connector (and not only the diagramLink)

I'm not sure if it's necessary to copy the diagramLinks as well in that case.

Geert

7179
You have to be careful with the DiagramLinks collection.
At some point (v8 or v9) they changed the behavior of that collection.
Before it would only contain the DiagramLinks for links that had other then default style (or were once changed and then went back to the default)

Then they changed it so that it includes all links on the diagram no matter of their style.

That could explain the difference you are seeing.

Geert

7180
Danny,

I don't think the native copy operations are exposed in the API, but it should be relatively simple to duplicate a diagram.

Do do so you should:

- Create a new diagram in your new package and copy all attributes from the original diagram to the new diagram
- Create a copy of each DiagramObject of the original diagram in the new diagram
- Create a copy of each DiagramLink of the original diagram in the new diagram.

And that should be it.

Geert

7181
Michael,

In most places EA uses standard GUID's, which you can generate from a whole host of libraries or databases.

A google search for GUID + your scripting language/database should get you a solution quickly.

Geert

7182
Once you define the tagged value type you can just use its name when adding a new tagged value.

Geert

7183
I'm not sure about the multi-thread approach.
I think there's only one EA application object, and one database engine, so I think your threads get queued anyway.

I think as long as you have one thread dealing with EA, and maybe another tread dealing with your GUI that might just work. I think I'm going to try that in the near future to improve the performance of the EA Navigator. I'll know more after that experiment.

Geert

7184
Your component is an EA.Element, and it is connected to an EA.Diagram by means of a EA.DiagramObject.

Now you could of course loop through all diagrams of your project, loop through all DiagramObject in  Diagram.DiagramObjects and check whether or not it represents your object, but that will easily take minutes if not hours for a large model.

If is a lot more efficient (as in seconds rather then minutes) to use SQL for that purpose.

This part of the ElementWrapper class does exactly that:

Code: [Select]
   //returns a list of diagrams that somehow use this element.
    public override HashSet<T> getUsingDiagrams<T>()
    {
        string sqlGetDiagrams = @"select distinct d.Diagram_ID from t_DiagramObjects d
                                  where d.Object_ID = " + this.wrappedElement.ElementID;
        List<UML.Diagrams.Diagram> allDiagrams = this.model.getDiagramsByQuery(sqlGetDiagrams).Cast<UML.Diagrams.Diagram>().ToList(); ; ;
        HashSet<T> returnedDiagrams = new HashSet<T>();
        foreach (UML.Diagrams.Diagram diagram in allDiagrams)
        {
            if (diagram is T)
            {
                T typedDiagram = (T)diagram;
                if (!returnedDiagrams.Contains(typedDiagram))
                {
                    returnedDiagrams.Add(typedDiagram);
                }
            }
        }
        return returnedDiagrams;
    }

Geert

7185
Gordon,

There's three more settings you can use that are supposed to help with performance, but I don't have any proof they actually help:
- Repository.BatchAppend
- Repository.EnableCache
- Repository.EnableUIUpdates

You could give those a try...

Geert

Pages: 1 ... 477 478 [479] 480 481 ... 560