Hello All,
I am experiencing an out-of-memory error while working with Topology Tagging APIs on Inventor 2020.3.4.
[TestMethod]
public void ReferenceKeyApi()
{
// Get Inventor App
InventorApp = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
VctApplication.InventorApp = InventorApp;
Document document = VctApplication.InventorSession.ActiveDoc;
SelectSet selectSet = document.SelectSet;
dynamic selectedObject = null;
if (selectSet.Count > 0)
selectedObject = selectSet[1];
// Initialize the VctDocument class
VctDocument vctDocument = VctApplication.InventorSession.VctDocument;
// Example for an assembly document
switch (selectedObject)
{
case FaceProxy faceProxy:
faceProxy = (FaceProxy) selectedObject;
// To get reference key and key context
string fKey = vctDocument.GetReferenceKey(document, faceProxy, out string fKeyContext);
selectSet.Clear();
// later to bind back the reference key to the entity using the key context
FaceProxy fRetrievedObject = vctDocument.GetEntityFromReferenceKey(document, fKey, fKeyContext);
selectSet.Select(fRetrievedObject);
break;
case EdgeProxy edgeProxy:
edgeProxy = (EdgeProxy) selectedObject;
// To get reference key and key context
string eKey = vctDocument.GetReferenceKey(document, edgeProxy, out string eKeyContext);
selectSet.Clear();
// later to bind back the reference key to the entity using the key context
EdgeProxy eRetrievedObject = vctDocument.GetEntityFromReferenceKey(document, eKey, eKeyContext);
selectSet.Select(eRetrievedObject);
break;
}
}
Thanks,
Amitabh Mukherjee
Solved! Go to Solution.
Solved by CattabianiI. Go to Solution.
We have another question @CattabianiI
There is an API called ReleaseKeyContext. When should this API be called? Is it at the very end of the binding back?
What does it do? We did not see this API being used in your sample program.
To work with reference keys, the ReferenceKeyManager should be obtained from the Document object. There are two functions in the ReferenceKeyManager object that can create the key binding context scope hence allocate some memory:
long handle = ReferenceKeyManager.CreateKeyContext()
long handle = ReferenceKeyManager.LoadContextFromArray(something)
Both these functions provide a long integer as a handle to the corresponding key binding context scope and also both these functions need to be accompanied by the call to:
ReferenceKeyManager.ReleaseKeyContext(handle)
After this call, the document key binding scope should be released.
It might look cumbersome, but creating or restoring a new document key binding scope every time something needs to be bound to the reference key is a relatively expensive operation, so keeping it alive via handle helps with performance. A lot.
Thank you @CattabianiI @MjDeck @tomas.bujnoch @YuhanZhang .
We have found the root cause of the problem, the issue was to do with the Excel cell character limit issue. We are storing the information in an Excel file. The Excel cell is able to hold only 32767 characters, whereas the actual key context is 746232 characters long. We are now storing this in a text file and we are able to bind the key back.
Thank you, again to all who contributed to the discussion and helped find the right approach to doing this.
Thanks,
Amitabh Mukherjee
@amitabhVA4SD Glad to hear it was solved!
Can't find what you're looking for? Ask the community or share your knowledge.