Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Andre_b_b on July 07, 2023, 06:29:38 pm
-
Hello,
with the help of the forum during the last weeks, i have made a script that i can generate "parent" and "child" element and it appears the hierarchy in the project browser. I could also, generate a relationship(Realization) between the elements, when they are generated in a diagram. But, in fact, i would like to put the child element inside the parent element, does anyone know if it is possible using VBscript? For now, i have the parent element as a "stakeholder" and the child element as an "Action". For know i have this script, which works to build the relationship between parent and child.
Dim objElement
Set objElement = objElementParent.Elements.AddNew(child, "Action")
objElement.Update
dim newObjectparent
set newObjectparent = diagram.DiagramObjects.AddNew("", "")
newObjectparent.ElementID = objElementParent.ElementID
newObjectparent.Update()
dim newObjectchild
set newObjectchild = diagram.DiagramObjects.AddNew("", "")
newObjectchild.ElementID = objElement.ElementID
newObjectchild.Update()
Set connector = objElementParent.Connectors.AddNew("", "Realization")
connector.SupplierID = objElement.ElementID
connector.Update()
-
You have to calculate the sizes (and positions) or each shape. That way it is possible.
q.
-
Thanks for your answer, qwerty. You mean the size of the boxes and their position in relation to the diagram?
-
Exactly. Basically it's simple geometry.
q.
-
Ok, thanks for your help.
-
Is the only way to resize an element of a diagram is Manually? I have tried to use the .SetApperance, .SetGeometry and .Width and .Height and none of them worked :( There is always the problem of property related to the object. Do you guys have any recomendation?
-
Is the only way to resize an element of a diagram is Manually? I have tried to use the .SetApperance, .SetGeometry and .Width and .Height and none of them worked :( There is always the problem of property related to the object. Do you guys have any recomendation?
I honestly have no idea what exactly your are asking. "problem of property related to the object" what does that mean?
You can perfectly set the size of an element on a diagram using the properties of DiagramObject (top, left, right, bottom)
Geert
-
Thanks for your answer Geert. Even with the left, top, right and bottom, nothing changes. I am sorry for the misunderstanding, it is beacause my software is in french :) But, basically the problem is that when i use the properties i have mentioned, it appears an error that says the objet do not handle the property. I leave here examples of the code i am using and i am having this problem.
set newObject = diagram.DiagramObjects.AddNew("", "")
newObject.SetAppearance 0,0,100,50
newObject.SetGeometry 0,0,100,50
newObject.Width = 100
newObject.Height = 50
diagram.Update()
-
As i said, my problem is that i cannot generate the child element inside the parent element, so, as Qwerty said, i would have just to change the size of the parent element. Even though, i am not able to rezise the element
-
Thanks for your answer Geert. Even with the left, top, right and bottom, nothing changes. I am sorry for the misunderstanding, it is beacause my software is in french :) But, basically the problem is that when i use the properties i have mentioned, it appears an error that says the objet do not handle the property. I leave here examples of the code i am using and i am having this problem.
set newObject = diagram.DiagramObjects.AddNew("", "")
newObject.SetAppearance 0,0,100,50
newObject.SetGeometry 0,0,100,50
newObject.Width = 100
newObject.Height = 50
diagram.Update()
DiagramObjects.AddNew creates an object of type DiagramObject: https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/diagramobjects.html (https://sparxsystems.com/enterprise_architect_user_guide/16.1/add-ins___scripting/diagramobjects.html)
None of those methods or properties exist on DiagramObject
And after you update properties of newObject, you have to save them to the database by calling newObject.Update. Don't call diagram.Update unless you need to. In some cases it can even undo your updates on the diagramObjects.
Geert
-
Thanks for your help Geert. I will make the changes and be sure that the objects i am handling accept the properties. Would you recommend to make diagram update only in the end of the script?
-
Thanks for your help Geert. I will make the changes and be sure that the objects i am handling accept the properties. Would you recommend to make diagram update only in the end of the script?
I would recommend to not execute a single line of code without knowing absolutely sure you need it.
Geert
-
The diagram update is nonsense since you do not alter any properties of it. As said earlier: learn the API first. Sucking won't help in the long term (and bascially also not in the short term).
q.
-
Thanks guys!