Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: nivek on July 31, 2015, 07:12:50 am

Title: ShowInProjectView() not working from excel
Post by: nivek on July 31, 2015, 07:12:50 am
I have VBA code similar to the following:

Dim App As EA.App
Set App = GetObject(, "EA.App")
Dim el As EA.Element
Set el = App.Repository.GetElementByID(869)
Excel.Cells(1, 1) = el.Notes
App.Repository.ShowInProjectView (el)


this gets the open instance of EA and properly gets notes for the referenced element. Other UI methods work as well like ensureOutputVisible or changing tabs so the connection should be good. However, this gives me an "object does not support this property or method" error. Inside of EA the method works just fine. Has anyone gotten this to work external to EA? Excel specifically?

Thank you very much for any assistance, I must be missing something.

Title: Re: ShowInProjectView() not working from excel
Post by: qwerty on July 31, 2015, 07:43:58 am
Maybe the object with that ID does not exist. Have you printed the object to see that it's not nil?

q.
Title: Re: ShowInProjectView() not working from excel
Post by: nivek on July 31, 2015, 10:55:39 pm
yup, the element is definitely found and populated
Title: Re: ShowInProjectView() not working from excel
Post by: qwerty on August 01, 2015, 12:07:19 am
Hard to debug. But if you print el.notes right before the Excel assignment, does that work?

q.
Title: Re: ShowInProjectView() not working from excel
Post by: nivek on August 01, 2015, 12:23:49 am
thanks q, yes print does work.

Also I have re-created the same issue in word.
To add intrigue I thought I would try the OLE, the following WORKS from DXL within DOORS
Code: [Select]
oleMethod(objRepo, "ShowInProjectView", argBlock, ret)
Title: Re: ShowInProjectView() not working from excel
Post by: Geert Bellekens on August 03, 2015, 07:35:02 pm
I've used code similar to that from both Word as Excel.

But each time I created a separate dim for the Repository (and not call it with App.Repository.DoSomething()

Have you tried that?
The COM stuff is weird sometimes  :-/

Geert
Title: Re: ShowInProjectView() not working from excel
Post by: nivek on August 04, 2015, 12:49:03 am
Thanks Geert, unfortunately no good that way either. I tried the following
Code: [Select]
Dim repo As EA.Repository
Set repo = App.Repository
Dim el As EA.Element
Set el = repo.GetElementByID(869)
Excel.Cells(12, 2) = el.Notes
repo.ShowInProjectView (el)

I also tried both on a different random configuration of windows, office and EA versions to no avail. :'( gotta love windows
Title: Re: ShowInProjectView() not working from excel
Post by: qwerty on August 04, 2015, 12:54:48 am
You might contact Sparx support directly (bug report bottom right of this page). Formerly I found that the API had some deficiency with scripting languages.

q.
Title: Re: ShowInProjectView() not working from excel
Post by: Geert Bellekens on August 04, 2015, 04:49:44 pm
I just tried it in excel, and indeed it doesn't seem to work, I get the same error on the ShowInProjectView.

I'm guessing the problem is related tot he COM stuff and the fact that the operation takes an object as parameter type. The EA.Element object has to be transferred to the API and then the API has to recognize which type of object has been transferred.

When looking back at an excel macro I wrote a couple of years ago I noticed that back then I wrote a small interop dll myself to allow this kind of interaction between Excel and the model.

Maybe the Sparxians have an idea how to get this working.

Geert
Title: Re: ShowInProjectView() not working from excel
Post by: Geert Bellekens on August 04, 2015, 04:51:18 pm
Found it! You have to use Variant as the type of the element object.
The code below works if EARepos is initialised with a valid EA.Repository.

Code: [Select]
Public Sub test()
    Dim el As Variant
    Set el = EARepos.GetElementByGuid("{AE85574D-739B-4143-8953-2C43DDB0C22B}")
    MsgBox el.name
    EARepos.ShowInProjectView (el)
End Sub

Geert
Title: Re: ShowInProjectView() not working from excel
Post by: nivek on August 06, 2015, 05:54:29 am
SCORE! Thank you very much! I had messed with typing it as object but never would have found Variant.
Title: Re: ShowInProjectView() not working from excel
Post by: Geert Bellekens on August 06, 2015, 03:52:03 pm
Quote
SCORE! Thank you very much! I had messed with typing it as object but never would have found Variant.
After a while you get a kind of feel for these things ::)

Geert