Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started 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.
-
Maybe the object with that ID does not exist. Have you printed the object to see that it's not nil?
q.
-
yup, the element is definitely found and populated
-
Hard to debug. But if you print el.notes right before the Excel assignment, does that work?
q.
-
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
oleMethod(objRepo, "ShowInProjectView", argBlock, ret)
-
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
-
Thanks Geert, unfortunately no good that way either. I tried the following
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
-
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.
-
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
-
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.
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
-
SCORE! Thank you very much! I had messed with typing it as object but never would have found Variant.
-
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