[MSCE C#]如何将2个元素关联起来

我创建了2个元素,elementA和elementB,现在我希望鼠标点击elementA后,我可以根据elementA中的信息获取到elementB并对elementB进行操作,该如何实现呢?

  • 如下所示是c/c++的代码演示,c # 的找了一下没找到,可能是目前还没有封装

    void TestAddXAttributePersistentElementPath()
    {
    	ElementAgenda selectset;
    	SelectionSetManager::GetManager().BuildAgenda(selectset);
    	if (selectset.GetCount() < 2)
    	{
    		return;
    	}
    	EditElementHandle& eeh1 = selectset[0];
    	EditElementHandle& eeh2 = selectset[1];
    	PersistentElementPath  persisElePath(eeh2.GetElementRef());
    	XAttributeHandlerId xAttHandlerId(123, 456);
    	UInt32 xAttId = 1;
    	bvector<byte> sink;
    	persisElePath.Store(sink);
    	if (SUCCESS == ITxnManager::GetCurrentTxn().AddXAttribute(eeh1.GetElementRef(),
    		xAttHandlerId, xAttId, sink.begin(), (UInt32)sink.size()))
    	{
    		printf("SUCCESS");
    	}
    }
    void TestGetXAttribute()
    {
    	ElementAgenda selectset;
    	SelectionSetManager::GetManager().BuildAgenda(selectset);
    	if (selectset.GetCount() < 1)
    	{
    		return;
    	}
    	EditElementHandle& eeh1 = selectset[0];
    	XAttributeHandlerId xAttHandlerId(123, 456);
    	UInt32 xAttId = 1;
    	XAttributeHandle xAttHandle(eeh1.GetElementRef(), xAttHandlerId, xAttId);
    	byte const*  bytes = (byte const*)xAttHandle.PeekData();
    
    	PersistentElementPath persisElePath;
    	persisElePath.Load(bytes, 5);
    	printf("%d\n", persisElePath.EvaluateElement(ACTIVEMODEL).GetElementId());
    }
    

    Answer Verified By: lingwei liu