Hi
I want to place a textnote with leader and establish a dependency between them in a way that when the user moves the text element then the leader will be changed accordingly. So far I got this:
TextBlockPtr textBlock = TextBlock::Create(*DgnTextStyle::GetActive(), *ISessionMgr::GetActiveDgnModelP()); textBlock->SetUserOrigin(DPoint3d::From(1000, 1000)); textBlock->AppendText(L"Test"); EditElementHandle eehText; EditElementHandle eehLeaderElm; bvector<DPoint3d> leaderPts; leaderPts.push_back(DPoint3d::From(0.0, 0.0)); leaderPts.push_back(DPoint3d::From(2000.0, 2000.0)); NoteCellHeaderHandler::CreateNote(eehText, eehLeaderElm, *textBlock, *DimensionStyle::GetActive(), ISessionMgr::GetActiveDgnModelRefP()->Is3d(), *ISessionMgr::GetActiveDgnModelRefP(), leaderPts); eehText.AddToModel(); eehLeaderElm.AddToModel(); DependencyLinkage depLinkageLeader; if (SUCCESS == DependencyManagerLinkage::InitLinkage(depLinkageLeader, DEPENDENCYAPPID_MicroStation, DEPENDENCY_DATA_TYPE_ASSOC_POINT_I, DEPENDENCY_ON_COPY_DeepCopyRootsAlways)) { depLinkageLeader.nRoots = 1; depLinkageLeader.appValue = DEPENDENCYAPPVALUE_AssocPoint; AssocPoint assocPt; AssociativePoint::InitOrigin(assocPt, AssociativePoint::CreateOptions::CREATE_ASSOC_Normal); AssociativePoint::SetRoot(assocPt, eehText.GetElementId(), 0, 0); depLinkageLeader.root.assoc[0] = assocPt; // Rewrite leaderelm ElementRefP oldFirstRef = eehLeaderElm.GetElementRef(); DependencyManagerLinkage::AppendLinkage(eehLeaderElm, depLinkageLeader, 0); eehLeaderElm.ReplaceInModel(oldFirstRef); } DependencyLinkage depLinkageText; if (SUCCESS == DependencyManagerLinkage::InitLinkage(depLinkageText, DEPENDENCYAPPID_Note, DEPENDENCY_DATA_TYPE_ELEM_ID, DEPENDENCY_ON_COPY_DeepCopyRootsAlways)) { depLinkageText.nRoots = 1; depLinkageText.appValue = DEPENDENCYAPPVALUE_Label; // Add the leader element as root depLinkageText.root.elemid[0] = eehLeaderElm.GetElementId(); // Rewrite ElementRefP oldFirstRef = eehText.GetElementRef(); DependencyManagerLinkage::AppendLinkage(eehText, depLinkageText, 0); eehText.ReplaceInModel(oldFirstRef); }
At first glance it works fine but when I move the text element the leader element is modified in a way so it starts at the origin of the text elements original position and points to the new position.
What am I doing wrong ?
TIA.
Regards, Evan
Hi EvanH,
See if calling: AssociativePoint::InitKeypoint for your association point passing it to SetRoot and verify/validate using AssociativePoint::IsValid and AddToModel; provides the desired results.
AssociativePoint::InitKeypoint (m_assocPoint, 0, 0, 0, 1); ... AssociativePoint::SetRoot (m_assocPoint, &path, model, true, 0); ... AssociativePoint::IsValid (m_assocPoint, path.GetEffectiveRoot(), model); ... NoteCellHeaderHandler::AddToModel(m_noteElement, m_leader, *model));
Here are two other posts for reference using the same approach that may be helpful too:
Bob
Answer Verified By: EvanH
Hi Bob
Thank you very much for your help.
I've made it work using the code shown in the first link, though it seems a little strange to me that you create a temporary line element, creates an AssociativePoint based on this element and then deletes that element again... but it works :-)