Genii Weblog


Civility in critiquing the ideas of others is no vice. Rudeness in defending your own ideas is no virtue.


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.
Inline GIF image

Copyright © 2003 Genii Software Ltd.

Wed 3 Dec 2003, 05:02 PM
There was an interesting interchange over at Duffbert's site.  Tom did what many of us do on our blogs and offered a bit of code, in this case a subroutine he uses for doing character replacement in a string variable.  I replied with one suggested change, and John Marshall made another critique, and both of us were pretty nice about it, but poor Duffbert must still have felt a bit "piled on", as he semi-jokingly said, "Here I try to help, and what do I get? Nuthin' but grief!".

Nothing out of the ordinary.  Everyday, people like Tom and Ben Poole and Rocky Oliver and Rich Schwartz and Andrew Pollack offer technical advice, snippets of code, technical articles and the like.  People either applaud, or thank them, or raise objections, but generally, they do it nicely.

Similarly, over on the Gold 4&5 forum and the Gold 6 forum, people like Stan Rogers and Rod Whiteley and others offer up code snippets and advice all the time.  Sometimes people challenge their code or assertions, sometimes not, but (unless it is one of those ungrateful wretches who ask question and then take umbrage when the answer isn't to their liking or the code or solution isn't completely done for them) if they do, they usually do it nicely.

Why?  Why are we all so nice?  The answer is simple.  The person offering the advice or code or article is doing it out of the kindness of their hearts, and we try to be nice back.  Even if we disagree, we strive hard to be pleasant and non-judgmental.

This is a problem.  While Miss Manners would be pleased with us all, sometimes niceness is not appropriate.  What if the article is wrong?  What if the advice is horrible?  What if the code sucks?  We can ignore it, or we can gently tug at its loose threads, but it would be horribly rude to tear it to shreds in the context of someone else's blog, or in the full glare of the public eye on the Golf forums.  Yet, there should be a place for such shredding.

Years ago, in the late 1960's, my parents were part of a group called Hammer and Tongs.  I was small, and only vaguely aware of it, but as I understand it, the purpose of this social group was to have one person prepare a thesis in the form of a paper or presentation, and distribute it to the others.  At the actual meeting, he or she would present the ideas and arguments supporting it, and then the feeding frenzy would start.  Like sharks at a shipwreck, they would jab and poke and tear and the goal seemed to spare no mercy for the presenter.  Of course, each person in the group took their turn, but if you think this made them more gentle, you are sadly mistaken.  At the time, I was convinced that my parents were nuts.  Crazy.  Bonkers!

Now, I am not so sure.  Imagine if we, the Domino bloggers and forum contributors and "big thinkers" were to take a similar approach.  In some less personal space than our own blog, and less public than the Gold forum, what if we took turns presenting an article, code library, or concept, with supporting arguments, etc.  Then, rather than having everybody sit back and be nice, invite them all in for the kill.  Tell every blogger and contributor and wiseguy around to take their best shot, and try to parry and twist and defend your thesis or code or concept, but with the understanding that every person joining the fray had to take their turn eventually.

What would happen if everybody felt free to really let loose?  What would result if we were requested to truly challenge the idea or technical concept?  It might not be comfortable, but whatever was left standing would have the strength of tempered steel.  I think this would be a perfect exercise for OpenNTF.org, so long as people agreed to the ground rules.  Unlike my parent's group, we could all participate from our different countries and time zones and perspectives, but we could also all benefit from the ideas that withstood that beating.  Rather than wait for people to voluntarily contribute to an open source effort, and then feel like you can't really criticize their contributions, challenge them to prove their mettle against their peers.  It would be fun - grueling, nasty, and spiteful at times, but all within the rules, so still fun.  What do you think?

Copyright © 2003 Genii Software Ltd.