I have this code to change all Occurences in an assembly (level 1). but sometimes I need it done on more Level .. it possible to get it to do it on all Level down. ?
Sub resetviewtocomplete()
Dim oDoc As AssemblyDocument = ThisDoc.Document
Dim oCompDef As Inventor.ComponentDefinition = oDoc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc In oCompDef.Occurrences
Try
oCompOcc.SetDesignViewRepresentation("Default",,True)
Catch
'MessageBox.Show("This viewrep does not exist", "Error")
End Try
Next
End Sub
Hi @Darkforce_the_ilogic_guy. We could certainly create an iLogic rule that uses a 'recursive' Sub routine to iterate down through all levels of the assembly for this task, but I am not convinced that it would work out as expected. I suspect that the DVR (DesignViewRepresentation) named "Default" is a custom one (I use one like that too). When setting a 'custom' DVR to active, and setting it to be 'associative', there are certain restrictions involved. For instance, if we set a component representing a sub assembly to that DVR, and set it to associative, but the later processed the components within that sub assembly, and turned all of then to that DVR, and associative later, that would undo the associative setting of their parent sub assembly. These DVR's need to be set from the bottom to the top, and not from the top down to the bottom. This is because the sub assembly's DVR records what DVR all the components within that sub assembly are set to. So each level records the level below them.
If you were able to process the assembly from bottom (parts), to the next level sub assemblies, then the parent sub assemblies of those sub assemblies, and so on until we get to the main assembly, then that might work. Not real sure how to do that though. I know there are examples recursive routines that attempt to keep track of which 'level' they are on, but I do not recall an example like that which lets you process them in reverse order (lowest level first, then stepping up a level each time).
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.