Hi,I've got some problems when I copy elements with items and labels from a reference file. The elements, items and labels a copied but extra cell elements with the label text are added too.
I've attached a design file that contains two models: a design model and sheet model in which I've attached the design model as reference.
3755.TestFile.zip
If you run the code listed below you will see the problem.
// create shape element DPoint3d pts[5]; pts[0].x = pts[0].y = 0; pts[1].x = 500; pts[1].y = 0; pts[2].x = 500; pts[2].y = 500; pts[3].x = 0; pts[3].y = 500; pts[4].x = pts[4].y = 0; for (int i = 0; i < 5; i++) pts[i].z = 0; EditElementHandle eehShape; ShapeHandler::CreateShapeElement(eehShape, NULL, pts, 5, true, *ISessionMgr::GetActiveDgnModelRefP()); // define fence by shapeElement IndexedViewSetR viewSet = IViewManager::GetManager().GetActiveViewSet(); FenceManagerR fenceManager = FenceManager::GetManager(); fenceManager.DefineByElement(&eehShape, viewSet.GetViewport(tcb->lstvw)); FenceParamsP fenceParams = FenceParams::Create(ISessionMgr::GetActiveDgnModelP()); fenceManager.InitFromActiveFence(*fenceParams, false, false, FenceClipMode::None); // build modelreflist DgnModelRefListP modelRefList; mdlModelRefList_create(&modelRefList); mdlModelRefList_add(modelRefList, ISessionMgr::GetActiveDgnModelP()); ModelRefIteratorP mrIteratorP; if (mdlModelRefIterator_create(&mrIteratorP, mdlModelRef_getActive(), MRITERATE_Root | MRITERATE_PrimaryChildRefs, -1) == SUCCESS) { DgnModelRefP modelRef = mdlModelRefIterator_getFirst(mrIteratorP); while (modelRef) { mdlModelRefList_add(modelRefList, modelRef); modelRef = mdlModelRefIterator_getNext(mrIteratorP); } mdlModelRefIterator_free(&mrIteratorP); } // build element agenda and free modelreflist ElementAgenda elmAgenda; fenceManager.BuildAgenda(*fenceParams, elmAgenda, modelRefList, false, false, false); mdlModelRefList_free(&modelRefList); // copy the elements in the elementAgenda ElementCopyContext elmCopyContext(ISessionMgr::GetActiveDgnModelP()); elmCopyContext.SetLevelHandling(CopyContextLevelOption::CopyIfNotFound); for (UInt index = 0; index < elmAgenda.GetCount(); index++) { EditElementHandleP eehP = elmAgenda.GetEntryP(index); elmCopyContext.DoCopy(*eehP); eehP->AddToModel(); }
Any ideas to solve this problem ?
TIA, Evan
Unknown said:Extra cell elements with the label text are added too
DgnModelRefListP modelRefList; mdlModelRefList_create(&modelRefList); mdlModelRefList_add(modelRefList, ISessionMgr::GetActiveDgnModelP());
modelRefList now contains one member, which is the active model.
modelRefList
if (mdlModelRefIterator_create(&mrIteratorP, mdlModelRef_getActive(), MRITERATE_Root | MRITERATE_PrimaryChildRefs, -1) == SUCCESS)
Iterator enumerates the active model (MRITERATE_Root) and its references.
MRITERATE_Root
mdlModelRefList_add(modelRefList, modelRef);
The active model is added to the list a second time, along with each reference.
fenceManager.BuildAgenda(*fenceParams, elmAgenda, modelRefList, false, false, false);
I don't know what that does when the same model is present multiple times in the modelRefList.
There are probably unexpected consequences of your algorithm …
I suggest that you put some trace statements in there so you can log the program flow, and see which elements are copied from what source.
Regards, Jon Summers LA Solutions
Hi Jon,
Thank you very much for your reply.
Yes, I must admit that the active model is added twice but that is not the problem because this model is empty. I've added a trace statement and it tells me that only cell elements and one dimension element are copied... In some way the label items is copied as cells...
Regards, Evan
Unknown said: In some way the label items is copied as cells...
Can you post a sample DGN file that contains a label that, when copied, ends up as a cell?
It's included in my first post...
Unknown said:It's included in my first post
So it is! I used the Analyse Element tool to examine your DGN.
You have two cells (msdas_bronde): one contains the ellipse, the other (MSDAS_BRONDE_lbl) contains a text node having three text elements. It's not your copy code that creates a cell: the cell is already in your reference.