我这边可能需求更多一点,我想要的是把参考的图形复制一份保存在 当前model,这些元素需要有参考的旋转,缩放等信息。
如下代码。我做了测试,只是把原始参考文件的元素复制过来了, 这些元素不具有参考的参数,比如旋转和缩放等。
DgnDocumentMonikerPtr moniker = Bentley::DgnPlatform::DgnDocumentMoniker::CreateFromFileName(CCommonOperate::CStringToBentleyWString(frameInfo.sFilePath).c_str(),NULL); DgnAttachmentP attachment; if (0 != ACTIVEMODEL->CreateDgnAttachment(attachment, *moniker, CCommonOperate::CStringToBentleyWString(frameInfo.sModelName).c_str())) { MessageBox::Show("参考模版文件失败"); } attachment->SetStoredScale(dScale); attachment->SetMasterOrigin(insertPoint); Bentley::DgnModelP dgnModelP = attachment->GetDgnModelP(); for (PersistentElementRefP const& elemRef : *dgnModelP->GetGraphicElementsP()) { if (CELL_HEADER_ELM != elemRef->GetElementType()) { continue; } Bentley::DgnPlatform::ElementId elmID = elemRef->GetElementId(); EditElementHandle eehCell(elmID, dgnModelP->AsDgnModelP()); if (!eehCell.IsValid()) { continue; } Bentley::DgnPlatform::ElementCopyContext copier(ACTIVEMODEL); if (SUCCESS != copier.DoCopy(eehCell)) { MessageBox::Show("有一个没成功"); } } ACTIVEMODEL->DeleteDgnAttachment(attachment);
调用copier.SetSourceSourceModelRef()指向参考模型,
再调用copier.SetTransformToDestination(true)要求执行元素变换。
老师 依然不行啊。
Bentley::DgnPlatform::ElementCopyContext copier(ACTIVEMODEL); copier.SetSourceModelRef(attachment); copier.SetTransformToDestination(true); if (SUCCESS != copier.DoCopy(eehCell)) { MessageBox::Show("有一个没成功"); }
抱歉。我在准备明天的用户公开课。明天下午我实际编码测试一下。思路应该是对的,可能漏掉了什么细节。
下面代码,可以将参考文件的元素拷贝到目的模型,我测试的文件很简单,就是两个dgn模型,1.dgn画了个圆,2.dgn将1参考进去,然后执行下面代码, 在2的模型中生成的圆是带有1中圆的几何信息的。
DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP(); DgnAttachmentArrayP pAttachArray = pActiveModel->GetDgnAttachmentsP(); if (NULL == pAttachArray) { mdlDialog_dmsgsPrint(L"No Attached Reference"); return false; } for (DgnAttachmentP pAttach : *pAttachArray) { DgnModelP newModel = pAttach->GetDgnModelP(); EditElementHandle eeh(783L, newModel); Bentley::DgnPlatform::ElementCopyContext copier(ACTIVEMODEL); copier.SetSourceModelRef(eeh.GetModelRef()); copier.SetTransformToDestination(true); if (SUCCESS == copier.DoCopy(eeh)) { return true; } }
老师,你的代码能把参考的旋转和放大,以及参考的位置放置都拷贝到吗。 这个应该是拷贝原文件的元素吧。 比如原文件 是 中心为0,0的 半径为100的圆, 参考到当前文件被放大了2倍,并且圆心位置是 300,300 。这种情况下 复制的元素应该还是中心为0,0的 半径为100的圆吧。 我想要的是 放大了2倍,并且圆心位置是 300,300 的圆
我测试了下,scale是可以的,位置不太对,我再研究研究,回头请教符老师看看咋解决,他最近忙着培训得事。
胡工:您好!
非常抱歉未能及时答复您的问题。我也编程测试了,确实有问题。我需要时间和国外专家沟通看是否还有别的办法解决。