mdlCell_getElmDscr(&cellDscrP, NULL, &origin, &scale, true, &rotMat, NULL, 0, 2, false, L"NAME", &(*dgnFilePtr)); if (cellDscrP != NULL) { EditElementHandle eeh1(cellDscrP, true, false, ACTIVEMODEL); eeh1.GetHandler().ConvertTo3d(eeh1, 1); ElementAgenda elemAgenda; EditElementHandle eeh2; DSegment3d seg1; seg1.Init(DPoint3d::From(0, 0, 0), DPoint3d::From(1000, 0, 0)); LineHandler::CreateLineElement(eeh2, NULL, seg1, true, *ACTIVEMODEL); elemAgenda.Insert(eeh1); elemAgenda.Insert(eeh2); EditElementHandle cellEle; NormalCellHeaderHandler::CreateGroupCellElement(cellEle, elemAgenda); MSElementDescrP descrP = cellEle.ExtractElementDescr(); mdlElmdscr_add(descrP); }
如上代码所示,单独add单元没有问题,创建一个group就会闪退
1. 为何不直接调用cellEle.AddToModel()来将元素添加到模型中?
2. 在调用ExtractElementDescr之前需要用如下写法确认EditElementHandle中含有MSElementDescr
if (NULL == eeh.PeekElementDescrCP()) eeh.GetElementDescrP(); // Let the element handle create and own an element descriptor MSElementDescrP edP = eeh.ExtractElementDescr();
MS学习资源:
MicroStation Wednesday视频分享
深入探讨MicroStation DGN基本概念系列
一步步学习MicroStation CE Addin开发
一步步学习MicroStation CE MDL开发
EditElementHandle eeh1(cellDscrP, true, false, ACTIVEMODEL); eeh1.GetHandler().ConvertTo3d(eeh1, 1); ElementAgenda elemAgenda; EditElementHandle eeh2; DSegment3d seg1; seg1.Init(DPoint3d::From(0, 0, 0), DPoint3d::From(1000, 0, 0)); LineHandler::CreateLineElement(eeh2, NULL, seg1, true, *ACTIVEMODEL); if (NULL == eeh2.PeekElementDescrCP()) eeh2.GetElementDescrP(); // Let the element handle create and own an element descriptor elemAgenda.Insert(eeh1); elemAgenda.Insert(eeh2); EditElementHandle cellEle; NormalCellHeaderHandler::CreateGroupCellElement(cellEle, elemAgenda); if (NULL == cellEle.PeekElementDescrCP()) cellEle.GetElementDescrP(); // Let the element handle create and own an element descriptor MSElementDescrP descrP = cellEle.ExtractElementDescr(); mdlElmdscr_add(descrP);
这样写还是会闪退,请符老师指点一下
我有几个疑问:
1. mdlCell_getElmDscr(&cellDscrP, NULL, &origin, &scale,true, &rotMat, NULL, 0, 2, false, L"NAME", &(*dgnFilePtr));中的最后一个参数是指的单元库吗?一般我们都是先调用mdlCell_attachLibrary连接单元库后,该参数给NULL即可。
2. 以上函数中的第九个参数给2,您明确2的含义吗?该参数给0表示不以共享单元获取该单元,给1表示一定按共享单元获取该单元,给2则是按系统当前的共享标记获取该单元。我感觉该参数应该给0更适合您的情况。
3. 为何要调用ConvertTo3d函数?是因为您单元库是二维的,当前模型是三维的吗?
4. 您的eeh2是否创建成功?CreateLineElement函数的第四个参数一般要写成ACTIVEMODEL->Is3d()这样,让程序自动判断当前模型是二维的还是三维的。而不是直接给true。这样,万一当前模型不是三维的就会造成问题。
5. CreateGroupCellElement是否返回了SUCESS?
6. 为何不直接调用AddToModel添加元素而要改为mdlElmdscr_add ?
如下测试代码是有关CreateGroupCellElement的。能将当前选择集中的元素构造成一个组。
void CreateGroupCellElementTest() { if (!SelectionSetManager::GetManager().IsActive()) { mdlDialog_dmsgsPrint(L"No selection set found"); return; } ElementAgenda agenda; SelectionSetManager::GetManager().BuildAgenda(agenda); EditElementHandle eeh; if (SUCCESS == NormalCellHeaderHandler::CreateGroupCellElement(eeh, agenda)) { eeh.AddToModel(); mdlDialog_dmsgsPrint(L"CreateGroupCellElement is successful"); } else mdlDialog_dmsgsPrint(L"CreateGroupCellElement failed"); }
Answer Verified By: Liaoyuan Zhang
符老师,我是做符号替换,用到的是ViewCallback::SetSubstituteElemFunction;
这里的is3d必须是true,不然不显示,不知道什么原因;
返回多个元素,之前我都是创建一个group,可以正常显示,但是包含单元就出错了,我尝试用mdlElmdscr_addToChain,也没有成功;
还有一个额外的问题,不管我用eeh1.GetDisplayHandler()->CalcElementRange还是mdlElmdscr_computeRange都无法获取单元的范围
那是否与您的这个ViewCallback::SetSubstituteElemFunction编程环境有关?先写一个独立的函数进行测试
另外的问题最好开一个新帖提问,这样方便我们跟踪问题,也方便后来者查询问题。谢谢!
感谢符老师的解释,我测试发现用NormalCellHeaderHandler::CreateCellElement不会闪退;
另外计算范围,这个我有点迷惑,现在用mdlElmdscr_computeRange能计算出来了