GetReferenceKey not returning the correct value since upgrading to 2025

GetReferenceKey not returning the correct value since upgrading to 2025

Russell.BrownVEZMW
Contributor Contributor
259 Views
3 Replies
Message 1 of 4

GetReferenceKey not returning the correct value since upgrading to 2025

Russell.BrownVEZMW
Contributor
Contributor

When I run the following code in Inventor 2023, the message box returns the correct string that represents the reference key of the line selected. However, when the same code is ran in Inventor 2025 it returns "AA==", no matter what is selected. Does anyone know how to fix this?

 

Dim oAsm As Document = ThisApplication.ActiveDocument

oObject = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveFilter, "Select a line to link length to - Press Esc to cancel")

If IsNothing(oObject) Then
	Exit Sub
End If

' Set a reference to the ReferenceKeyManager object.
Dim refKeyMgr As ReferenceKeyManager
refKeyMgr = oAsm.ReferenceKeyManager

' Get reference keys from the selected entities.
Dim refKey(0) As Byte
oObject.GetReferenceKey(refKey)
	
' Convert the reference keys to strings to make saving it easier.
Dim strKey As String
strKey = oAsm.ReferenceKeyManager.KeyToString(refKey)
MessageBox.Show(strKey, "Title")

 

0 Likes
Accepted solutions (1)
260 Views
3 Replies
Replies (3)
Message 2 of 4

Michael.Navara
Advisor
Advisor
Accepted solution

Try to change byte array initialization and cast oObject to explicit type

 

Dim oAsm As Document = ThisApplication.ActiveDocument

oObject = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveFilter, "Select a line to link length to - Press Esc to cancel")

If IsNothing(oObject) Then
	Exit Sub
End If

' Set a reference to the ReferenceKeyManager object.
Dim refKeyMgr As ReferenceKeyManager
refKeyMgr = oAsm.ReferenceKeyManager

' Get reference keys from the selected entities.
Dim refKey As Byte() = {}
Dim skLine As SketchLine = oObject
skLine.GetReferenceKey(refKey)
	
' Convert the reference keys to strings to make saving it easier.
Dim strKey As String
strKey = oAsm.ReferenceKeyManager.KeyToString(refKey)
MessageBox.Show(strKey, "Title")
0 Likes
Message 3 of 4

Russell.BrownVEZMW
Contributor
Contributor

That works perfectly! Thank you very much.

0 Likes
Message 4 of 4

COLINBRUSCHI
Enthusiast
Enthusiast

This worked for me too, not sure why the type cast is required now, but doesn't work otherwise

0 Likes