Author Topic: AddIn on shapescript...  (Read 5194 times)

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
AddIn on shapescript...
« on: December 12, 2014, 08:39:09 pm »
Hi,

I'm trying to invoke an Addin from my shapescript. I've followed Geerts excellent example. I believe my add-in is registered ok. It should just return a test String - "Test". But I get nothing. I'm not sure if the code in my shapescript is correct, can someone validate:

println ("#ADDIN:RelationshipAddIn, GetRelationships, Application#");

Here

- RelationshipAddIn is the name of my "Class", should it be the name of the assembly/project ? Which would be dbSparxRelationshipAddIn

- GetRelationships is the Public method in my Add In. It has this signature:

public String GetRelationships(EA.Repository repo, String guid, String[] args)
{
  return "Test";
}

Any thoughts, suggestions appreciated.

Regards,


Jon.


« Last Edit: December 12, 2014, 08:40:03 pm by openit »

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: AddIn on shapescript...
« Reply #1 on: December 12, 2014, 10:52:17 pm »
Hi,

Update on this - the issue turned out to be with the fact that I was staring Sparx via the MS Application Virtualization Client. It doesn't use the standard keys in the local registry for Sparx.

When I started Sparx locally the Addin was found and invoked. FYI  

println ("#ADDIN:dbSparxRelationshipAddIn, GetRelationships, Application#");

Kind of works. I'm now getting an error dialogue in sparx informing me that the parameters for GetRelationships are invalid. I've tried String[] and Object[]. Same error.

Any suggestions what my final parameter type should be ?

Regards,


Jon.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: AddIn on shapescript...
« Reply #2 on: December 12, 2014, 10:58:58 pm »
Hi,


The "AddIn" part of the argument should be the name of the Add-In. This is not the name of the main class, nor the project/solution, but the assembly name.
If you don't have the source handy you can check the menu under Extensions -- Manage Add-Ins, that should give you the correct name.

As to the method signature, strictly speaking the third argument should be an object rather than a string[] but I think it'll work either way. Still, declaring it as object and performing the cast explicitly is more robust, and robust code is the only code worth writing (sorry, that's what fifteen years in the defence industry does to you...).

A simple way to check whether the call is coming through is to add a line
Code: [Select]
repository.WriteOutput("System", "GetRelationships() called", -1);to your method. Remember to open the output tab in your test project, or call repository.EnsureOutputVisible(). Ahhh, the days of fprintf() debugging... :)

Finally, not to knock Geert's samples, but I strongly recommend that you do not allow Visual Studio to register the assembly for COM interop, but instead create an installer. Otherwise, since Studio does not automatically de-register when rebuilding (but an installer will deregister when uninstalling) you'll soon find your dev machine registry lousy with old registrations which can make debugging a far bigger PITA than it needs to be.
Ayone who's ever seen the above dialog complaining "Error - AddIn not found" knows what I'm on about.


/Uffe
My theories are always correct, just apply them to the right reality.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: AddIn on shapescript...
« Reply #3 on: December 12, 2014, 11:00:57 pm »
Sorry, your update came in while I was crafting my eloquent, if not loquacious, reply.  ;D

Try a plain object, rather than an object array.

/U
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: AddIn on shapescript...
« Reply #4 on: December 12, 2014, 11:13:58 pm »
IIRC the methods receives a string collection (means you can use GetAt) and returns a string. So basically Uffe is right.

q.
« Last Edit: December 12, 2014, 11:14:48 pm by qwerty »

OpenIT Solutions

  • EA User
  • **
  • Posts: 555
  • Karma: +9/-1
    • View Profile
Re: AddIn on shapescript...
« Reply #5 on: December 12, 2014, 11:32:03 pm »
Hi,

The solution that worked in the end was this method signature (in c#) :

public String GetRelationships(EA.Repository repo, String guid, params Object[] args)
{
  String stereotype = ((string[])(args[0]))[0];
  return stereotype;
}

Now to put some meat into the AddIn :-).....Thanks all for your help.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: AddIn on shapescript...
« Reply #6 on: December 12, 2014, 11:42:13 pm »
Thanks for sharing :-)

q.