Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to create a rule to automatically create a view representation for all parts in the main assembly and all parts within the subassembly as well. I Found a code that allows me to create a view rep for the parts but does not seem to work for the subassembly parts. Note that it creates the view rep for each part in the subassembly but does not turn the visibility of that part on.
See the code I have been using below
'create a design view representation for each unique part in the assembly
'define current document
Dim openDoc As Document
openDoc = ThisDoc.Document
'set a reference to the assembly component definintion.
'this assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'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 view rep
Dim oViewRep As DesignViewRepresentation
'define an arraylist to hold the list of view rep names
Dim NameList As New ArrayList()
'Look at the view reps in the assembly
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
'set the list of names to the array list
NameList.add(oViewRep.Name)
Next
'check for a Default view rep and create it if not found
If Not NameList.Contains("Default") Then
'create Default view rep
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("Default")
oViewRep.ShowAll
oViewRep.Activate
End If
'zoom all
ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
'look at all of the unique parts in the assembly
For Each docFile In openDoc.AllReferencedDocuments
If docFile.DocumentType = 12290 Then '12290 is the part document enumurator
'locate the last backslash position in the full file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
'remove path from part file name
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'remove extension from part file name
ShortName = Left(docFName, Len(docFName) - 4)
'check to see if the arraylist contains the desired view rep
If Not NameList.Contains(ShortName) Then
'create new View Rep
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(ShortName)
oViewRep.Activate
oViewRep.Locked = False
Else If NameList.Contains(ShortName) Then
'reference existing View Rep
oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(ShortName)
oViewRep.Activate
oViewRep.Locked = False
End If
'look at all of the occurences
For Each oCompOcc in oCompDef.Occurrences
'locate the colon position in the occurence name
oCompOccPos = InStrRev(oCompOcc.Name, ":")
'set occurence name to everything left of the colon
oOccName = Left(oCompOcc.Name, oCompOccPos -1)
'set visible if name matches first occurence
If oCompOcc.Name = ShortName & ":1" Then
oCompOcc.Visible = True
ThisApplication.ActiveView.Update()
Else
oCompOcc.Visible = False
ThisApplication.ActiveView.Update()
End If
Next
End If
'lock view rep
oViewRep.Locked = True
Next
'set Default View Rep active
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
Solved! Go to Solution.

