Home       About Genii       Products       Downloads       News & Events       Support       Weblog   
May, 2008
SMTWTFS
    01 02 03
04 05 06 07 08 09 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
May, 2008
April, 2008
March, 2008
February, 2008
January, 2008
December, 2007

Show all 61 months


Search the weblog

Ben Langhinrichs
E-mail address - Ben Langhinrichs

Photograph of Ben Langhinrichs



©2003-2008 Genii Software Ltd. All rights reserved. The rights to all logos, images, etc. are owned by their respective owners.

The views expressed in this weblog are mine alone, but since I am President and Owner, they necessarily also reflect the views of Genii Software, Ltd.
Genii Weblog
Genii Weblog

Calling Midas from VB

Wed 3 Dec 2003, 11:15 PM

I have frequently gotten asked whether it is possible to call our Midas Rich Text LSX from Visual Basic, or other places for that matter, using COM.  I must admit that while I know customers have done it, I wasn't sure how myself.  Someone even showed me a while back, and I forgot, so I finally sat down and figured it out again and am posting it here so I can't forget again.  Now, before someone jumps down my throat, I don't think this is really COM.  I think it is actually OLE, but whatever it is called, this allows you to take a script which uses Midas to read or modify rich text, and call that script from VB or another OLE client.

Existing Midas Script

Sub ExportDocumentToMSWord(filepath As String, noteid As String)
   ' *** Constants
   Const EXPORT_DIRECTORY = "c:\export"
   
   ' *** Midas Rich Text LSX class objects
   Dim rtitem As GeniiRTItem
   Dim rtchunk As GeniiRTChunk

   ' *** Create the GeniiRTItem object 
   Set rtitem = New GeniiRTItem

   ' *** Connect to the document and export
   Call rtitem.Connect("", filepath, noteid, "Body")
   If Not rtitem.IsConnected Then Exit Sub
   Call rtitem.ExportToHTML(EXPORT_DIRECTORY & "\MX"  & noteid & ".doc", "HTML", |
CSSBorders='Yes'
AddNewlines=CRLF
AttachmentHandling='To Disk'
AttachmentDirectory='| & EXPORT_DIRECTORY & |'
AttachmentURLDirectory='| & EXPORT_DIRECTORY & |'
ImageHandling='To Disk'
ImageDirectory='| & EXPORT_DIRECTORY & |'
ImageURLDirectory='| & EXPORT_DIRECTORY & |'|)
   Print "Exported to " & EXPORT_DIRECTORY & "\MN"  & noteid & ".doc"            
End Sub

Modified Midas Script

Sub ExportDocumentToMSWord(filepath As String, noteid As String)
   ' *** Constants
   Const EXPORT_DIRECTORY = "c:\export"

   ' *** OLE server
   Dim oWS As Object
   
   ' *** Midas Rich Text LSX class objects
   Dim rtitem As Object
   Dim rtchunk As Object

   ' *** Connect to Notes as an OLE server
   Set oWS = CreateObject("Notes.NotesUIWorkspace")
   
   ' *** Load the LSX using its full pathname
   oWS.UseLSX("c:\lotus\notes\nlsxrtc.dll")
   
   ' *** Create the GeniiRTItem object by calling its OLE name
   Set rtitem = CreateObject("LSX.GeniiRTItem")
   
   ' *** Connect to the document and export
   Call rtitem.Connect("", filepath, noteid, "Body")
   If Not rtitem.IsConnected Then Exit Sub
   Call rtitem.ExportToHTML(EXPORT_DIRECTORY & "\MX"  & noteid & ".doc", "HTML", |
CSSBorders='Yes'
AddNewlines=CRLF
AttachmentHandling='To Disk'
AttachmentDirectory='| & EXPORT_DIRECTORY & |'
AttachmentURLDirectory='| & EXPORT_DIRECTORY & |'
ImageHandling='To Disk'
ImageDirectory='| & EXPORT_DIRECTORY & |'
ImageURLDirectory='| & EXPORT_DIRECTORY & |'|)
   Print "Exported to " & EXPORT_DIRECTORY & "\MN"  & noteid & ".doc"            
   Set rtitem = Nothing
   Set oWS = Nothing
End Sub

Comparison using Midas' rich text comparison
Sub ExportDocumentToMSWord(filepath As String, noteid As String)
   ' *** Constants
   Const EXPORT_DIRECTORY = "c:\export"

   ' *** OLE server
   Dim oWS As Object
   
   ' *** Midas Rich Text LSX class objects
   Dim rtitem As GeniiRTItemObject
   Dim rtchunk As GeniiRTChunkObject

   ' *** Connect to Notes as an OLE server
   Set oWS = CreateObject("Notes.NotesUIWorkspace")
   
   ' *** Load the LSX using its full pathname
   oWS.UseLSX("c:\lotus\notes\nlsxrtc.dll")
   
   ' *** Create the GeniiRTItem object by calling its OLE name
   Set rtitem = NewCreateObject("LSX.GeniiRTItem")
   
   ' *** Connect to the document and export
   Call rtitem.Connect("", filepath, noteid, "Body")
   If Not rtitem.IsConnected Then Exit Sub
   Call rtitem.ExportToHTML(EXPORT_DIRECTORY & "\MX"  & noteid & ".doc", "HTML", |
CSSBorders='Yes'
AddNewlines=CRLF
AttachmentHandling='To Disk'
AttachmentDirectory='| & EXPORT_DIRECTORY & |'
AttachmentURLDirectory='| & EXPORT_DIRECTORY & |'
ImageHandling='To Disk'
ImageDirectory='| & EXPORT_DIRECTORY & |'
ImageURLDirectory='| & EXPORT_DIRECTORY & |'|)
   Print "Exported to " & EXPORT_DIRECTORY & "\MN"  & noteid & ".doc"            
   Set rtitem = Nothing
   Set oWS = Nothing
End Sub

Conclusion (and limitation)
So, there you have it.  Change just a few lines and your script intended for LotusScript will run from Visual Basic, Excel, MS Word or wherever else you need it to run.  Pretty cool, eh?  (Also, a pretty simple example of how Midas's rich text comparison can show what has changed in a script)

There is one annoying limitation.  This is a front end action, not a server based backend action (note the Notes.NotesUIWorkspaceto understand why).  Still, for those more comfortable with VB, or for those who need to access some rich text in the middle of a script in MS Word, for example, this is an easy and effective way to use Midas outside of Lotus Notes/Domino.

Addendum
In order to make this work, you need to import the registry file attached here.

What's been said:

81.1. Tony (08/26/2004 09:10 AM)

how do you handle the event ActOnText in this example.

Thanks

Tony

Have your say:

Name *:
E-mail:
e-mail addresses will not be displayed on this site
Notify me of other comments

Comment *:


<HTML is not allowed>
Linking: Add links as {{http://xxx|title}}, and they will be activated once approved
Blocked? Unable to post a comment? Please read this for a possible explanation...

Copyright © 1996-2008 Genii Software Ltd. All Rights Reserved. Some images courtesy of BigFoto.com  Nedstat