Tuesday, April 19, 2011

Using Inventor iLogic to Create E-Mail Notifications with Outlook

Issue:
When you've made a design change, you'd like to use iLogic to create an email notification with the current file as an attachment to be sent to your client.



Solution:
Here is a sample code that will do the following tasks:

  • Time Stamp the current file
  • Fill out the status iProperties for the current file
  • Save the current file
  • Create a new email using Outlook that is addressed to the client's email
  • Add a basic message
  • Add the current file to the email as an attachment
  • Display the email (but don't send it)


'------- start of iLogic code -------------------


 ' Start Outlook.
 ' If it is already running, you'll use the same instance...
   Dim oOApp
   oOApp = CreateObject("Outlook.Application")
   
' Log on. Doesn't hurt if you are already running and logged on...
   Dim olNs
   olNs = oOApp.GetNamespace("MAPI")
   olNs.Logon

‘get the Inventor user name from the Inventor Options
myName= ThisApplication.GeneralOptions.UserName

'get current time
oTime = Now.ToShortTimeString

'set status tag to For Review and time stamp
iProperties.Value("Status", "Status") = "For Review @ " oTime

'set the Design State to Pending
iProperties.Value("Status", "Design State") = "Pending"

'set the Checked By to user name from the Inventor Options
iProperties.Value("Status", "Checked By") = myName

'set the Checked Date to the current date
iProperties.Value("Status", "Checked Date") = Now

'save the file
ThisDoc.Save

'send email using outlook
Dim oOMail

oOMail = oOApp.CreateItem(olMailItem)

With oOMail
            'replace with your client's email address
            .To = "myclient@domain.com"
            .Subject = "Please Review: " & ThisDoc.FileName
          .Body = "Please review " & ThisDoc.FileName & " and let me know if you see any issues."
            .Body = .Body & "Thanks, " & myname
            .Display

            'Add attachments to the message.
            objOutlookAttach = .Attachments.Add(ThisDoc.PathAndFileName(True))

End With
'------- end of iLogic code -------------------



The end result is an email waiting for you to hit the send button:


 Here are the results of the Status iProperties that are being set:



 To send an email automatically from iLogic, you can add .Send as in this example:

'------- Start of iLogic code -------------------

'send email using outlook
Dim oOApp
Dim oOMail

oOApp = CreateObject("Outlook.Application")
oOMail = oOApp.CreateItem(olMailItem)

With oOMail
.To = "name@domain.com"
.Subject = "Some Subject Line Here"
.Body = "Some Text Here"
'Add attachments to the message
objOutlookAttach = .Attachments.Add(ThisDoc.PathAndFileName(True))
.Send
End With
'------- end of iLogic code -------------------


Update: 5-27-2014
  For more on this topic, see this link for Clinton Brown's blog article "iLogic- Email your Part Files with EOP Rolled Up"