Hi,
We are using Inventor 2023.2.1.
Here is the error message:

DrawingView.ActivePositionalRepresentation also returns "[Primary]" for me but when I try to pass it in as an argument for addoverlayview, its gives me the error above, parameter incorrect.
This is the assembly without an additional positional representation which gives the error

If I add an additional positional representation, the code works fine and accepts "[Primary]" as an argument

Here is my code
Imports System.Collections.Generic
Class SparePartsListHighlightRed
Shared cutToLengthItems As New List(Of String)
Public oColor As Color
Public oBlue As Color
Public oRed As Layer
Public oTG As TransientGeometry
Public oDrawDoc As DrawingDocument
Public sparesSheet As Sheet ' We will track of our spares sheet object
Public hasSparesSheet As Boolean ' Keep track if we need to make a sheet
Public oDrawingView As DrawingView
Public oDataSets As GraphicsDataSets
Public oClientGraphics As ClientGraphics
Public Sub Main
'Definitions for highlighting
Dim oSketch As DrawingSketch
Dim oDC As DrawingCurve
' Set a reference to the drawing document.
oDrawDoc = ThisDoc.Document
If oDrawDoc.Sheets(1).DrawingViews.Count < 1 Then Exit Sub ' User hasn't placed their view yet
oDrawingView = oDrawDoc.Sheets(1).DrawingViews(1) ' Get a reference to the first drawing view placed on the first sheet
' This is where we will grab our model referene for the parts list
'--------------------------------------------
' Highlght Spares Items
'--------------------------------------------
' We will label our spare parts sheet in order to know which sheet to run our code on
' If a spare parts sheet doesn't exist, we need to create it
Dim oSheet As Sheet ' Just need this for the for loop
' Check if any are named spare parts and save a reference while we're at it
For Each oSheet In oDrawDoc.Sheets
' Logger.Debug("Sheet name: " & Left(oSheet.Name, (InStrRev(oSheet.Name, ":")-1)))
If Left(oSheet.Name, (InStrRev(oSheet.Name, ":")-1)) = "Spare Parts" Then ' Need to remove the :# at the end of each sheet
hasSparesSheet = True
sparesSheet = oSheet
End If
Next
'sparesSheet = oDrawDoc.Sheets(1)
'hasSparesSheet = True
' If we couldn't find it, there is nothing to highlight
If hasSparesSheet = False Then
MsgBox("No spare parts sheet found in drawing.")
Exit Sub
End If
' If there are no drawing views on the sheet, we don't need to do anything
If sparesSheet.DrawingViews.Count < 1 Then
MsgBox("No drawing views found on the sheet to highlight parts on.")
Exit Sub
End If
oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
oBlue = ThisApplication.TransientObjects.CreateColor(0, 0, 0)
oTG = ThisApplication.TransientGeometry
' oDataSets = sparesSheet.GraphicsDataSetsCollection.Item("CG_Test3")
' oDataSets.Delete
' oClientGraphics = sparesSheet.ClientGraphicsCollection.Item("CG_Test3")
' oClientGraphics.Delete
' Exit Sub
' Set up a vew rep for spare parts
' Creates a new View Rep "Active Components" and then turns all Reference Components visibility to off.
'It only turns On active Components at this level.
'Then returns back to original active View Rep when logic was initiated.
Dim odoc As Document
Dim oCompDef As ComponentDefinition
odoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
oCompDef = odoc.ComponentDefinition
'Sets initial View Rep
oActiveViewRep = oCompDef.RepresentationsManager.ActiveDesignViewRepresentation
'Creates New View Rep
Dim oviewrep2 As DesignViewRepresentation
Try
oCompDef.RepresentationsManager.DesignViewRepresentations.Item("Spare Parts").Activate
Catch
oviewrep2 = oCompDef.RepresentationsManager.DesignViewRepresentations.Add("Spare Parts")
End Try
'This sets some parameters to turn off ref components
oAssemblyComponents = oCompDef.Occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAssemblyComponents
Try
If oOccurrence.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("Wear Item").Expression = "Yes" Then
oOccurrence.Visible = True
Else
oOccurrence.Visible = False
End If
Catch
Try
oOccurrence.Visible = False
Catch
End Try
End Try
If oOccurrence.SubOccurrences.Count > 0 Then
TraverseAssembly(oOccurrence.SubOccurrences)
End If
Next
'Sets the view rep back to the one that was active before the rule was executed
' oActiveViewRep.Activate
'Loop through all views that currently exist on the active sheet
For Each oDrawingView In sparesSheet.DrawingViews
' Try
' oDataSets = oDrawingView.GraphicsDataSetsCollection.Item("CG_Test3")
' oDataSets.Delete
' oDataSets = oDrawingView.GraphicsDataSetsCollection.Add("CG_Test3")
' Catch
' oDataSets = oDrawingView.GraphicsDataSetsCollection.Add("CG_Test3")
' End Try
' Try
' oClientGraphics = oDrawingView.ClientGraphicsCollection.Item("CG_Test3")
' oClientGraphics.Delete
' oClientGraphics = oDrawingView.ClientGraphicsCollection.Add("CG_Test3")
' Catch
' oClientGraphics = oDrawingView.ClientGraphicsCollection.Add("CG_Test3")
' End Try
' TraverseAssembly(oModelDoc.ComponentDefinition.Occurrences)
MsgBox(oDrawingView.ActivePositionalRepresentation)
' Dim overlayView As DrawingView
' overlayView = sparesSheet.DrawingViews.AddOverlayView(oDrawingView, oDrawingView.ActivePositionalRepresentation, "Spare Parts", False, kShadedHiddenLineDrawingViewStyle)
' overlayView.ViewStyle = DrawingViewStyleEnum.kFromBaseDrawingViewStyle
sparesSheet.DrawingViews.AddOverlayView(oDrawingView, oDrawingView.ActivePositionalRepresentation, "Spare Parts", False, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, False)
' iLogicVb.UpdateWhenDone = True
Next
ThisApplication.ActiveView.Update
' Update the document
'oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument.Update
'InventorVb.DocumentUpdate
End Sub
Sub TraverseAssembly(oOccs As ComponentOccurrences)
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oOccs
If Not oOccurrence.Suppressed Then
Try
If oOccurrence.Definition.Document.PropertySets.Item("Inventor User Defined Properties").Item("Wear Item").Expression = "Yes" Then
oOccurrence.Visible = True
Else
oOccurrence.Visible = False
End If
Catch
Try
oOccurrence.Visible = False
Catch
End Try
End Try
Logger.Debug(oOccurrence.Name & " - TYPE: " & oOccurrence.Type)
If oOccurrence.SubOccurrences.Count > 0 Then
TraverseAssembly(oOccurrence.SubOccurrences)
End If
End If
Next
End Sub
End Class