View rep ilogic not acting the same since 2023

View rep ilogic not acting the same since 2023

dwweekly
Advocate Advocate
574 Views
9 Replies
Message 1 of 10

View rep ilogic not acting the same since 2023

dwweekly
Advocate
Advocate

I just noticed some of my ilogic is failing in 2023
I think it is related to the "Master" to "[Primary]" change

 I have 2 view reps labeled 12345 SOW FULL (full model) and 12345 SOW ONLY (shows what has changed) in an .iam (assembly model)
In my idw (drawing)  I create a view using the 12345 SOW ONLY rep
and then I use the Ilogic to create the overlay to my settings
It worked fine in 2022
but now it errors to line 18 (last line)
What must I change?

 

oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view.")
If IsNothing(oObj) Then Exit Sub
If Not TypeOf oObj Is DrawingView Then Exit Sub
Dim oView As DrawingView = oObj
oDVRepName = oView.DesignViewRepresentation
oPRepName = oView.ActivePositionalRepresentation  
Dim oDoc As DrawingDocument= ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet

ViewNameLen = Len(oDVRepName)
NewViewNameLen = ViewNameLen - 5
NewViewNameExtract = Mid(oDVRepName, 1, NewViewNameLen)
FullView = NewViewNameExtract & " FULL"


 Dim oOverlayView As DrawingView
' 	oOverlayView = oSheet.DrawingViews.AddOverlayView(oView, "Master", FullView, True, kHiddenLineRemovedDrawingViewStyle, False)
oOverlayView = oSheet.DrawingViews.AddOverlayView(oView, oPRepName, FullView, True, kHiddenLineRemovedDrawingViewStyle, False)

 

0 Likes
575 Views
9 Replies
Replies (9)
Message 2 of 10

A.Acheson
Mentor
Mentor

Their is one error on the oDVRepName string variable. Correction is below. This was tested in INV 2020.  If you can post any error messages you might have this will help out also.

 

oDVRepName = oView.ActiveDesignViewRepresentation

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 10

jdasilvaS39UQ
Advocate
Advocate

Did you ever find a solution to that error? I am also running into this issue if there is no positional representation on my assembly.

0 Likes
Message 4 of 10

WCrihfield
Mentor
Mentor

Hi @jdasilvaS39UQ.  Can you show us what both tabs of the error message dialog says when it throws the error?  And can you show us what your code up to that point looks like.  And what version of Inventor are you currently using?  Some of these types of things can be pretty difficult to debug remotely.  I just opened a drawing of an assembly, picked the drawing view, and checked the value of the DrawingView.ActivePositionalRepresentation property, as a test.  The code ran just fine, and showed me that the value was "[Primary]".  But I'm using 2024.0.1 version, so things might be slightly different.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 10

jdasilvaS39UQ
Advocate
Advocate

Hi,

 

We are using Inventor 2023.2.1.

Here is the error message:

jdasilvaS39UQ_0-1690288097372.png 

jdasilvaS39UQ_1-1690288105926.png

 

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

 
 
 

jdasilvaS39UQ_5-1690288333205.png

 

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

 

jdasilvaS39UQ_6-1690288420687.png

 

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

 

 

0 Likes
Message 6 of 10

WCrihfield
Mentor
Mentor

Well, the error is definitely happening at that line of code, but it simply does not tell us which of the inputs it is having a problem with.  I would try checking the value of oDrawingView.ActivePositionalRepresentation just before that line somewhere, and if its value is either "[Primary]" or "" (empty String), I would leave that input entry in that line of code as an empty String ("") instead, and try that.  If the model does not have any PositionalRepresentations available, it may simply not like you trying to specify one by name, even if it was the default one.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 10

jdasilvaS39UQ
Advocate
Advocate

I have a textbox before that line, 

MsgBox(oDrawingView.ActivePositionalRepresentation)

it shows "[Primary]"

 

I tried passing "[Primary]", tried an empty string "" and the old "Master" as values and get the same error for all of them

Message 8 of 10

WCrihfield
Mentor
Mentor

OK.  I have not tested this myself lately, so I will take your word for it.  That does sound like a bug then.  And it does seem to be a 'required' input parameter, so we can't simply not specify anything there.  Maybe try specifying the keyword 'Nothing' there instead of an empty String.  Or maybe vbNullString.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 10

jdasilvaS39UQ
Advocate
Advocate

That was a good idea but same result.

 

I can work around it by adding a position rep to the assembly but that doesn't get to the root of the issue.

Message 10 of 10

A.Acheson
Mentor
Mentor

Hi @jdasilvaS39UQ 

This is the instructions for PosRep Object. It is required so you will need to create one. I guess the designers didn't build a situation where the PosRep would be empty. 

 

"Input String that specifies the positional representation to use for the overlay view. The input string must the name of an existing position representation in the assembly referenced by the parent view. The method returns a failure if a representation with this name is not found in the referenced assembly."

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes