Author Topic: Using VBScript to import Excel Files and generate diagrams automatically  (Read 5797 times)

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Nice. Thanks Geert. Should i get the element by GUID? If yes, i am trying to use the code, but it says that there is a "Internal Application Error".
Code: [Select]
' Active Diagram 
Set Diagram = Repository.GetCurrentDiagram() 
 
' Get 2 elements from their GUID 
Set Element1 = Repository.GetElementByGuid("{53C6DD5C-04D6-4b6f-9102-142557A3F4C7}")   
Set Element2 = Repository.GetElementByGuid("{49602501-62AA-4426-A862-45B066F62DF0}") 

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
On what line exactly does it give you this error?
Are you sure this guid exists in t_object.ea_guid?

Geert

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
There is this "internal error" in the line "Set Element1 = Repository.GetElementByGuid("{53C6DD5C-04D6-4b6f-9102-142557A3F4C7}")". And the GUID i have copied by right-clicking in the element from the browser and copying the GUID. Here it is the code i have been working with. I am sorry, i do not understand what is the t_object.ea_guid you asked me.

Code: [Select]
option explicit 
 
!INC Local Scripts.EAConstants-VBScript 

sub main 

 

Dim Repository 
Dim Diagram 
Dim Element1
Dim Element2
Dim Connector 
 

Set Repository = CreateObject("EA.Repository") 
 

Set Diagram = Repository.GetCurrentDiagram() 
 

Set Element1 = Repository.GetElementByGuid("{53C6DD5C-04D6-4b6f-9102-142557A3F4C7}")
Set Element2 = Repository.GetElementByGuid("{49602501-62AA-4426-A862-45B066F62DF0}")

Set Connector = Element1.Connectors.AddNew("", "Association")
 
Connector.SupplierID = Element2.ElementID 
 
Diagram.DiagramLinks.Refresh() 
Diagram.Update() 

end sub 
 
main 

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Loose the Set Repository = CreateObject("EA.Repository") that creates a new instance of EA (but without a model loaded), which you probably don't want.

The Repository object is a inserted as a global variable in your scripting environment, you can use it without setting it first.

You also don't need the diagram to create an association, and you should only Refresh/Update if really needed.

And you forgot to update() your new connector. Update() means: Save my changes to the database.

Geert

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Thanks for your help Geert.
Unfortunately, even with the suggestions and corrections you've made, i am still not able to run the script and so, i cannot make the connections. The error given is "this object does not manage" and it does reference to the line of "Element1 = Repository.GetElementByGUID("{53C6DD5C-04D6-4b6f-9102-142557A3F4C7}")"
Code: [Select]
option explicit 
 
!INC Local Scripts.EAConstants-VBScript 
sub main

Dim Element1
Dim Element2
Dim Connector
Element1 = Repository.GetElementByGUID("{53C6DD5C-04D6-4b6f-9102-142557A3F4C7}")
Element2 = Repository.GetElementByGUID("{49602501-62AA-4426-A862-45B066F62DF0}")

Set Connector = Element1.Connectors.AddNew("", "Association")
   Msgbox ("!")
Connector.SupplierID = Element2.ElementGUID
Connector.Update()
end sub 
 
main 


Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
I have managed to create the connection, but how can i turn it visible? I would like to show the relation in a diagram.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Hi Andre,

I think you might want to follow a few tutorials to get the basics right.
When setting an object to a variable in VBScript you should use set

You got it right at first, and then you changed it for some reason

this Element1 = Repository.GetElementByGUID("{53C6DD5C-04D6-4b6f-9102-142557A3F4C7}") should be set Element1 = Repository.GetElementByGUID("{53C6DD5C-04D6-4b6f-9102-142557A3F4C7}")

And the supplierID is a long, so it will give you an error when you set a string value (GUID) to it.

I can't keep debugging your scripts for you like this.
Checkout https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library There are lots of scripts that you can use as an example there.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
I think you might want to follow a few tutorials to get the basics right.
This was suggested in the very beginning. Doesn't look to have been a fruitful suggestion.

q.

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Thanks guys! I have tried reading the tutorials and everything but i do not understand the documentation, and everything looks advanced to me, so in this moment i am not able to learn - apparently -, that is why i keep asking here in the forum, because i do not find answers in any other place. Sorry for the mistakes and thanks for your help.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
You know that people like you are called vampires? I'm pretty allergic against those since I had unpleasant experiences in the past.
q.

Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
Excuse me, i am not sure what you mean from this comment. I hope you are not judging me for trying to learn programming and how to use Enterprise Architect.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13286
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Excuse me, i am not sure what you mean from this comment. I hope you are not judging me for trying to learn programming and how to use Enterprise Architect.
Don't worry about it too much. Q can get a bit grumpy sometimes ;D

What he means I think is that you might want to do a bit more research/trying yourself before asking for help.
If we look back at the history of this post, you might have called for help too soon a few times, which can be perceived as a send me teh codez request.

For context about help vampires: https://meta.stackoverflow.com/questions/258206/what-is-a-help-vampire

Geert


Andre_b_b

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-1
    • View Profile
ok  :D. Yes, looking back in the post, it really seems i am a "vampire", but if i am, it was not my intention. Sorry guys, i am trying to understand stuff, but sometimes my low-konwledge of programming, in general, do not allow me to evolute  :-\ :-\