Book a Demo

Author Topic: Accessing Current Element from Add-In  (Read 8782 times)

fwoolz

  • EA User
  • **
  • Posts: 435
  • Karma: +0/-0
  • We have met the enemy, and he is us.<Pogo, 1970>
    • View Profile
Accessing Current Element from Add-In
« on: February 11, 2005, 12:45:07 pm »
Hi All,

Is there an automatic way to access and manipulate the current element via the Automation Interface in an Add-In?

Thanks,
Fred Woolsey
Interfleet Technology Inc.

Always be ready to laugh at yourself; that way, you beat everyone else to the punch.


KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Accessing Current Element from Add-In
« Reply #1 on: February 13, 2005, 02:03:33 pm »
Hi,

You have a choice: Repository.GetTreeSelectedItem or Diagram.SelectedObjects, depending on whether you want the objects selected in the Project View or on the diagram.

Tip: your EA_MenuClick event will give you a MenuLocation parameter which will tell you where the add-in was called from, i.e. diagram, main menu or project view.

The EA help file has more info. e-mail me if you get stuck  :)

Neil
The Sparx Team
[email protected]

tugelblend

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • /* You are not expected to understand this */
    • View Profile
Re: Accessing Current Element from Add-In
« Reply #2 on: May 31, 2005, 05:51:20 am »
Quote
Hi,

You have a choice: Repository.GetTreeSelectedItem or Diagram.SelectedObjects, depending on whether you want the objects selected in the Project View or on the diagram.

Neil


Hi,
could you please give an example for that. I've got the problem, that the GetCurrentDiagram-Method doesn't work for me (f.e. when selecting a Use Case in the Diagram View).

For being a VB Newbie maybe I'm doing a basic thing wrong. This is my code:

Code: [Select]

Sub Set_Object_As_Source(ByVal Repository As EA.Repository, ByVal Location As String)
   [...]
   Dim currentDiagram As EA.Diagram
   [...]
   Case "Diagram"
               currentDiagram = Repository.GetCurrentDiagram()
   [...]


The last line causes error '91 - Object variable or With block variable not set'.

What am I doing wrong?

I would appreciate any help. Thanx.

Hauke Altmann

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Accessing Current Element from Add-In
« Reply #3 on: May 31, 2005, 06:35:19 am »
Hauke,

In VB, you need to use the "Set" syntax for object variables.

Thus:
   Case "Diagram"
     Set currentDiagram = Repository.GetCurrentDiagram()

Should do it...

HTH,

Paolo
« Last Edit: May 31, 2005, 06:36:21 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

tugelblend

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
  • /* You are not expected to understand this */
    • View Profile
Re: Accessing Current Element from Add-In
« Reply #4 on: May 31, 2005, 07:21:06 am »
Paolo,
thanks. Works now to that point. I will take a deeper look in my vb book to avoid another question like that  ;).

Hauke