• Blog posts

    Bio

    by Clint Brown

    I was recently asked for some help with emailing Inventor Part files for review, and I came up with a bit of iLogic code to help.

    The idea is to first check that the current document is a part file, to then roll up the end of part, as this reduces the file size ( if you are not familiar with this principle, see Autodesk MFG Blog for more info), and to then attach the file to an email automatically.

    The file type check I have used is very simple, yet effective, in my code, I look for the document type "

    kPartDocumentObject" which tells me that this is indeed a part file.


    Rolling up the EOP is relatively simple. The code below will do this for you, incidentally, if you change the (True) at the end of the line to (False), it will roll it back down for you.

    ThisDoc.Document.ComponentDefinition.SetEndOfPartToTopOrBottom(True)

    On the email front, I based my code on some work that Curtis Waguespack did in his blog post "Using Inventor iLogic to Create E-Mail Notifications with Outlook" I have formatted the email in such a way that the user does not need to specify anything more than the name of the person they wish to email, and their email address, the code does the rest.

    The video below shows how the code works, and the code is located at the bottom of the blog post. 

    '------- Start of iLogic code -------------------
    'Email Part of the Code adapted by Clint Brown @ClintCadline from Curtis Waguespack's blog
    'http://inventortrenches.blogspot.co.uk/2011/04/using-inventor-ilogic-to-create-e-mail.html
    
    'Ensure that this is a part file, exit on other files
    oDoc = ThisDoc.ModelDocument
    If oDoc.DocumentType = kPartDocumentObject
    OType = 1
    Else 
    OType = 0
    End If
    If OType = 0
    MessageBox.Show("Email Code will only run on Part files", "Cadline")
    
    Return
    End If
    
    'Roll up end of Part
    ThisDoc.Document.ComponentDefinition.SetEndOfPartToTopOrBottom(True)
    
    'Create Email Contents
    oPerson = InputBox("Specify name of person you are sending the email to", "Cadline", "")
    oEmailAddress = InputBox("Specify Email address", "Cadline", "")
    oOApp = CreateObject("Outlook.Application")
    oOMail = oOApp.CreateItem(olMailItem)
    oAdressee = "Dear " + oPerson & vbLf & vbLf & "Attached please find '"
    oFileName = ThisDoc.FileName + "' for review"  & vbLf & vbLf & "Kind Regards"
    oFrom = iProperties.Value("Summary", "Author")
    'Create Email & Add Attachments
    With oOMail
    .To = oEmailAddress
    .Subject = "Please review " + ThisDoc.FileName
    .Body = oAdressee + oFileName & vbLf & vbLf & oFrom
    objOutlookAttach = .Attachments.Add(ThisDoc.PathAndFileName(True))
    .Display
    End With
    '------- end of iLogic code -------------------