Book a Demo

Author Topic: ShowInProjectView() not working from excel  (Read 7005 times)

nivek

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
ShowInProjectView() not working from excel
« 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.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShowInProjectView() not working from excel
« Reply #1 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.

nivek

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView() not working from excel
« Reply #2 on: July 31, 2015, 10:55:39 pm »
yup, the element is definitely found and populated

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShowInProjectView() not working from excel
« Reply #3 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.

nivek

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView() not working from excel
« Reply #4 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)
« Last Edit: August 01, 2015, 12:48:05 am by nivek.nitram »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13519
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShowInProjectView() not working from excel
« Reply #5 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

nivek

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView() not working from excel
« Reply #6 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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShowInProjectView() not working from excel
« Reply #7 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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13519
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShowInProjectView() not working from excel
« Reply #8 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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13519
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShowInProjectView() not working from excel
« Reply #9 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

nivek

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: ShowInProjectView() not working from excel
« Reply #10 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.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13519
  • Karma: +573/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShowInProjectView() not working from excel
« Reply #11 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