Wednesday, March 27, 2013

Turn On/Off all Workfeatures with iLogic

see this link for a version that handles traversing subassemblies:

Issue:

You have other members of your design team that do not remember to turn off work features at the part level or sub-assembly level when they are done working with those files. As a result file previews and view representations get messed up. You'd like to have a quick way to toggle all of the work features off. Can this be done with iLogic?





Solution:
You can use this example iLogic rule to toggle all work features on or off.




'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument 

'get user input as True or False
wfBoolean = InputRadioBox("Turn all Work Features On/Off", "On", "Off", False, "iLogic")

'Check all referenced docs
Dim oDoc As Inventor.Document
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = wfBoolean
    Next
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = wfBoolean
    Next
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = wfBoolean
    Next
Next
'update the files
InventorVb.DocumentUpdate()




Update 2/16/17:
Here is a version that handles sketches as well:
SyntaxEditor Code Snippet
'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument

'get user input as True or False
wfBoolean = InputRadioBox("Turn all Work Features On/Off", "On", "Off", False, "iLogic")

'Check all referenced docs 
Dim oDoc As Inventor.Document
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set work plane visibility
    For Each oWorkPlane In oDoc.ComponentDefinition.WorkPlanes
    oWorkPlane.Visible = wfBoolean
    Next
    'set work axis visibility
    For Each oWorkAxis In oDoc.ComponentDefinition.WorkAxes
    oWorkAxis.Visible = wfBoolean
    Next
    'set work point visibility
    For Each oWorkPoint In oDoc.ComponentDefinition.WorkPoints
    oWorkPoint.Visible = wfBoolean
    Next    
    'set sketch visibility
    For Each oSketch In oDoc.ComponentDefinition.Sketches
    oSketch.Visible = wfBoolean
    Next
Next

'update the files
InventorVb.DocumentUpdate()

Monday, March 25, 2013

Determine File Type for iLogic Rule

Issue:
You need your iLogic code to check to see if the file type is a part file first, before running. Otherwise it generates an error. Is there a way to do this?



Solution: 
Here are a couple of quick code snippets that demonstrate how to do this using the DocumentType enumerators:

'start of iLogic rule - - - - - - - - - - - - - - - - - -

doc = ThisDoc.ModelDocument
 'check file type
If doc.DocumentType = kPartDocumentObject Then
MessageBox.Show("This is a part file.", "iLogic")
Else if doc.DocumentType = kAssemblyDocumentObject Then
MessageBox.Show("This is an assembly file.", "iLogic")
End if
 'end of iLogic rule - - - - - - - - - - - - - - - - - -

 
'start of iLogic rule - - - - - - - - - - - - - - - - - -
doc = ThisDoc.ModelDocument
 'check file type
If doc.DocumentType = kPartDocumentObject Then
'do nothing
Return
Else if doc.DocumentType = kAssemblyDocumentObject Then
'do something
MessageBox.Show("This is an assembly file.", "iLogic")
End if  
'end of iLogic rule - - - - - - - - - - - - - - - - - -



Here is a list of all of the the DocumentType enumerators available in the API:
kUnknownDocumentObject
kPartDocumentObject
kAssemblyDocumentObject
kDrawingDocumentObject
kPresentationDocumentObject
kDesignElementDocumentObject
kForeignModelDocumentObject
kSATFileDocumentObject 
kNoDocument

 Update July 02, 2013
Here is another version of the rule that will report the file type and check to see if a sketch is active. This example rule will report the file type even when editing within another file type. Meaning that if you have a part file active within an assembly, this rule reports that it is a part file.



'start of iLogic rule - - - - - - - - - - - - - - - - - -
Dim oDoc As Document
oDoc = ThisDoc.Document

If oDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject  Then
            If Typeof ThisApplication.ActiveEditObject Is Sketch Then
            MessageBox.Show("You have a sketch active in a part file.", "iLogic")
            Else
            MessageBox.Show("This is a part file.", "iLogic")
            End If
Else If oDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
            If Typeof ThisApplication.ActiveEditObject Is Sketch Then
            MessageBox.Show("You have a sketch active in an assembly file.", "iLogic")
            Else
            MessageBox.Show("This is an assembly file.", "iLogic")
            End If
Else If oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
            If Typeof ThisApplication.ActiveEditObject Is Sketch Then
            MessageBox.Show("You have a sketch active in a drawing file.", "iLogic")
            Else
            MessageBox.Show("This is a drawing file.", "iLogic")
            End If
End If
'end of iLogic rule - - - - - - - - - - - - - - - - - -   

 
Update 5/27/2014
Luke Davenport's blog article "iLogic – Exit Rule Based on File Type"
http://www.cadlinecommunity.co.uk/Blogs/Blog.aspx?ScoId=d94fe4c0-e7d8-49ae-921d-04910a7d9740