Message 1 of 14
Using ReferenceKeys to match a Copy Object Face with the Source Face

Not applicable
09-18-2015
11:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to use ReferenceKeys to match a Copy Object Face with the Source Face in the source part. The code below does not seem to show any matching Reference keys,
Imports System.Runtime.InteropServices Imports System.IO Imports Inventor Public Module modReferenceKeys ' Name of the file for saving reference keys Private _Filename As String = "c:\temp\keydata.txt" Public Sub GetKeys(CopyObjectComponent As ComponentOccurrence, SourceComponent As ComponentOccurrence) Dim oDoc As PartDocument = CopyObjectComponent.Definition.Document() Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition Dim oRefKeyMgr As ReferenceKeyManager = oDoc.ReferenceKeyManager Dim oScupltDoc As PartDocument = SourceComponent.Definition.Document() Dim oSculptDef As PartComponentDefinition = oScupltDoc.ComponentDefinition Dim oSculptRefKeyMgr As ReferenceKeyManager = oScupltDoc.ReferenceKeyManager ' The keys will be written to binary file for later access Dim binWriter As New BinaryWriter( _ System.IO.File.Open(_Filename, FileMode.Create)) Try Dim lContext As Long Dim byContext() As Byte = New Byte() {} ' initilization ' The conext should be created only once lContext = oRefKeyMgr.CreateKeyContext Dim lSculptContext As Long Dim bySculptContext() As Byte = New Byte() {} ' initilization ' The conext should be created only once lSculptContext = oSculptRefKeyMgr.CreateKeyContext ' Dump the number of faces in this model binWriter.Write(oDef.Features.NonParametricBaseFeatures(1).Faces.Count()) binWriter.Write(Chr(13)) binWriter.Write(oSculptDef.Features.KnitFeatures(1).Faces.Count()) binWriter.Write(Chr(13)) ' Iterate through all faces and dump key Dim oFace As Face For Each oFace In oDef.Features.NonParametricBaseFeatures(1).Faces ' get key from oFace Dim byKey() As Byte = New Byte() {} oFace.GetReferenceKey(byKey, lContext) Dim oSculptFace As Face For Each oSculptFace In oSculptDef.Features.KnitFeatures(1).Faces ' get key from oFace Dim byScupltKey() As Byte = New Byte() {} oSculptFace.GetReferenceKey(byScupltKey, lSculptContext) If byScupltKey Is byKey Then binWriter.Write("YAY They Matched!!!!!!!!!!") binWriter.Write(Chr(13)) End If ' save the key size and key in the file 'binWriter.Write(Chr(13)) 'binWriter.Write("-----------------------------------") 'binWriter.Write(Chr(13)) 'binWriter.Write(byKey.Length) 'binWriter.Write(Chr(13)) 'binWriter.Write(byKey) 'binWriter.Write(Chr(13)) 'binWriter.Write(byKey.ToString()) 'binWriter.Write(Chr(13)) 'binWriter.Write(byScupltKey.Length) 'binWriter.Write(Chr(13)) 'binWriter.Write(byScupltKey) 'binWriter.Write(Chr(13)) 'binWriter.Write(byScupltKey.ToString()) 'binWriter.Write(Chr(13)) 'binWriter.Write("-----------------------------------") 'binWriter.Write(Chr(13)) 'End If Next Next ' We have finished creating all the keys, ' now save the long context as byte array ' Context should be saved after creating all the keys oRefKeyMgr.SaveContextToArray(lContext, byContext) ' Dump the size and context array into file binWriter.Write(byContext.Length) binWriter.Write(Chr(13)) binWriter.Write(byContext.ToString()) binWriter.Write(Chr(13)) Catch ex As SystemException MsgBox(ex.ToString()) Finally binWriter.Close() MsgBox("Reference Keys are Saved in the file:" & vbNewLine & _Filename) End Try oRefKeyMgr = Nothing oDoc = Nothing End Sub 'GetKeys End Module
I got the original code form here: Maintaining persistent links to objects across Inventor sessions using ReferenceKeys
I using Inventor 2016
Thanks,