Blog posts

Bio

by Luke Davenport

Issue:

So you’ve got a wonderful iLogic rule that only works with a certain type of Inventor file. Therefore you need your iLogic rule to automatically exit unless the right type of Inventor document is open and active. How can I do this easily?

 

Solution:

Use the handy code snippet below, simply ‘un-commenting’ (by removing the ‘ ) one of the first four lines of code. Paste the code straight into the start of any iLogic rule to ensure it only runs on the right type of files.

 

Note:

Uber Inventor-guru Curtis Waguespack has posted some similar code here:

 

http://inventortrenches.blogspot.co.uk/2013/03/determine-file-type-for-ilogic-rule.html

 

– which is definitely worth checking out. My rule below is slightly different – it’s a ‘one-size-fits-all’ rule that might save you a few seconds when copying and pasting.

 

Nice and simple. Enjoy!

 

' What document do you want? - comment out a single line as required….

Dim Doctype As String = "Part"

'Dim Doctype As String = "Sheet Metal"

'Dim Doctype As String = "Assembly"

'Dim Doctype As String = "Drawing"

 

 

oDoc = ThisApplication.ActiveDocument

 

Select Case DocType

 

Case "Part"

 

    If oDoc.DocumentType <> kPartDocumentObject Then

    MessageBox.Show("This rule can only be run in a " & DocType & " file - exiting rule...", "Cadline iLogic")

    Return

    End If

   

Case "Sheet Metal"

 

    If oDoc.ComponentDefinition.Type <> 150995200 Then

    MessageBox.Show("This rule can only be run in a " & DocType & " file - exiting rule...", "Cadline iLogic")

    Return

    End If

 

Case "Assembly"

 

    If oDoc.DocumentType <> kAssemblyDocumentObject Then

    MessageBox.Show("This rule can only be run in a " & DocType & " file - exiting rule...", "Cadline iLogic")

    Return

    End If

 

Case "Drawing"

 

    If oDoc.DocumentType <> kDrawingDocumentObject Then

    MessageBox.Show("This rule can only be run in a " & DocType & " file - exiting rule...", "Cadline iLogic")

    Return

    End If

 

End Select