0

I created an EA addin in C# and I want to add a flow property to a Class and I have different result if I do it manually from EA. Signal4 is the item added manually, and Signal5 added with API. From Signal5 is missing FlowPropery ( from SyML1.5), also that is a Part Property (added picture below)

var flowPropertyProprieties = new Dictionary<string, string>
{{"Name", client.Name}, {"Type", "FlowProperty"}, {"Stereotype", "FlowProperty"},
                {"ClassfierID", $"{client.ClassfierID}"}
};

public Element AddFlowPropertyToElement(Element element, Dictionary<string, string> elementProprieties)
{
    var newFlowProperty = element.Elements.AddNew(elementProprieties["Name"], elementProprieties["Type"]);
    newFlowProperty.Stereotype = elementProprieties["Stereotype"];
    newFlowProperty.ClassfierID = Convert.ToInt32(elementProprieties["ClassfierID"]);
    newFlowProperty.Update();

    return element;
}

Below are some of the properties using Visual Studio with debug option (process attached), and I don't see any differences.
enter image description here enter image description here

enter image description here

enter image description here

2. Also I tried the same API with Type Part and Stereotype FlowProperty, but the result is not the expected one like Signal4 that was added manually in EA.

var flowPropertyProprieties = new Dictionary<string, string>
{{"Name", client.Name}, {"Type", "Part"}, {"Stereotype", "FlowProperty"},
                {"ClassfierID", $"{client.ClassfierID}"}
};

enter image description here enter image description here enter image description here

Ice
  • 193
  • 1
  • 2
  • 13
  • Seems like the problem is that EA is making a "slot" and not a "part". That is also why it's not showing the "part" properties. – Geert Bellekens Mar 14 '23 at 14:12
  • I know, but I don't know why in the view is so different. Also strange that the name in view is Signal5 / ValuleType1:ValueType1 instead of "Signal5:ValueType1". Also in code behind (debug mode) all the properties are the same between Signal4 and Signal5, also checked the CustomProperties and are the same – Ice Mar 14 '23 at 14:16
  • 1
    I would check the database. See what the difference is, and then fix it in the code. – Geert Bellekens Mar 14 '23 at 14:29
  • The Classifier and Classifier_guid are the different in DB: Signal4 property type is Boolean (Classifier and Classifier_guid are empty) and Signal5 that I'm creating is a reference type. I deleted the line newFlowProperty.ClassfierID = Convert.ToInt32(elementProprieties["ClassfierID"]); , added line PropertyType =Convert.ToInt32(elementProprieties["ClassfierID"]) and now is set ok. Thank you Geert! – Ice Mar 14 '23 at 16:38

1 Answers1

2

Try creating your element using it's fully qualified stereotype:

element.Elements.AddNew(elementProprieties["Name"], "SysML1.4::FlowProperty");

or

element.EmbeddedElements.AddNew(elementProprieties["Name"], "SysML1.4::FlowProperty");

And then don't set the type, or the stereotype.
Anyhow, you should never set the Element.Stereotype field, because that is asking EA to search for a stereotype in all of it's MDG's. If you are lucky, EA will find the correct one, but it might also select a stereotype from another MDG that happens to have the same name.
Instead always use Element.StereotypeEx and use the fully qualified stereotype.

There was something weird with the SysML 1.5 and SysML 1.4 profile, so you might need to use

element.Elements.AddNew(elementProprieties["Name"], "SysML1.5::FlowProperty");
Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50
  • tried with: element.Elements.AddNew(elementProprieties["Name"], "SysML1.4::FlowProperty"); and with element.EmbeddedElements.AddNew(elementProprieties["Name"], "SysML1.4::FlowProperty"); and has the same result like in first case from the question: Name Value Type FQStereotype "SysML1.4::FlowProperty" System.String Name "Signal5" System.String Stereotype "FlowProperty" System.String Type "Part" System.String ParentID 23446 System.Int32 – Ice Mar 14 '23 at 14:06
  • with argument "SysML1.5::FlowProperty" it is not working properly, it is creating a Property with Stereotype "FlowProperty" instead of "Flow Property". Don't know why in code behind is "SysML1.4::FlowProperty" instead of "SysML1.5::FlowProperty". I will attached a picture in the question about MDG technologies from the my EA program – Ice Mar 14 '23 at 14:12