GetReferenceKey

GetReferenceKey

wppdev
Contributor Contributor
729 Views
6 Replies
Message 1 of 7

GetReferenceKey

wppdev
Contributor
Contributor

Can some one explain the key we get from GetReferenceKey method.

I am using it for component occurrence and subcomponent occurrence object and I am getting different keys for both the objects.

Can I get the component id directly from the key generated?

 

Thanks ,

Rajdeep

0 Likes
730 Views
6 Replies
Replies (6)
Message 2 of 7

HideoYamada
Advisor
Advisor

Hello wppdev,

 


@wppdev wrote:

Can I get the component id directly from the key generated?

Is this meaning you want to retrieve the object from ReferenceKey?

If so, use Document.RefernceKeyManager.BindKeyToObject.

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 3 of 7

chandra.shekar.g
Autodesk Support
Autodesk Support

@wppdev,

 

Hoping that suggestions in below blog link may be helpful.

 

https://adndevblog.typepad.com/manufacturing/2012/07/reference-keys-in-inventor.html

https://modthemachine.typepad.com/my_weblog/2015/09/understanding-reference-keys-in-inventor.html

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 7

Maxim-CADman77
Advisor
Advisor

dear @chandra.shekar.g 

Here is my attempt to start with RFs in iLogic (based on the second url you've posted):

Dim doc As Document = ThisApplication.ActiveDocument
Dim selFace As Face = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Select face.")
Dim refKeyMgr As ReferenceKeyManager = doc.ReferenceKeyManager
Dim keyContext As Long = refKeyMgr.CreateKeyContext
Dim faceRefKey() As Byte	

Call selFace.GetReferenceKey(faceRefKey, keyContext)

On the sample IPT attached I'm getting Error:

Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

What I'm missing?

 

PS: I'm using Inventor 2022.3

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 7

Maxim-CADman77
Advisor
Advisor

I kindly hope author of that article (@BrianEkins) can comment the mismatch issue.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 7

adam.nagy
Autodesk Support
Autodesk Support

This issue is discussed here:
https://adndevblog.typepad.com/manufacturing/2013/07/pass-arguments-to-getreferencekey-and-bindkeyto...

You just have to initialize the Byte arrays:

 Dim faceRefKey() As Byte = New Byte() {}


Adam Nagy
Autodesk Platform Services
Message 7 of 7

abdullah_elq
Advocate
Advocate

Attaching the full iLogic code in case anyone else finds it useful:

    ' Get the active document.
    Dim doc As Document = ThisApplication.ActiveDocument
   
    ' Have a face and edge selected.
    Dim selFace As Face = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Select face.")

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

    ' Create a key context.
    Dim keyContext As Long = refKeyMgr.CreateKeyContext
   
    ' Get reference keys from the selected entities.
    Dim faceRefKey() As Byte = New Byte() {}
    Call selFace.GetReferenceKey(faceRefKey, keyContext)

    ' Get the key context as an array of bytes and
    ' convert it to a string.
    Dim contextArray() As Byte = New Byte() {}
    Call refKeyMgr.SaveContextToArray(keyContext, contextArray)
    Dim strContext As String
    strContext = refKeyMgr.KeyToString(contextArray)
   
    ' Convert the reference keys to strings to make saving it easier.
    Dim strFaceKey As String
    strFaceKey = doc.ReferenceKeyManager.KeyToString(faceRefKey)
	
	'Display the key
	MessageBox.Show(strFaceKey)