Hi,
I recently had a customer request for an iLogic code that would look through the components of an assembly and pick on a Custom iProperty called "Visibility", and toggle the component Visibility according to the property vaule "On" or "Off".
When I asked the customer why not just use the LOD functionality in Inventor he advised that this working rather slow for them and was not exactly what they where looking for.
Anyway, I just finished that code and thought I would share this in case it is needed as a whole or as an example on how to access the comoponents occurence iProperties.
'Set Assembly Component Deifiniton
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
Try
'MessageBox.Show(oOccurrence.Name, "iLogic")
'get the selected item document occurrence name
doc = oOccurrence.Definition.Document
'get the path and file name of the selected item
CurFileName = doc.FullFileName
'MessageBox.Show(CurFileName, "iLogic")
'Get the Document from the occurrence
docFile = oOccurrence.definition.Document
'Find position in full filename path string where component filename begins
FNamePos = InStrRev(doc.FullFileName, "\", - 1)
'Strip off filename path string and set docFName to just the component's file name
docFName = Mid(doc.FullFileName, FNamePos + 1, Len(docFile.FullFileName) - FNamePos)
'MessageBox.Show(docFName, "iLogic")
Dim oName As String
'Set oName to the current component occurrence name
oName = oOccurrence.Name
Try
'Check if custom iProperty "Vibility" is ON
If iProperties.Value(docFName, "Custom", "Visibility") = "On" Then
'MessageBox.Show(oName & " " & "=" & "On", "Title")
'Do NOT Suppress component
Component.Visible(oName) = True
Else If iProperties.Value(docFName, "Custom", "Visibility") = "Off" Then
'MessageBox.Show(oName & " " & "=" & "OFF", "Title")
'Suppress Component
Component.Visible(oName) = False
End If
'Move to next component if "Visibility" iProperty is not present on file
Catch ex As Exception
End Try
'Move to next component if component is already suppressed
Catch ex As Exception
End Try
Next
Hope this comes handy anyway...
Best Regards,
Vas