hexagon logo

How to Insert Multiple Images Into the Report

Hi All,

A bit over a year ago I asked this question on how to have an image generated on the fly shown in the report. The very helpful answer provided by was to create a custom report label template and use an Events script to update the image when the label is run. This works great when I only have one image. What I'm trying to do now, though, is run multiple similar calculations using subroutines and bring an image from each into my program.

Right now, my subroutine uses a particular custom label template, containing a single image. The subroutine copies the image I want to show to the file referenced in the label and then shows the label. When I run my test program, the report as shown in the report window looks as I would expect - a different image is shown for each subroutine call. However, the printed PDF shows the last shown image repeated each time the label is used. The same thing happens if I hit the refresh icon in the report window - the refreshed report shows the same image repeated.

Here's the code that calls my label in the subroutine. The image is copied into the right name using the FILE/COPY command, and the label name is specified by a variable so I can switch between development/test and production versions:

ASSIGN/IMAGENAME=TMPDIR + QUEUESTRUCT.OUTFILENAME + ".bmp"
FILE/COPY,IMAGENAME,TMPDIR + "SHOW_temporary_image_file.bmp",OVERWRITE
REPORT/LABEL, FILENAME= REPTLABEL​


Here's the event update code in the label template, under event "EventReportData":

this.Bitmap = "C:\CMM_local_data\tmp\SHOW_temporary_image_file.bmp"


The only thing in my label template is this bitmap object.

Is there some way (perhaps specifying a different event? How would I do that?) to "lock" the label template to the image it loads when the REPORT/LABEL command is called? Is there another way to accomplish loading multiple different images through a label template like this?
  • Thanks for bringing this up. I haven't played with this way of putting images into a report until now. I'm now seeing that it may have helped me with some projects in the past.

    To put multiple static images into a report using report labels I think it might work best to create a separate label for each image and then insert each of those into your measuring routine using separate commands.

    The method you described to use an even to select the image would not be necessary for a single static image. You could just create a new report label, adjust the size so it works with the rest of your reporting, then add an image object. When you do that the following dialog window opens.


    Clicking the Load button will open a dialog window to let you select an image ​to use. If the Link check box is checked, the picture will be loaded from that file each time the label is used. If the box is unchecked it will embed the image into the label and will always remain the same, even if the original image is edited or moved.

    I tested this a bit and found that using the Link option doesn't work as dynamically as expected. I created a label and put in a picture using the link option. I inserted that into a measuring routine. I then edited the picture and ran the measuring routine offline. The picture did not update to the new edited image. I tried closing and reopening the measuring routine and then re-running the routine again. Still, the image in the report label did not update. I completely closed PC-DMIS, re-opened it and re-ran the measuring routine. Now, the image updated on the report. So, 's method would still be the way to go if you want to put in an image on the fly. But for an image that will only be updated occasionally, you could just use the link option.

    Also, just a note, I was having issues using .jpg images. They didn't scale right. .Bmp images worked better.
  • Yeah, I found the same thing - the image doesn't update like it's supposed to unless you force it using a trick like showed me.

    Creating a separate label should work, but since I'm trying to do this in a subroutine calling a different label each time would be a pain in the neck. I'd probably have to have a "master" label template file that I'd programmatically copy to a unique name and then load. I was hoping there would be a setting somewhere that would fix my issue without all that rigamarole.

    I've been sticking with .bmp just to avoid the quality degradation that .jpg files produce. It would be really nice if they would support a modern decent file type like .png, but apparently no dice on that one...
  • I modified my code to copy the label, then use the copy, and it seems to work pretty well! Both the report window and the PDF show the right images. The only thing is that if you regenerate the report with the temporary copies deleted, it freaks out; but we shouldn't need that functionality in production. The kludge didn't even end up taking all that much code. Thank you for your thoughts Cris_C!
  • I played around with this some. I modified the image label to look for a variable inside of pcdmis (ASSIGN statement).

    On the EventReportData event for the bitmap I put the lines

    Dim Command As Object
    Dim imagePath As String
    Dim assignName As String
    Dim done As integer
    
    imagePath = "D:\Temp\label1.jpg" ' give it a default
    
    Set Command = ReportData.GetCommand
    done = 0
    
    While Not(Command is Nothing) And done <> 1
        If Command.Type = 195 Then
             assignName = Command.GetText(133, 1)
             If assignName = "IMAGEPATH" Then
                imagePath = Command.GetText(134, 1)
                If Mid(imagePath, 1, 1) = """" Then   ' strip off added quotes
                   imagePath = Mid(imagePath, 2, Len(imagePath)-2)
                End If
                done = 1
             End If
       End If  
       Command.Prev
    Wend
    
    this.bitmap = imagePath
    ​


    which looks into the PRG from the REPORT command going backwards for the variable IMAGEPATH and uses the value to create the image on the report.

                ASSIGN/IMAGEPATH="D:\TEMP\MYLABEL.JPG"
                REPORT/LABEL, FILENAME= IMAGELABEL.LBL
                ASSIGN/IMAGEPATH="D:\TEMP\SMART2.JPG"
                REPORT/LABEL, FILENAME= IMAGELABEL.LBL
                ASSIGN/IMAGEPATH="D:\TEMP\IMAGE.JPG"
                REPORT/LABEL, FILENAME= IMAGELABEL.LBL
    ​


    I used my path and JPG files as I was just seeing if it would work.
    Seems to with my limited testing.

    195 is the ASSIGN statement type
    133 is the destination variable name
    134 is the source expression
  • , this is so cool, and a much cleaner way of doing it than I'm using now! But does it depend on the assign statement directly stating a path to the image? In my case, I'm getting the path from combining a couple of different other variables - a GetText command might not read that correctly.
  • that one not so simple. You may have to always use specific files for the LABEL. Not as nice but use your expression path to copy the file you want to the specific name before the REPORT/LABEL.
  • Ok, that's more like what I've been doing. The only problem was that if I use the same label more than once, it ends up repeating the image, so I needed to copy the label as well.