This topic is in response to another thread:
http://forums.autodesk.com/t5/Autodesk-Inventor/ilogic-or-vb-help/m-p/3268448
I figured I'd start an new topic with the subject line that might come up in future searches in case it helps someone at some point.
Here's an ilogic rule to handle the view reps. I didn't test it all that thoughly, so I can't promise you won't find an error. Also note that it looks for a view rep of the same name it is trying to create, and deletes it if found. I think there is a better way to handle this, but I didn't find the time to work on this any further.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'define the Material being looked at Dim oMatl as Object oMatl = "Steel" 'define View Rep name Dim oNotMatl as Object oNotMatl = "No " & oMatl ' set a reference to the assembly component definintion. ' This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oViewRep As DesignViewRepresentation 'Look for an existing View Rep of the same name and delete it if found For Each oViewRep in oAsmCompDef.RepresentationsManager.DesignViewRepresentations If oViewRep.Name = "Master" Then 'set the Master View Rep to be active oViewRep.Activate 'if Master is already active, skip error On error Resume Next 'look for same name view rep Else if oViewRep.Name = oNotMatl Then 'delete same name view rep if found oViewRep.Delete Else End if Next 'create new View Rep oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(oNotMatl) 'define current document Dim openDoc As Document openDoc = ThisDoc.Document 'kAssemblyDocumentObject = 12291 If openDoc.DocumentType = 12291 Then 'look at all of the components in the assembly Dim oCompDef As Inventor.ComponentDefinition = openDoc.ComponentDefinition 'define the first level components collection Dim oCompOcc As Inventor.ComponentOccurrence 'define the next level components collection Dim oSubCompOcc As Inventor.ComponentOccurrence 'Turn off the visibility of parts in the top level assembly that are the specified mat'l For each oCompOcc in oCompDef.Occurrences If iProperties.Material (oCompOcc.Name) = oMatl Then 'Turn the visibility off oCompOcc.Visible = False End If 'Turn off the visibility of parts in the second level assemblies that are the specified mat'l For Each oSubCompOcc In oCompOcc.SubOccurrences 'select for part files with specified material If iProperties.Material (oSubCompOcc.Name) = oMatl Then 'Turn the visibility off oSubCompOcc.Visible = False End If Next Next Else MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!") End If