Thanks Curtis. Nice example wit the inventor assembly. I used the coding for my purpose. A little more to go in my model - I keep developing using iLogic to maintain data accuracy and ease of modelling.
With your code for the Design View Representations, I developed the coding for Positional Representations and Level of Detail as well and combined in to a one. With Level of Detail part runs first, t run well as required.
Sub Main()
Dim oName_PR As String
'set a reference to the assembly component definition.
'This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate
'define pos rep
Dim oLOD As LevelOfDetailRepresentation
Dim oLOD_Rqd As String
Dim oArray_LODs As New ArrayList
'record the active view rep name
Dim oActiveLOD As String
oActiveLOD = oAsmCompDef.RepresentationsManager.ActiveLevelOfDetailRepresentation.Name
For Each oLOD In oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations
oArray_LODs.add(oLOD.Name)
Next
oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item("Master").Activate
iArrayList = oArray_LODs.Count
oLOD_New = "To create new, CLICK!"
oArray_LODs.add(oLOD_New)
oLOD_Rqd = InputListBox("Select PREF from the list:", oArray_LODs, oActiveLOD, "iLogic", "SET Positional Rep. (PREF)")
If oLOD_Rqd = oLOD_New Then
newPosRep = InputBox("Enter a name:", "iLogic", "New Pos Rep_" & iArrayList)
newAngle = InputBox("Enter an Angle:", "iLogic", "5")
'create new pos rep
oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Add(newPosRep)
myAngle = newAngle
Else
'activate the selected pos rep
oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(oLOD_Rqd).Activate
End If
'activate the selected pos rep
oAsmCompDef.RepresentationsManager.LevelOfDetailRepresentations.Item(oLOD_Rqd).Activate
oPR()
oDefault()
oDVR()
ThisApplication.ActiveView.Fit
End Sub
Sub oPR()
Dim oName_PR As String
'set a reference to the assembly component definition.
'This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item("Master").Activate
'define pos rep
Dim oPosRep As PositionalRepresentation
Dim oPosRep_Rqd As String
Dim oArray_PosReps As New ArrayList
'record the active view rep name
Dim oActivePosRep As String
oActivePosRep = oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name
For Each oPosRep In oAsmCompDef.RepresentationsManager.PositionalRepresentations
oArray_PosReps.add(oPosRep.Name)
Next
oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item("Master").Activate
iArrayList = oArray_PosReps.Count
oPosRep_New = "To create new, CLICK!"
oArray_PosReps.add(oPosRep_New)
oPosRep_Rqd = InputListBox("Select PREF from the list:", oArray_PosReps, oActivePosRep, "iLogic", "SET Positional Rep. (PREF)")
If oPosRep_Rqd = oPosRep_New Then
newPosRep = InputBox("Enter a name:", "iLogic", "New Pos Rep_" & iArrayList)
newAngle = InputBox("Enter an Angle:", "iLogic", "5")
'create new pos rep
oAsmCompDef.RepresentationsManager.PositionalRepresentations.Add(newPosRep)
myAngle = newAngle
Else
'activate the selected pos rep
oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item(oPosRep_Rqd).Activate
End If
'activate the selected pos rep
oAsmCompDef.RepresentationsManager.PositionalRepresentations.Item(oPosRep_Rqd).Activate
End Sub
Sub oDefault()
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAsmCompDef As ComponentDefinition
oAsmCompDef = doc.ComponentDefinition
Dim oCompOcc As Inventor.ComponentOccurrence
For Each oCompOcc in oAsmCompDef.Occurrences
If oCompOcc.Visible = True Then
If oCompOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
oCompOcc.SetDesignViewRepresentation("Default", True)
Else
End If
Else
End If
'oCompOcc.SetDesignViewRepresentation("Default",, True)
On Error Resume Next
Next
End Sub
Sub oDVR()
'get the current assembly
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
'get AssemblyComponentDefinition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oDoc.ComponentDefinition
'get Manager of Representations
Dim oViewRepMgr As RepresentationsManager
oViewRepMgr = oAsmCompDef.RepresentationsManager
'define new ViewRep - oViewRep_Rqd
'Dim oViewRep As DesignViewRepresentation
Dim oViewRep_Rqd As String
Dim oArray_ViewReps As New ArrayList
'record the active view rep name
Dim oActiveViewRep As String
oActiveViewRep = oAsmCompDef.RepresentationsManager.ActiveDesignViewRepresentation.Name
For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations
oArray_ViewReps.add(oViewRep.Name)
Next
iArrayList = oArray_ViewReps.Count
oViewRep_New = "To create new, CLICK!"
oArray_ViewReps.add(oViewRep_New)
oViewRep_Rqd = InputListBox("Select PREF from the list:", oArray_ViewReps, oActiveViewRep(2), "iLogic", "SET Design View Rep. (DVR)")
If oViewRep_Rqd = oViewRep_New Then
newViewRep = InputBox("Enter a name:", "iLogic", "New View Rep_" & iArrayList)
'create new pos rep
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add(newViewRep)
Else
'activate the selected pos rep
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oViewRep_Rqd).Activate
End If
'activate the selected pos rep
oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oViewRep_Rqd).Activate
End Sub