Solved

Lotusscript extract picture from lotus form...

Posted on 2013-05-28
11
2,523 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
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:larsberntrop
Comment Utility
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
Comment Utility
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 10

Expert Comment

by:larsberntrop
Comment Utility
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
 

Author Comment

by:nicedone
Comment Utility
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 10

Expert Comment

by:larsberntrop
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:nicedone
Comment Utility
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
Comment Utility
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 10

Expert Comment

by:larsberntrop
Comment Utility
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
Comment Utility
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 10

Accepted Solution

by:
larsberntrop earned 500 total points
Comment Utility
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
Comment Utility
tnx.sorry for the delay I was not able to test it since we had a health problem in the family..
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Python 2.7 - French characters 6 46
strCopies  challenge 17 73
Magic Software info 18 101
Make a file test.vbs using vbscript 5 41
A short article about a problem I had getting the GPS LocationListener working.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now