Book a Demo

Author Topic: PutDiagramImageOnClipboard  (Read 5065 times)

David OD

  • EA User
  • **
  • Posts: 56
  • Karma: +0/-0
    • View Profile
PutDiagramImageOnClipboard
« on: March 16, 2010, 05:24:18 pm »
Does anybody have a sample of using the ProjectInterface to place an image of a diagram onto the clipboard (or any other sample code at all!)?
Regards
David

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: PutDiagramImageOnClipboard
« Reply #1 on: March 16, 2010, 07:33:46 pm »
David,

I might have something in VBA that uses that function, need to check when I'm back at home.
Have you found the examples on the website?
Another source might be the community site.

Geert

David OD

  • EA User
  • **
  • Posts: 56
  • Karma: +0/-0
    • View Profile
Re: PutDiagramImageOnClipboard
« Reply #2 on: March 17, 2010, 10:19:43 am »
Geert

Any help you could offer would be appreciated.  I am developing Word VBA macros to extract data from EA to generate specifications - in fact some of that code is based upon your own work!

The issue I am having is related to getting the diagrams out into the document.  While there are lots of examples of code available, they all appear to be of the automation interface, not the XML based project interface.  That is the only way of accessing the images as far as I am aware.

I will keep looking though.  The diagrams are the last piece of the puzzle!
Regards
David

David OD

  • EA User
  • **
  • Posts: 56
  • Karma: +0/-0
    • View Profile
Re: PutDiagramImageOnClipboard
« Reply #3 on: March 17, 2010, 07:43:56 pm »
I have an answer, and it works fine.  Will post the sample code tomorrow morning when back at work.  Stay tuned...
Regards
David

David OD

  • EA User
  • **
  • Posts: 56
  • Karma: +0/-0
    • View Profile
Re: PutDiagramImageOnClipboard
« Reply #4 on: March 18, 2010, 10:07:01 am »
All

Here is a sample of the VBA code that invokes this feature.  Sparx informed me yesterday that the sample code can be found in the scripting function examples inside EA itself.

Code: [Select]
Public EARepos As EA.Repository
Public eaProject As EA.Project

'-------------------------------------------------------------
' Initializes the repository
'-------------------------------------------------------------
Private Sub Class_Initialize()
   If EARepos Is Nothing Then
      Set EARepos = Me.getCurrentRepository
   End If
End Sub

'-------------------------------------------------------------
' Return the currently opened EA Model
'-------------------------------------------------------------
Public Function getCurrentRepository() As EA.Repository
    Dim EAapp As EA.App
    Dim EArepository As EA.Repository

   Set EAapp = GetObject(, "EA.App")
    ' Warning when EA not open
   If EAapp Is Nothing Then
      MsgBox "Please Open Enterprise Architect"
      ' try again
      Set getCurrentRepository = Me.getCurrentRepository
   End If
  
   ' Warning when no repository is opened.
   Set EArepository = EAapp.Repository
   If EArepository Is Nothing Then
      MsgBox "Please open a Model in Enterprise Architect"
       ' try again
      Set getCurrentRepository = Me.getCurrentRepository
   End If
  
   ' Return the found repository
   Set getCurrentRepository = EAapp.Repository
End Function


'-------------------------------------------------------------
' Copy the nominated diagram to the clipboard (so it can be pasted)
'-------------------------------------------------------------
Public Sub copyDiagramToClipboard(guid As String)
    Dim aEArepository As EA.Repository
    Dim xmlGUID As String

   ' If the repository is not already know get the repository
   If EARepos Is Nothing Then
        ' Get the currently opened repository
     Set EARepos = Me.getCurrentRepository
   End If
  

   ' If the project interface is not already loaded, do so
   If eaProject Is Nothing Then
        ' Get the currently project interface
     Set eaProject = EARepos.GetProjectInterface()
   End If
  
   ' GUIDs need to be converted to XML format for teh project interface
   xmlGUID = eaProject.GUIDtoXML(guid)
  
   eaProject.PutDiagramImageOnClipboard xmlGUID, 0
  
End Sub

Hope that helps the next person havign a go at this stuff.
Regards
David

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: PutDiagramImageOnClipboard
« Reply #5 on: March 19, 2010, 01:52:06 am »
David,

I see you already found the solution, I was just about to post my code, but it is not near as clean as example as yours.

Sorry it took so long.

Geert

David OD

  • EA User
  • **
  • Posts: 56
  • Karma: +0/-0
    • View Profile
Re: PutDiagramImageOnClipboard
« Reply #6 on: March 19, 2010, 09:20:46 am »
Geert

Glad you like it - it is based on your code after all!!  I am doing a LOT fo work on generating Word specifications, and plan to post code segements as I solve problems.  There have been several issues I've tried to solve by looking on the forum, and the lack of code samples needs to be addressed!  Wish me luck!
Regards
David