hexagon logo

PC-DMIS Email Routine Complete Notification

PC-DMIS Email Routine Complete Notification

The other day the HxGN SFx was unable to send a notification to let me know that the routine was complete.
I decided to create a Email notification to let me know that the routine was finish measuring the part.
This script is set as default to send yourself an email. There are options to send the email using
cc and bcc. I am using TraceFields to control the input information.

PC-DMIS Routine Code:
PART NAME : Email Test
REV NUMBER : A
SER NUMBER :
STATS COUNT : 1

STARTUP =ALIGNMENT/START,RECALL:USE_PART_SETUP,LIST=YES
ALIGNMENT/END
MODE/MANUAL
FORMAT/TEXT,OPTIONS, ,HEADINGS,SYMBOLS, ;NOM,TOL,MEAS,DEV,OUTTOL, ,
LOADPROBE/3BY30_5W_M3_SH_2
TIP/TIP1, SHANKIJK=0, 0, 1, ANGLE=0

START_MENU_LT1=GROUP/SHOWALLPARAMS=YES
START_MENU_START_L1 =LABEL/

TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Part ID ; Part ID : PN00001
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Rev Number ; Rev Number : R1
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Lot Number ; Lot Number : LN0000A01
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Serial Number ; Serial Number : SN1
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Cavity ; Cavity : CN1
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Machine Recall ID ; Machine Recall ID : 0000
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=> Use Routine Complete Email Notification ; USE_EMAIL_NOTIF : Yes
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=' View Routine Complete Email Notification Controls ; VIEW_EMAIL_NOTIF_CTRLS : Yes

START_MENU_END_L1 =LABEL/
ENDGROUP/ID=START_MENU_LT1

EMAIL_ROUTINE_COMPLETE_GRP1=GROUP/SHOWALLPARAMS=YES
EMAIL_ROUTINE_COMPLETE_START_L1 =LABEL/

IF_GOTO/GETTRACEVALUE("USE_EMAIL_NOTIF")=="No",GOTO = EMAIL_ROUTINE_COMPLETE_END_L1
IF/GETTRACEVALUE("VIEW_EMAIL_NOTIF_CTRLS")=="Yes"
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Cc: (Carbon Copy) ; Cc :
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Bcc: (Blind Carbon Copy) ; Bcc :
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Subject: ; Subject : "Inspection complete for "+GETPROGRAMINFO("PARTNAME")+"_"+GETPROGRAMINFO("R EVISION")
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Machine Info: ; Machine Info : "Machine Recall ID: "+GETTRACEVALUE("Machine Recall ID")
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Part Info: ; Part Info : "Part Info: "+GETTRACEVALUE("Lot Number")+"_"+GETTRACEVALUE("Serial Number")+"_"+GETTRACEVALUE("Cavity")
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Run Time: ; Run Time : "Run Time: "+ELAPSEDEXECUTIONTIME()
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Total Number of Measured: ; Total Measured : "Total Measured: "+GETPROGRAMINFO("NUMMEAS")
TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Number Out of Tolerance: ; Total OutTol : "Total OutTol: "+GETPROGRAMINFO("NUMOOT")
END_IF/
EMAIL_ROUTINE_COMPLETE_CS1 =SCRIPT/FILENAME= C:\USERS\PUBLIC\DOCUMENTS\HEXAGON\ROUTINE BUILDER\ROUTINE BASIC SCRIPTS\EMAILSCRIPTTRACEFIELD1.BAS
FUNCTION/Main,SHOW=NO,ARG1=GETTRACEVALUE("Cc"),ARG2=GETTRAC EVALUE("Bcc"),ARG3=GETTRACEVALUE("Subject"),$
ARG4=GETTRACEVALUE("Machine Info"),ARG5=GETTRACEVALUE("Part Info"),$
ARG6=GETTRACEVALUE("Run Time"),ARG7=GETTRACEVALUE("Total Measured"),$
ARG8=GETTRACEVALUE("Total OutTol"),,
STARTSCRIPT/

EMAIL_ROUTINE_COMPLETE_END_L1 =LABEL/
ENDGROUP/ID=EMAIL_ROUTINE_COMPLETE_GRP1


Basic Script Code:

Sub main( pcOutLookCC, pcOutLookBCC, pcOutLookSub, pcOutLookMachInfo, pcPartInfo, pcRunTime, pcMeas, pcOutTol As String )
'
Dim outLookApp, outMail, pcApp, pcPart, outLookAllUsers, outLookExchUser, outLookEntry, myItem As Object
Dim outLookUser As String
'
Set outLookApp = CreateObject("Outlook.Application")
Set outLookAllUsers = outLookApp.Session.AddressLists.Item("All Users").AddressEntries
outLookUser = outLookApp.Session.CurrentUser.Name
Set outLookEntry = outLookAllUsers.Item(outLookUser)
Set outLookExchUser = outLookEntry.GetExchangeUser()
Set outMail = outLookApp.CreateItem(0)
'
outMail.To = outLookExchUser.PrimarySmtpAddress
outMail.cc = pcOutLookCC
outMail.bcc = pcOutLookBCC
outMail.Subject = pcOutLookSub
'
Dim msgHtmlBody1, msgHtmlBody2, msgHtmlBody3, msgHtmlBody4, msgHtmlBody5, msgHtmlBody6 As String
msgHtmlBody1 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcOutLookMachInfo &" "& "</BODY>"
msgHtmlBody2 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcPartInfo &" "& "</BODY>"
msgHtmlBody3 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcRunTime &" "& "</BODY>"
msgHtmlBody4 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcMeas &" "& "</BODY>"
msgHtmlBody5 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcOutTol &" "& "</BODY>"
msgHtmlBody6 = "<BODY style=font-size:11pt;font-family:Calibri><br/>This is an automated message.</BODY>"
outMail.htmlBody = msgHtmlBody1 & msgHtmlBody2 & msgHtmlBody3 & msgHtmlBody4 & msgHtmlBody5 & msgHtmlBody6
sendMsg = outMail.Send
'
Set outLookApp = Nothing
Set outLookAllUsers = Nothing
Set outLookEntry = Nothing
Set outLookExchUser = Nothing
Set outMail= Nothing
'
End Sub
'
'Notes:
'
'Insert Basic Script command into Routine
'
'EMAIL_ROUTINE_COMPLET_CS1 =SCRIPT/FILENAME= C:\USERS\Public\DOCUMENTS\HEXAGON\ROUTINE BUILDER\ROUTINE BASIC SCRIPTS\EMAILSCRIPTTRACEFIELD1.BAS
' Function/Main,SHOW=NO,ARG1=GETTRACEVALUE("Cc"),ARG2=GETTRAC EVALUE("Bcc"),ARG3=GETTRACEVALUE("Subject"),$
' ARG4=GETTRACEVALUE("Machine Info"),ARG5=GETTRACEVALUE("Part Info"),$
' ARG6=GETTRACEVALUE("Run Time"),ARG7=GETTRACEVALUE("Total Measured"),$
' ARG8=GETTRACEVALUE("Total OutTol"),,
' STARTSCRIPT/
'
'Email Sample Output
'
'Inspection complete For Email Test_A
'
'Machine Recall ID: 0000
'Part Info: LN0000A01_SN1_CN1
'Run Time: 00:00:00
'Total Measured: 0
'Total OutTol: 0
'
'This is an automated message.



  • I am testing the attachment code and should be able to post the code this week.
  • ah, that's why.
    I was experimenting with a gmail script today and it just wouldn't connect.
    Is there a way around it?
  • The security settings will have to be change to a setting that is no longer protected by modern security standards.

    Here is a link I found Gmail for Developers Gmail API.
    https://developers.google.com/gmail/api/guides/sending
  • PC-DMIS Email Routine Complete Notification with Attachments

    I am using the Excel Form Report to create the Text Reports to be used for the attachments and will be overwritten.
    This example can be edited to use a different file directory to add the attachments.
    I also added the option to add a report folder directory to the email.

    PC-DMIS Routine:
    PART NAME  : Email Test
    REV NUMBER : A
    SER NUMBER :
    STATS COUNT : 1
     
    STARTUP    =ALIGNMENT/START,RECALL:USE_PART_SETUP,LIST=YES
                ALIGNMENT/END
                MODE/MANUAL
                FORMAT/TEXT,OPTIONS, ,HEADINGS,SYMBOLS, ;NOM,TOL,MEAS,DEV,OUTTOL, ,
                LOADPROBE/3BY30_5W_M3_SH_2
                TIP/TIP1, SHANKIJK=0, 0, 1, ANGLE=0
    START_MENU_LT1=GROUP/SHOWALLPARAMS=YES
    START_MENU_START_L1  =LABEL/
      $$ NO,
                  <When using STATS_LT Group change the START_MENU_LT Group TraceFields using REPORT=YES to REPORT=NO>
                  <Use a new measurement routine to create a new UID>
                  ASSIGN/DATE_V1=SYSTEMDATE("MM/dd/yyyy")
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Part ID ; Part ID : PN00001
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Rev Number ; Rev Number : R1
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Lot Number ; Lot Number : LN0000A02
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Serial Number ; Serial Number : SN1
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Cavity ; Cavity : CN1
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Machine Recall ID ; Machine Recall ID : 3435 3436 3271 5472 5473
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=> Use Routine Complete Email Notification ; USE_EMAIL_NOTIF : Yes
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE='  View Routine Complete Email Notification Controls ; VIEW_EMAIL_NOTIF_CTRLS : Yes
                  TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=> Save Report Directory ; Save Report Directory : E:\Users\Public\Documents\Hexagon\PC-DMIS Measurement Routine Directory\PC-DMIS Offline\2022.1\Reports
    START_MENU_END_L1  =LABEL/
                ENDGROUP/ID=START_MENU_LT1
    EMAIL_ROUTINE_COMPLET_START_L1  =LABEL/
                  IF_GOTO/GETTRACEVALUE("USE_EMAIL_NOTIF")=="No",GOTO = EMAIL_ROUTINE_COMPLET_END_L1
                  IF/GETTRACEVALUE("VIEW_EMAIL_NOTIF_CTRLS")=="Yes"
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Cc: (Carbon Copy) ; Cc :
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Bcc: (Blind Carbon Copy) ; Bcc :
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Subject: ; Subject : "Inspection complete for "+GETPROGRAMINFO("PARTNAME")+"_"+GETPROGRAMINFO("R EVISION")
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Machine Info: ; Machine Info : "Machine Recall ID: "+GETTRACEVALUE("Machine Recall ID")
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Part Info: ; Part Info : "Part Info: "+GETTRACEVALUE("Lot Number")+"_"+GETTRACEVALUE("Serial Number")+"_"+GETTRACEVALUE("Cavity")  
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Run Time: ; Run Time : "Run Time: "+ELAPSEDEXECUTIONTIME()
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Total Number of Measured:  ; Total Measured : "Total Measured: "+GETPROGRAMINFO("NUMMEAS")
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Number Out of Tolerance:  ; Total OutTol : "Total OutTol: "+GETPROGRAMINFO("NUMOOT")
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Add Attachment Report Type: ; Attachment : Routine Report
                    TRACEFIELD/DISPLAY=YES,REPORT=NO,DISPLAY MESSAGE=Add Report File Directory: ; Add File location : Yes
                  END_IF/
                  IF/GETTRACEVALUE("Attachment")=="Routine Report" OR GETTRACEVALUE("File location")=="Yes" OR (GETTRACEVALUE("Attachment")=="Routine Out of Tolerance Report" AND (GETPROGRAMINFO("NUMOOT") > 0))
    EMAIL_EXCEL_FORM1    =EXCELFORMREPORT/TEMPLATE=Form Row Wise Email Attachment, TYPE=TXT
                    RESULT FOLDER/PCDMISSYSTEMVISIBLEDATAPATH()
                  END_IF/
    EMAIL_ROUTINE_COMPLET_CS1  =SCRIPT/FILENAME= C:\USERS\PUBLIC\DOCUMENTS\HEXAGON\ROUTINE BUILDER\ROUTINE BASIC SCRIPTS\EMAILSCRIPTTRACEFIELD1.BAS
                  FUNCTION/Main,SHOW=NO,ARG1=GETTRACEVALUE("Cc"),ARG2=GETTRAC EVALUE("Bcc"),ARG3=GETTRACEVALUE("Subject"),$
                      ARG4=GETTRACEVALUE("Machine Info"),ARG5=GETTRACEVALUE("Part Info"),$
                      ARG6=GETTRACEVALUE("Run Time"),ARG7=GETTRACEVALUE("Total Measured"),$
                      ARG8=GETTRACEVALUE("Total OutTol"),ARG9=PCDMISSYSTEMVISIBLEDATAPATH(),$
                      ARG10=GETTRACEVALUE("Attachment"),ARG11=GETTEXT("OutputFileType",0,GETCOMMAND(32000,"UP",1)),$
                      ARG12=GETTRACEVALUE("Add File location"),ARG13=GETTRACEVALUE("Save Report Directory"),,
                  STARTSCRIPT/
    EMAIL_ROUTINE_COMPLET_END_L1  =LABEL/
                ENDGROUP/ID=EMAIL_ROUTINE_COMPLET_GRP1
    


    Basic Script
    Sub main( pcOutLookCC, pcOutLookBCC, pcOutLookSub, pcOutLookMachInfo, pcPartInfo, pcRunTime, pcMeas, pcOutTol, pcAttachPath, pcAttachName, pcAttachExt, pcFileLoc, pcSaveDir As String )
    '
      Dim outLookApp, outMail, pcApp, pcPart, outLookAllUsers, outLookExchUser, outLookEntry As Object
      Dim outLookUser As String
      Dim pcAttach As String
    '  
      Set outLookApp = CreateObject("Outlook.Application")
      Set outLookAllUsers = outLookApp.Session.AddressLists.Item("All Users").AddressEntries
            outLookUser = outLookApp.Session.CurrentUser.Name
      Set outLookEntry = outLookAllUsers.Item(outLookUser)
      Set outLookExchUser = outLookEntry.GetExchangeUser()
      Set outMail = outLookApp.CreateItem(0)
    '      
            outMail.To = outLookExchUser.PrimarySmtpAddress
            outMail.cc = pcOutLookCC
            outMail.bcc = pcOutLookBCC
            outMail.Subject = pcOutLookSub
    '
            If Not pcAttachName = "None" Then
                pcAttach = pcAttachPath+pcAttachName & "." & pcAttachExt
                outMail.Attachments.Add pcAttach
            End If
            If pcFileLoc = "Yes" Then
                pcAttach = "Report Folder Directory: " & pcSaveDir
            ElseIf pcFileLoc = "No" Then
                pcAttach = " "
            End If  
    '  
      Dim msgHtmlBody1, msgHtmlBody2, msgHtmlBody3, msgHtmlBody4, msgHtmlBody5, msgHtmlBody6, msgHtmlBody7  As String
             msgHtmlBody1 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcOutLookMachInfo &" "& "</BODY>"
             msgHtmlBody2 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcPartInfo &" "& "</BODY>"
             msgHtmlBody3 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcRunTime &" "& "</BODY>"
             msgHtmlBody4 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcMeas &" "& "</BODY>"
             msgHtmlBody5 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcOutTol &" "& "</BODY>"
             msgHtmlBody6 = "<BODY style=font-size:11pt;font-family:Calibri></BODY>" & pcAttach &" "& "</BODY>"
             msgHtmlBody7 = "<BODY style=font-size:11pt;font-family:Calibri><br/>This is an automated message.</BODY>"
             outMail.htmlBody = msgHtmlBody1 & msgHtmlBody2 & msgHtmlBody3 & msgHtmlBody4 & msgHtmlBody5 & msgHtmlBody6 & msgHtmlBody7
             sendMsg = outMail.Send  
    '
     Set outLookApp = Nothing  
     Set outLookAllUsers = Nothing
     Set outLookEntry = Nothing
     Set outLookExchUser = Nothing
     Set outMail= Nothing
    '
    End Sub
    '
    'Notes:
    '
    'Insert Basic Script command into Routine
    '
    'EMAIL_ROUTINE_COMPLET_CS1  =SCRIPT/FILENAME= C:\USERS\Public\DOCUMENTS\HEXAGON\ROUTINE BUILDER\ROUTINE BASIC SCRIPTS\EMAILSCRIPTTRACEFIELD1.BAS
    '              Function/Main,SHOW=NO,ARG1=GETTRACEVALUE("Cc"),ARG2=GETTRAC EVALUE("Bcc"),ARG3=GETTRACEVALUE("Subject"),$
    '                  ARG4=GETTRACEVALUE("Machine Info"),ARG5=GETTRACEVALUE("Part Info"),$
    '                  ARG6=GETTRACEVALUE("Run Time"),ARG7=GETTRACEVALUE("Total Measured"),$
    '                  ARG8=GETTRACEVALUE("Total OutTol"),ARG9=PCDMISSYSTEMVISIBLEDATAPATH(),$
    '                  ARG10=GETTRACEVALUE("Attachment"),ARG11=GETTEXT("OutputFileType",0,GETCOMMAND(32000,"UP",1)),$
    '                  ARG12=GETTRACEVALUE("Add File location"),ARG13=GETTRACEVALUE("Save Report Directory"),,
    '              STARTSCRIPT/
    '
    'Email Sample Output
    '
    'Inspection complete For Email Test_A
    '
    'Machine Recall ID: 0000
    'Part Info: LN0000A01_SN1_CN1
    'Run Time: 00:00:00
    'Total Measured: 0
    'Total OutTol: 0
    'Report Folder Location: C:\Users\Public\Documents\Hexagon\PC-DMIS\2022.1
    '
    'This is an automated message.