Solved

Lotusscript extract picture from lotus form...

Posted on 2013-05-28
11
2,808 Views
1 Endorsement
Last Modified: 2013-12-18
Hi,

I would like to extract screenshots from a lotus form which is a picture on a form...

I am looking for help with the lotusscript code to extract the picture and put it in folder as an attachment,
is it possible?
if yes can you guide me how with the code,

tnx alot

picture to be extracted is in richtext field and looks like something on the form...
fields.JPG
screenshot.JPG
1
Comment
Question by:nicedone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 11

Expert Comment

by:larsberntrop
ID: 39201048
Sub Initialize
  Dim session As NotesSession
  Dim db As NotesDatabase
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument
  Dim body As NotesRichTextItem
  Dim rtnav As NotesRichTextNavigator
  Dim att As NotesEmbeddedObject
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstDocument
  If Not doc.HasEmbedded Then Exit Sub
  Set body = doc.GetFirstItem("Photo")
  Set rtnav = body.CreateNavigator
  
  REM Get attachments
  If rtnav.FindFirstElement(RTELEM_TYPE_FILEATTACHMENT) Then
    Do
      Set att = rtnav.GetElement()
      filepath$ = "C:\Files\" & att.Source
      Call att.ExtractFile(filepath$)
      Print filepath$ & " extracted"
    Loop While rtnav.FindNextElement()
  End If
End Sub

Open in new window

0
 

Author Comment

by:nicedone
ID: 39204684
Thank you very much for the code,

but unfortunately on 13th line it decides that it does not have an attachment then it exits and nothing happens,

so i removed that line so that i could continue and try to get "Photo" field

but then it filled rtnav with nothing

what might be wrong?

tnx
0
 
LVL 11

Expert Comment

by:larsberntrop
ID: 39204811
try it without line 13 (don't have time to build a test case sorry.  you'll have to test...)

alternatively, step through the code with the lotusscript debugger on (Tools:Debug LotusScript)
when you have executed line 14 (Set body = doc.GetFitrstItem("Photo")
check the rbody item for the properties of body.EmbeddedObjects

if that is filled, you can use the ExtractFile method of the EmbeddedObject to save the file to disk.  See also designer help: http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.main.doc/H_EXTRACTFILE_METHOD.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:nicedone
ID: 39207339
Sub Initialize
	
  Dim session As NotesSession
  Dim db As NotesDatabase
  Dim dc As NotesDocumentCollection
  Dim doc As NotesDocument
  Dim body As NotesRichTextItem
  Dim rtnav As NotesRichTextNavigator
  Dim att As NotesEmbeddedObject
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstDocument
  'If Not doc.HasEmbedded Then Exit Sub
  Set body = doc.GetFirstItem("Photo")
  'Set rtnav = body.CreateNavigator
  'Dim filepath As String
 
  Set att = body.EmbedObject( EMBED_ATTACHMENT, "","C:/Fatih/jim.sam")
    
  Call att.Extractfile("C:\Fatih\a.jpg")
	
End Sub

Open in new window


Since I could not retrieve the file i want, I modified the code as above

Although While debugging body is not empty

EmbeddedObject property of body has 0 lenght

thus in the screenshots i provided you can see these values...

why can it transfer it as embeddedobject or attachment somehow

and afterwards the file a.jpg is an empty 0kb file,

any suggestions?

what should i do now? i am stuck here?
body.JPG
body2.JPG
0
 
LVL 11

Expert Comment

by:larsberntrop
ID: 39207814
Pure logic.
You create the the attachment by set att=body.EmbedObject(..) call.
The chnages in the rich text are not done when you next call ExtractFile, so nothing is exported. See the Designer help on NotesRichTextItem

The other thing is that i forgot about inline images and the the fact that they are not considered attachments or OLE objects, so not reacheable by conventional LotusScript methods. Sorry I sent you barking up the wrong tree.

It IS possible to do a prgrammatic export, however that plan has several moving parts.
The only way you can get at inline images is if they RichText items are stored as MIME instead of Notes RichText.
1. Make a backup copy of the db to work on.
2. Edit the form design, and mark all the RichText fields to store their contents as HTML and MIME (2nd tab of Field properties)
3. There is a bug when updating, so update the existing documents by code from this IBM technote:
Sub Initialize
	Dim ws As NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument, docNext As NotesDocument
	Dim s As NotesSession
	Dim selectedDocs As NotesDocumentCollection
	Set s = New NotesSession
	Set ws = New NotesUIWorkspace
	
	Set selectedDocs = s.CurrentDatabase.UnprocessedDocuments
	Set doc = selectedDocs.GetFirstDocument
	Do Until doc Is Nothing
		Set docNext = selectedDocs.GetNextDocument(doc)
		If Not doc.HasItem("ConvertedMime") Then ' make sure we do this ONCE to avoid bug that deletes images 
			doc.ReplaceItemValue "ConvertedMime", "1"
			doc.Save True, False
			Set uidoc = ws.EditDocument(True, doc)
			uidoc.Save
			uidoc.Close
		End If
		Set doc = docNext
	Loop
End Sub

Open in new window


Then use code which extracts the images:
	Dim mEnt As NotesMIMEEntity, mEntNext As NotesMIMEEntity, sImg As NotesStream
	Dim pathName$, subType$, filename$
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
	filename = doc.SimpleName(0)
	
	Set mEnt = doc.GetMIMEEntity("Photo")
	Do
		Set mEntnext = mEnt.GetNextEntity
		If mEnt.Contenttype = "image" Then
			subType = mEnt.ContentSubtype
			Set sImg = session.CreateStream
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
			pathname = "c:\temp\" & filename & "." & subtype
			If Not sImg.Open(pathname, "binary") Then
				MsgBox pathname,, "Open failed"
				Exit Sub
			End If
			Call mEnt.GetContentAsBytes(sImg, True)
			Call sImg.Close
		End If
		Set mEnt = mEntNext 
	Loop Until mEnt Is Nothing
	Call doc.CloseMIMEEntities(False, "Photo")

Open in new window

0
 

Author Comment

by:nicedone
ID: 39210125
Thanks for your assistance,

I get the object variable not set error in the second agent.(the one that extracts the image)

On line 8 and then i commented out this line and tried it for just 1 document with only the Photo richtextitem to be extracted but then I get Object variable not set error on line 9

somehow from this line of code;

Set mEnt = doc.GetMIMEEntity("Photo")

mEnt comes empty :(

what would be your suggestion ? what i am doing wrong...i also put a screenshot of the debugging screen.. thanx in advance for your support...
ment.JPG
0
 

Author Comment

by:nicedone
ID: 39210143
Dim mEnt As NotesMIMEEntity, mEntNext As NotesMIMEEntity, sImg As NotesStream
	Dim pathName$, subType$, filename$
	' Note you need to create a meaningful filename here, maybe based on other fields in th doc
	
	Dim ws As NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument, docNext As NotesDocument
	Dim session As NotesSession
	Dim selectedDocs As NotesDocumentCollection
	Set session = New NotesSession
	Set ws = New NotesUIWorkspace
	

	Set selectedDocs = session.CurrentDatabase.UnprocessedDocuments
	Set doc = selectedDocs.GetFirstDocument
	filename = doc.Form(0)
	Set mEnt = doc.GetMIMEEntity("Photo")
	Do
		'Set mEntnext = mEnt.GetNextEntity
		If mEnt.Contenttype = "image" Then
			subType = mEnt.ContentSubtype
			Set sImg = session.CreateStream
			' Note you need to create a meaningful filename here, maybe based on other fields in th doc
			pathname = "c:\temp\" & filename & "." & subtype
			If Not sImg.Open(pathname, "binary") Then
				MsgBox pathname,, "Open failed"
				Exit Sub
			End If
			Call mEnt.GetContentAsBytes(sImg, True)
			Call sImg.Close
		End If
		Set mEnt = mEntNext 
	Loop Until mEnt Is Nothing
	Call doc.CloseMIMEEntities(False, "Photo") 

Open in new window


Here is the code in the second agent if you want to look at the code too...

thanks for your help
0
 
LVL 11

Expert Comment

by:larsberntrop
ID: 39210182
For this to work, the form definition of the document (not the Form name, but the design) needs to correct, i.e. the property 'Store contents as HTML and MIME' needs to be checked. AND the documents has to be opened in edit mode and saved, so the field will be converted from rich text to MIME.
You can check the design is correct and conversion has occurred by pointing to the document you are using to check the agent, ands opening the property box. Check the fields tab of the Document properties, scroll down to the Photo field,and click on it.
The first two lines in the righthand part should read:
[Field Name: Photo
Data Type: MIME Part

Open in new window

If it reads
Field Name: Photo
Data Type: Rich Text

Open in new window

, the design was not changed, or the document not re-saved.

Another point is that setting the filename to the form will allow you to export exactly one photo 'PerData.jpg'.  Please use your imagination and create a filename which will be unique even if you run the agent on many documents.

modded code cheking tha availability of Photo:
Dim mEnt As NotesMIMEEntity, mEntNext As NotesMIMEEntity, sImg As NotesStream
	Dim pathName$, subType$, filename$, v as Variant
	' Note you need to create a meaningful filename here, maybe based on other fields in th doc
	
	Dim ws As NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument, docNext As NotesDocument
	Dim session As NotesSession
	Dim selectedDocs As NotesDocumentCollection
	Set session = New NotesSession
	Set ws = New NotesUIWorkspace
	

	Set selectedDocs = session.CurrentDatabase.UnprocessedDocuments
	Set doc = selectedDocs.GetFirstDocument
	Do Until doc Is Nothing
		' get next document before, because this might fail if we save or delete doc
		Set docNext = selectedDocs.GetNextDocument(doc)
		' need to set this to a unique  recognizable name
		' consider the shortname or employee number
		' this example combines the form name and a Unique identifier
		v = Evaluate("@Unique")
		filename = doc.Form(0) & "-" & v(0)
		Set mEnt = doc.GetMIMEEntity("Photo") ' try to get Photo MIME
		If mEnt Is Nothing Then
			Print "No 'Photo' in doc: "; doc.UniversalID
		Else
			Do
				'Set mEntnext = mEnt.GetNextEntity
				If mEnt.Contenttype = "image" Then
					subType = mEnt.ContentSubtype
					Set sImg = session.CreateStream
					' Note you need to create a meaningful filename here, maybe based on other fields in th doc
					pathname = "c:\temp\" & filename & "." & subtype
					If Not sImg.Open(pathname, "binary") Then
						MsgBox pathname,, "Open failed"
						Exit Sub
					End If
					Call mEnt.GetContentAsBytes(sImg, True)
					Call sImg.Close
				End If
				Set mEnt = mEntNext 
			Loop Until mEnt Is Nothing
			Call doc.CloseMIMEEntities(False, "Photo") ' clean up after ourselves
		End If
		Set doc = docNext ' point doc to next document
	Loop

Open in new window

0
 

Author Comment

by:nicedone
ID: 39215580
Hi,

Thank you , when I do the first step you mention..

1) Save that richtextitem field ,check the property 'Store contents as HTML and MIME'
2) edit and save document(document refresh)

after that when i check the Photo field i see that there are 4 Photo fields rather then 1...

i attach the all 4 Photo item contents for you to check, what am  i doing wrong here?
1photo.JPG
2photo.JPG
3Photo.JPG
4photo.JPG
0
 
LVL 11

Accepted Solution

by:
larsberntrop earned 500 total points
ID: 39218235
You're doing nothing wrong, This is just how Notes does stuff in the backend. Nothing to worry about.

Did you run the code against this document? What happened? Did you follow along in the Debugger?
0
 

Author Closing Comment

by:nicedone
ID: 39287279
tnx.sorry for the delay I was not able to test it since we had a health problem in the family..
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The viewer will learn how to dynamically set the form action using jQuery.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question