Author Topic: Generation of parent and child elements using VBscript  (Read 2594 times)

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Generation of parent and child elements using VBscript
« 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.
Code: [Select]
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()

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #1 on: July 07, 2023, 07:02:16 pm »
You have to calculate the sizes (and positions) or each shape. That way it is possible.

q.

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #2 on: July 07, 2023, 07:22:18 pm »
Thanks for your answer, qwerty. You mean the size of the boxes and their position in relation to the diagram?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #3 on: July 07, 2023, 07:49:22 pm »
Exactly. Basically it's simple geometry.

q.

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #4 on: July 07, 2023, 09:59:49 pm »
Ok, thanks for your help.

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #5 on: July 10, 2023, 06:37:09 pm »
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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generation of parent and child elements using VBscript
« Reply #6 on: July 10, 2023, 06:41:06 pm »
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


Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #7 on: July 10, 2023, 07:06:10 pm »
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.
Code: [Select]
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()

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #8 on: July 10, 2023, 07:16:16 pm »
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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generation of parent and child elements using VBscript
« Reply #9 on: July 10, 2023, 07:22:36 pm »
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.
Code: [Select]
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
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

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #10 on: July 10, 2023, 07:37:38 pm »
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?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generation of parent and child elements using VBscript
« Reply #11 on: July 10, 2023, 08:35:18 pm »
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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #12 on: July 10, 2023, 11:40:17 pm »
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. 

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Re: Generation of parent and child elements using VBscript
« Reply #13 on: July 11, 2023, 12:11:46 am »
Thanks guys!