Book a Demo

Author Topic: VB.Net Macro  (Read 5689 times)

bungle77

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
VB.Net Macro
« on: July 02, 2014, 01:21:17 am »
Hi All,
i am a newbie of EA and i should make some macros to automatize some operations.
Unluckily the search function it returns me an error so i am sorry if there are already answer in the forum.
I am trying  to write an "Hello Word" macro in VB.Net that print me the list of the packages in the active project and it return me this error "System.Runtime.InteropServices.COMException"
I am useing VB.Net 2012 and the Trial version of EA.
Is this a problem?

Here it is my code:
Code: [Select]
Option Explicit On


Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim MyRep As New EA.Repository

        MyRep.EnsureOutputVisible("Script")

        For i = 0 To MyRep.Models.Count - 1
            Dim Package As EA.Package
            Package = MyRep.Models.GetAt(i)
            Print("Model: " & Package.Name)
        Next


    End Sub
End Class

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: VB.Net Macro
« Reply #1 on: July 02, 2014, 05:52:39 am »
Where do you run that? Stand alone?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: VB.Net Macro
« Reply #2 on: July 02, 2014, 04:19:19 pm »
The problem is that you just create an empty EA.Repository object, but it isn't initialized.
So you either have to
- Initialize the Repository object by calling Repository.OpenFile()
- Connect the repository object to the currently running instance of EA
- Get the initialized repository object from the application (like when reacting to an event)

Geert

bungle77

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: VB.Net Macro
« Reply #3 on: July 02, 2014, 06:36:31 pm »
Quote
The problem is that you just create an empty EA.Repository object, but it isn't initialized.
So you either have to
- Initialize the Repository object by calling Repository.OpenFile()
- Connect the repository object to the currently running instance of EA
- Get the initialized repository object from the application (like when reacting to an event)

Geert


Thanks, but can i just connect to the active instance of EA without opening a file? Can you tell me the code to do it?
In the code examples i see  that the just connect by "OpenFile".

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: VB.Net Macro
« Reply #4 on: July 02, 2014, 06:50:43 pm »
See page 6 of my Scripting book:
Code: [Select]
Dim Repository As EA.repository
Set EAapp = GetObject(, "EA.App")
Set Repository = EAapp.repository

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: VB.Net Macro
« Reply #5 on: July 03, 2014, 08:41:59 am »

bungle77

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: VB.Net Macro
« Reply #6 on: July 03, 2014, 06:37:14 pm »
thanks a lot. I tried to look on EA support, but I still need to get my bearings