Book a Demo

Author Topic: ShowInProjectView from VBA  (Read 7243 times)

rossi

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
ShowInProjectView from VBA
« on: February 24, 2014, 11:29:40 pm »
Hi,


I wrote a script in VB to access elements of my EA model and select an element in the project browser. It works well.

Now I try this from Excel with VBA.
GetElementByGuid() works, but ShowInProjectView() breaks the script.
Is it possible to do this from Excel?

Code: [Select]
Dim myElem As EA.Element
Set myElem = Repository.GetElementByGuid("{AD.....1B}")
Repository.ShowInProjectView(myElem)

thanks
Rossi.
« Last Edit: February 24, 2014, 11:30:26 pm by rossi »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShowInProjectView from VBA
« Reply #1 on: February 25, 2014, 01:45:17 am »
You need to access the EA instance. There's something like
Code: [Select]
Set EAapp = GetObject(, "EA.App")
Set Repository = EAapp.repository
you need to prepend.

q.

rossi

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView from VBA
« Reply #2 on: February 25, 2014, 02:20:06 am »
Thank you, unfortunately it doesn't work.
The ConnectionString points to the correct repository and the call of GetElementByGuid() returns a correct value.

But ShowInProjectView() jumps to the error label.
Any further ideas?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShowInProjectView from VBA
« Reply #3 on: February 25, 2014, 03:42:18 am »
I just tried with a Perl script and that worked. Maybe it's a VB issue?

q.

rossi

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView from VBA
« Reply #4 on: February 25, 2014, 10:20:57 am »
It seems so.
I tried with ActivePython and that was working too.

I'm not an expert of VBA, but can it be a problem in the type conversion (from Element to Object)?


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShowInProjectView from VBA
« Reply #5 on: February 25, 2014, 11:10:42 am »
Well, I used VB some time as long as there a) was no alternative and b) it worked with no issues. So I'm out ;-)

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: ShowInProjectView from VBA
« Reply #6 on: February 25, 2014, 05:45:39 pm »
What does the error say?
Even in VBA you have some kind of error information.

It could be a type issue.
In C# I use this code. Notice that the type of item is object.

                    
Code: [Select]
// for all other items we can only select them on the project browser
                    // get the element based on the type and the id
                    object item = getEAObjectByID(type, ID);
                    //show the item in the project view
                    if (item != null)
                    {
                        this.wrappedModel.ShowInProjectView(item);
                        return EAWrapperFactory.createEAWrapper(this, item);
                    }
                    else
                    {
                        // the item was not found
                        throw new Exception("Could not find a " + type + " with id " + ID);
                    }

Geert

rossi

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView from VBA
« Reply #7 on: February 25, 2014, 06:21:19 pm »
Now I have an error code:
"Object doesn't support this property or method"

Of what type should the parameter of ShowInProjectView() in VBA be?
'Object'? Or is there a particular EA type?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShowInProjectView from VBA
« Reply #8 on: February 25, 2014, 06:47:14 pm »
the documentation says object

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShowInProjectView from VBA
« Reply #9 on: February 25, 2014, 09:10:38 pm »
If I read above code correctly it *is* an object (EA.Element) being supplied  :-/

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: ShowInProjectView from VBA
« Reply #10 on: February 25, 2014, 10:43:41 pm »
I'm just thinking; if its not the type issue (EA.Element vs object) it might just be that VBA doesn't like the parentheses
You might need to write
Code: [Select]
Repository.ShowInProjectView myEleminstead of
Code: [Select]
Repository.ShowInProjectView(myElem)
Geert

Ah, the lovely VBA syntax :P

rossi

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView from VBA
« Reply #11 on: February 25, 2014, 11:18:45 pm »
Thanks a lot Geert!!!

Now it works  :)