private int CreateContext(out string context) { Inventor.ReferenceKeyManager rkm = m_app.ActiveDocument.ReferenceKeyManager; int index = rkm.CreateKeyContext(); byte[] bytes = new byte[] { }; rkm.SaveContextToArray(index, ref bytes); context = rkm.KeyToString(bytes); return(index); }
private void CreateReferenceKeyButton_Click(object sender, EventArgs e) { SelectSet ss = m_app.ActiveDocument.SelectSet; if (ss.Count != 1) { MessageBox.Show("Please select a single object before using this command", "No single object selected"); return; } try { string context, key; GetContextAndKey(ReferenceKeysTreeView.SelectedNode, out context, out key); int i = GetContextIndex(context); byte[] bytes = new byte[] { }; ss[1].GetReferenceKey(ref bytes, i); Inventor.ReferenceKeyManager rkm = m_app.ActiveDocument.ReferenceKeyManager; key = rkm.KeyToString(bytes); if (ReferenceKeysTreeView.SelectedNode.Nodes.ContainsKey(key)) { TreeNode existingNode = ReferenceKeysTreeView.SelectedNode.Nodes.Find(context, false)[0]; ReferenceKeysTreeView.SelectedNode = existingNode; MessageBox.Show("Such key already exists and is now highlighted in the Browser", "Duplicate key"); return; } TreeNode node = ReferenceKeysTreeView.SelectedNode.Nodes.Add(key, key); node.ImageKey = kReference; node.SelectedImageKey = kReference; node.EnsureVisible(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Could not create key"); } }