MDF export of graphics problem

15 views
Skip to first unread message

Jason Lee

unread,
Mar 1, 2022, 8:27:54 PM3/1/22
to Shoebox/Toolbox Field Linguist's Toolbox
I'm trying to include pictures in my MDF dictionary, but am having trouble.

Word is giving the error message "The graphics filter was unable to convert this file. (\png\Acacia_dunnii)"

Here is the syntax within the entry in Toolbox:
\pc .G.\png\Acacia_dunnii;2.5";2.5";PNG

I've tried other graphics formats and syntax, such as .jpg and .bmp:

\pc .G.\png\Acacia_dunnii.png;2.5";2.5";PNG
\pc .G.\jpg\Acacia_dunnii.jpg;2.5";2.5";JPG
\pc .G.\bmp\Acacia_dunnii.bmp;2.5";2.5";BMP

All of these have failed so far.

I've tried having the graphics folder (e.g. \png) in both the same level as the dictionary file, as well as in the 'settings' subfolder. Both don't work.

Here is the debug error line:

WordBasic.InsertPicture Name:=sFilePath$, LinkToFile:="0"

I've had filepath issues before. Something about Toolbox not cooperating so well with modern windows user folders or something.

Would appreciate advice.

Asigwan

unread,
Mar 2, 2022, 12:46:26 AM3/2/22
to shoeboxtoolbox-fiel...@googlegroups.com

Toolbox Help should assist you with this, but getting images to work may not be easy. I'm probably wrong, but I think Toolbox won't allow file names over eight characters. So maybe your file names are too long. Don't quote me on that, though. And don't go changing things until you know for sure the correct fix from the experts.

 

I got Lexique Pro to recognize images with the following kind of formatting:

\pc .G.i-corax4.jpg

 

I just had to make the images all the same size and then not try to put their dimensions in the database. That may just be an issue with getting them to work in Lexique Pro, but I can't remember now. I haven't worked in Toolbox for years and just use what I got to work in Lexique Pro back then. And maybe I just got rid of trying to put them in a different folder due to Lexique Pro. You have to think of how you will display these and what program(s) you will use. Word might give you fits when it comes to rendering these images in a document. It did me and I just used Lexique Pro to see things on the computer. We have never printed - which it sounds like you want to do.

 

I'll be interested in hearing what Toolbox Help has to say, but you are not the first person to ask about this. If this List has archives, you should look there for answers, too. Sorry I can't be of much help, but I wanted to send a few comments.

 

Crockett

 

From: 'Jason Lee' via Shoebox/Toolbox Field Linguist's Toolbox [mailto:shoeboxtoolbox-fiel...@googlegroups.com]
Sent: Tuesday, March 1, 2022 8:28 PM
To: Shoebox/Toolbox Field Linguist's Toolbox <shoeboxtoolbox-fiel...@googlegroups.com>
Subject: [Toolbox] MDF export of graphics problem

 

I'm trying to include pictures in my MDF dictionary, but am having trouble.

 

Word is giving the error message "The graphics filter was unable to convert this file. (\png\Acacia_dunnii)"

 

Here is the syntax within the entry in Toolbox:

\pc .G.\png\Acacia_dunnii;2.5";2.5";PNG

 

I've tried other graphics formats and syntax, such as .jpg and .bmp:

 

\pc .G.\png\Acacia_dunnii.png;2.5";2.5";PNG

\pc .G.\jpg\Acacia_dunnii.jpg;2.5";2.5";JPG

\pc .G.\bmp\Acacia_dunnii.bmp;2.5";2.5";BMP

 

All of these have failed so far.

 

I've tried having the graphics folder (e.g. \png) in both the same level as the dictionary file, as well as in the 'settings' subfolder. Both don't work.

 

Here is the debug error line:

 

WordBasicInsertPicture Name:=sFilePath$, LinkToFile:="0"

 

I've had filepath issues before. Something about Toolbox not cooperating so well with modern windows user folders or something.

 

Would appreciate advice.

--
You received this message because you are subscribed to the Google Groups "Shoebox/Toolbox Field Linguist's Toolbox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shoeboxtoolbox-field-ling...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shoeboxtoolbox-field-linguists-toolbox/9a2ad145-58c1-4df5-b8d8-6fe391e6e1c3n%40googlegroups.com.

John R. Rennison

unread,
Mar 2, 2022, 6:17:16 AM3/2/22
to shoeboxtoolbox-fiel...@googlegroups.com
My \pc fields work fine and look like this:

.G..\pc\baobab01_small.jpg;1.40";2.35";JPG

I think that Word has problems finding absolute paths (like "\pc\jpg\...") but the relative subdirectory ".\pc\,,," is fine. Note the two dots between G and \pc. The picture files have to be in the subdirectory \pc of the directory in which the .RTF file is located.

The FinishExportingFromShoebox macro works just as well in Word 365 as it did in Word 2000.

Good luck!
John

ToolBox Support

unread,
Mar 2, 2022, 11:01:08 AM3/2/22
to shoeboxtoolbox-fiel...@googlegroups.com
I appreciate John's confirmation of the macro. And I appreciate the others who responded also. LexiquePro is a possibility, but I think the export from Toolbox can be made to work.

There are two versions of the Graphics Macro in MDF. One is about 20 years old -- and that's the "new" one. The other stopped working some while ago, I believe. It may be Jason has the old one. Every time a new version of Word comes out, I worry that the macro may be broken because of age. I used to check often, but few enough people seem to include pictures and I've gotten careless. So I really do appreciate it that John has verified it.

Jason, if you send me your MDF template, I can check which macro you have. And if you include the RTF output from Toolbox, then I can experiment, if necessary. It doesn't have to be your whole document, but please be sure that what you send has one or more \pc fields in it. I can rename my own pictures and create a structure like you have. Hopefully I can figure out what the problem is.

Again, thanks to all!

Karen
Toolbox Support


Jason Lee

unread,
Mar 2, 2022, 4:54:32 PM3/2/22
to Shoebox/Toolbox Field Linguist's Toolbox
Thanks everyone for the advice. I've managed to fix this problem doing a few things, but I'm not sure which of the things I did actually fixed the problem:

1) I made a copy of the MDF_e.dot Word template in my \Settings folder and changed the 'InsertGraphics' macro (mostly copy-pasted) from the original to the one below (which uses VBA calls rather than WordBasic calls).
2) I changed the syntax of the \pc field in my lexical database to have two dots after the 'G' and the .bmp file extension after the file name (I also added height and width in centimetres), e.g.:
\pc .G..\bmp\Acacia_dunnii.bmp;7;7
3) I exported the MDF file into the same folder where my Toolbox lexicon, interlinear texts and other Toolbox data files were (instead of a separate \exports subfolder). This is also where my \bmp graphics subfolder resides.

I'm not sure if all three above contributed to solving the problem, or if any of the three above were unnecessary.

My next conundrum is how to add a macro that attaches a caption to the graphic with the contents of the \lx headword or \lc citation form? Useful if the graphic gets inserted onto the next page!

Thanks everyone once again!

Jason


Private Sub InsertGraphics()
'rewrite of "InsertGraphic" macro to use VBA calls rather than WordBasic calls
'using VBA, it doesn't need to do a search to find the picture frames
'It also does not require dimensions or image type to be specified.
'More reliable in inserting long file or path names.
' Steve White, Language Software Support, Jaars
' Modified by Karen Buseman, SAG, to support standard fixed size (optional)
' also made dimensions use centimeters rather than inches
Dim shpConvert As Shape

'The pic field data examples:
'no dimensions specified: \pic aehu.bmp
' (if no dimensions specified, Word uses defaults, which are probably the native image size, or the space available on the page
'dimensions specified: \pic c:\my documents\my pictures\aehu.bmp;5;2.5
' (height is specified first, then width -- so this is 5 cm high, 2.5 cm wide)
For Each aframe In ActiveDocument.Frames
On Error GoTo errorhandler
'
' *** NOTICE *** NOTICE *** NOTICE *** NOTICE ***
' To change the standard size
' Change the sHeight$ and sWidth$ values below
' Dimensions are in centimeters
' Modified Jan 16, 2010 KB
sHeight$ = "2.6" ' 26 mm
sWidth$ = "3.4" ' 34 mm
sField$ = aframe.Range
aframe.Range.Delete
lenField = Len(sField$) '23
' 'Sometimes when an image link is near the beginning of the entry, VBA detects
' 'an extra frame with no contents.
If lenField = 0 Then GoTo nextaframe

iAfterFilePath = InStr(1, sField$, ";") '9
If (iAfterFilePath) > 0 Then
sFilePath$ = Mid(sField$, 1, iAfterFilePath - 1) '
iAfterWidth = InStr(iAfterFilePath + 1, sField$, ";") '15
lenWidth = iAfterWidth - iAfterFilePath - 1 '5
sWidth$ = Mid(sField$, iAfterFilePath + 1, lenWidth) '1.25"
iAfterHeight = InStr(iAfterWidth + 1, sField$, ";") '20
If (iAfterHeight) > 0 Then
lenHeight = iAfterHeight - iAfterWidth - 1 '4
Else
lenHeight = lenField - iAfterWidth
End If
sHeight$ = Mid(sField$, iAfterWidth + 1, lenHeight) '1.1"
Else
sFilePath$ = sField$
End If
If InStr(sFilePath$, ":") = 0 Then sFilePath$ = ActiveDocument.Path + Application.PathSeparator + sFilePath$
aframe.Range.InlineShapes.AddPicture sFilePath$, False, True

' To disable the "standard size", reactivate the "if" and "end if" below
' Then only specified size and default size (actual size of picture?) will be active
' If (iAfterFilePath) > 0 Then
aframe.Height = CentimetersToPoints(Val(sHeight$))
aframe.Range.InlineShapes(1).Height = CentimetersToPoints(Val(sHeight$))
aframe.Width = CentimetersToPoints(Val(sWidth$))
aframe.Range.InlineShapes(1).Width = CentimetersToPoints(Val(sWidth$))
' End If

' Skip the shape conversion
SkipFrameRemoval = True
' Skip this part if the picture wasn't found
If SkipFrameRemoval = False Then

' these next two remove the frame
' then wrap settings are done on the result

aframe.Range.Select
Selection.Frames.Delete

' conversion to Shape is necessary for the wrap
' This section is from an internet website. It worked. I haven't messed with it.

With Selection.InlineShapes(1)
.LockAspectRatio = msoTrue
Set shpConvert = .ConvertToShape
End With
With shpConvert
.Left = ActiveDocument.PageSetup.TextColumns.Width - shpConvert.Width
.Left = wdShapeLeft
.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
With .WrapFormat
.Type = wdWrapInline
.Side = wdWrapRight
End With
End With
End If
SkipFrameRemoval = False ' set flag to OK for next picture


nextaframe:
Next aframe
Exit Sub

errorhandler:
' MsgBox "Error inserting picture file " + sFilePath$ + Chr(13) + "Is the path name correct?"
SkipFrameRemoval = True ' error flag, leave empty box
On Error Resume Next

Resume Next

End Sub   'InsertPictures

ToolBox Support

unread,
Mar 2, 2022, 6:15:23 PM3/2/22
to shoeboxtoolbox-fiel...@googlegroups.com
Congratulations, Jason!
The macro you installed is the "new" version and the first thing I would have tried. Most folks don't know how to install macros into a template, so I didn't even suggest that you try it.

At the very least, the other changes clearly haven't caused any problems. 

As for captions, I think I did something like that for someone, but I'll have to dig into my archives. I will and will let you know the outcome.

Karen
Toolbox Suport

Reply all
Reply to author
Forward
0 new messages