1
Automation Interface, Add-Ins and Tools / Re: How to set stereotype using C# API
« on: November 19, 2020, 01:30:12 am »Or use the new property EA.Element.FQStereotype
Geert
This worked, thanks
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.
Or use the new property EA.Element.FQStereotype
Geert
That might need to be "SysML1.4::requirement", depending on the version you are using.
In version 15 you can actually see the fully qualified stereotype in the properties. Use that to set StereotypeEx
ElementService elementService = new ElementService(repo);
// create parent requirement
RequirementObj reqObj = GetResource<RequirementObj>("requirement.json");
Element parent = elementService.[b]ProcessJson[/b](reqObj);
Assert.IsNotNull(parent);
Assert.AreEqual(parent.Name, "Parent");
// create child requirement - performance
reqObj = GetResource<RequirementObj>("child_req.json");
Assert.IsNotNull(reqObj);
Element child = elementService.ProcessJson(reqObj);
Assert.IsNotNull(child);
Assert.AreEqual(child.Name, "Child");
// relate
reqObj = GetResource<RequirementObj>("relation.json");
Assert.IsNotNull(reqObj);
Element updatedChild = elementService.ProcessJson(reqObj);
Assert.AreEqual(child.ElementGUID, updatedChild.ElementGUID);
Assert.AreEqual(child.Name, updatedChild.Name);
ElementService ElementService = new ElementService(repo);
// create parent requirement
RequirementObj reqObj = GetResource<RequirementObj>("requirement.json");
Element parent = ElementService.ProcessJson(reqObj);
Assert.IsNotNull(parent);
Assert.AreEqual(parent.Name, "Parent");
// create child requirement - performance
reqObj = GetResource<RequirementObj>("child_req.json");
Assert.IsNotNull(reqObj);
Element child = ElementService.ProcessJson(reqObj);
Assert.IsNotNull(child);
Assert.AreEqual(child.Name, "Child");
// relate
reqObj = GetResource<RequirementObj>("relation.json");
Assert.IsNotNull(reqObj);
Element updatedChild = ElementService.ProcessJson(reqObj);
Assert.AreEqual(child.ElementGUID, updatedChild.ElementGUID);
Assert.AreEqual(child.Name, updatedChild.Name);
Something like this should work bettter:Code: [Select]public bool CreateElement(...) {
parentPkg = CreateOrGetParentPkg(inputEle);
string eleType = inputEle.Type;
// name and type are passed are args to method
ele = parentPkg.Elements.AddNew(eleName, eleType);
ele.Update(); //save here to make sure it's in the database before messing with the other stuff
// creating diagram
Diagram rootDiagram = CreateOrGetDiagram(parentPkg, parentPkg.Name);
// Add element to diagram - autogenerate position
DiagramObject diagramObject = (DiagramObject)rootDiagram.DiagramObjects.AddNew(GetDiagramObjectPosition(ele.Name.Length), "");
diagramObject.ElementID = ele.ElementID;
diagramObject.Update();
//if you want to see the changes in the project browser you can do a reload here
Repository.ReloadPackage (parentPkg.PackageID) ; //check the exact syntax
}
Geert
Besides the fact that you're doing lots of superfluous updates and refreshes and use unknown functions there's nothing which creates a connector.I did not post the code for the connector creation because the issue seems to be with creation, even though the creation is successful the element cant be found
q.
// link is an arg, ele and otherSide are the 2 requirements
Connector connector = ele.Connectors.AddNew(link.Name, link.LinkType);
connector.SupplierID = otherSide.ElementID;
connector.Update();
public bool CreateElement(...) {
parentPkg = CreateOrGetParentPkg(inputEle);
string eleType = inputEle.Type;
// name and type are passed are args to method
ele = parentPkg.Elements.AddNew(eleName, eleType);
// creating diagram
Diagram rootDiagram = CreateOrGetDiagram(parentPkg, parentPkg.Name);
parentPkg.Elements.Refresh();
parentPkg.Update();
// Add element to diagram - autogenerate position
DiagramObject diagramObject = (DiagramObject)rootDiagram.DiagramObjects.AddNew(GetDiagramObjectPosition(ele.Name.Length), "");
diagramObject.ElementID = ele.ElementID;
diagramObject.Update();
rootDiagram.Update();
rootDiagram.DiagramObjects.Refresh();
parentPkg.Update();
parentPkg.Diagrams.Refresh();
ele.Update();
}
If you are using an installer you'll have to make sure it includes these files as well.
Yup, sounds like an installer problem.
It's not EA itself that's giving you the error, that's thrown up from the OS when EA tells it to load the Add-In DLL.
So I'd say what you've bumped into here is the limit of the "various docs" you've followed, if they don't include how to construct an installer for your Add-In. But there's plenty of stuff on installers to be found all over the net.
/Uffe
Make sure build process actually copies the required dll's to the output folder.
Geert