Wednesday, March 27, 2013

Turn On/Off all Workfeatures with iLogic

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()


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

Wednesday, February 27, 2013

Rule Fillet Incident Edges For Machined Corners


Issue:
You want a way to quickly add and update rounded corners that are cut with a particular size end mill when creating CNC router cut parts.

Solution:
Although the Rule Fillet tool is located on Inventor's Plastic Part tool panel, I find myself using its Face
selection Incident Edges option for machined parts cut on a CNC flat bed router all of the time.





Often I need to set the inside corners to match the cut diameter of the tooling to be used. Selecting all of these edges manually can be time consuming, error prone, and requires me to remember to update the selection set if I make a change. The Incident Edges option of the Rule Fillet tool can be used to select only vertical edges that come into contact with the selected faces.


Here a work piece is shown before and after the Rule Fillet tool is used to multi-select all of the corners that have incident edges contacting one or more selected faces. This criteria (all corner edges that contact the selected faces) defines the "rule".

Using the Incident Edges option of the Rule Fillet tool allows me to make changes to features in the feature tree, and then the Rule Fillet automatically picks up any new edges that are created, and removes any that are eliminated, without creating errors.


The Rule Fillet is set to match the end mill radius.





All of the vertical edges that contact the selected faces are selected.



If I only want to select inside corners where the endmill will cut, I can deselect the All Rounds checkbox.




If there are specific outside corners that I do not want to be radius-ed I can use the >> button to select faces or edges to exclude.




Using the Rule Fillet tool's Incident Edges option might not be the obvious choice for creating inside corner fillet for machined parts, but it can be a huge timesaver and help you eliminate errors along the way. Of course there are other options in the Rule Fillet tool that allow you to select edges based on features, feature contact, etc. so take some time to explore each option and give it a try and see if you can find a use for it in your designs.

Wednesday, January 23, 2013

iLogic: Delete All Sick Assembly Constraints

Issue:
You sometimes end up with a large number of broken (sick) assembly constraints, due to a particular workflow (such as swapping out a base component). You know why this is happening and don't mind fixing the assembly, but you wish there was a way to delete all of the sick assembly constraints at once, so you can re-constrain the assembly without having to be bothered by the alerts.



Solution:
Here is a quick iLogic snippet to help with this:

* A special thanks to Brendan Henderson for letting me know about a coding error I had when I first posted this. Check out Brendan's own blog at: http://www.blh.com.au/#/blog/4572268941             






Dim oAssDoc As AssemblyDocument
oAssDoc = ThisApplication.ActiveDocument
Dim oConstraint As AssemblyConstraint

RUSure = MessageBox.Show _
("Are you sure you want to Delete all sick constraints?",  _
"iLogic",MessageBoxButtons.YesNo)

If RUSure = vbNo Then
Return
Else
          i = 0
          For Each oConstraint In oAssDoc.ComponentDefinition.Constraints
            If oConstraint.HealthStatus <> oConstraint.HealthStatus.kUpToDateHealth And _
            oConstraint.HealthStatus <> oConstraint.HealthStatus.kSuppressedHealth Then
          oConstraint.Delete
            i = i + 1
          End If
          Next
End If
MessageBox.Show(" A total of "&  i & " constraints were deleted.", "iLogic")