[OPMCE C#]程序对一条线和一个cell添加约束后,在不同比例下,会导致生成线条和cell后立马删除的情况

前提:我用程序创建了一条线A,以及若干线条和注释组成的cell B,将线条A和cell B进行约束。

随着模型比例不同,有时候会遇到添加约束后,点击任何命令,都将删除刚建立线条A和cell B。

例如我在1:1比例时能生成,在1:100时生成后点击任何命令后,刚生成的线条和cell自己删除了,请问这是什么情况?

mtest.dgn

以上是我测试dgn。

static bool createDimensionCell(Bentley::GeometryNET::DPoint3d tempPoint1, Bentley::GeometryNET::DPoint3d tempPoint2,
		System::Collections::Generic::List<System::String^>^ listStr, System::Collections::Generic::List<System::String^>^% listEleID)
	{
		
		EditElementHandle eeh;
		DSegment3d seg;
		Bentley::DPoint3d basePt1, basePt2;
		basePt1.x = tempPoint1.X, basePt1.y = tempPoint1.Y, basePt1.z = tempPoint1.Z;
		basePt2.x = tempPoint2.X, basePt2.y = tempPoint2.Y, basePt2.z = tempPoint2.Z;
		//作引线
		seg.Init(basePt2, basePt1);
		ICurvePrimitivePtr pCurve = ICurvePrimitive::CreateLine(seg);
		Bentley::DgnPlatform::DraftingElementSchema::ToElement(eeh, *pCurve, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL);
		
		eeh.AddToModel();
		auto pos0 = mdlModelRef_getEof(ACTIVEMODEL);
		ElementRefP ele0 = mdlModelRef_getElementRef(ACTIVEMODEL, pos0 - 1);
		Bentley::DgnPlatform::ElementId id0 = ele0->GetElementId();
		listEleID->Add(id0.ToString());

		DPoint3d lastPoint = basePt2;
		
		//创建cell
		EditElementHandle eehCell;
		RotMatrix rMatrix = RotMatrix::FromIdentity();
		NormalCellHeaderHandler::CreateCellElement(eehCell, L"NormalCell", basePt2, rMatrix, true, *ACTIVEMODEL);
		if (listStr->Count == 0)
			return false;
		for (int i = 0; i < listStr->Count; i++)
		{
			Bentley::DPoint3d dpoint = lastPoint;

			if (i == 0)//t3
			{
				if ((basePt2.y) >= (basePt1.y))
				{
					dpoint.y += 10 * g_1mu;
				}
				else
				{
					dpoint.y -= 10 * g_1mu;
				}
				
			}
			else
			{
				if ((basePt2.y) >= (basePt1.y))
				{
					dpoint.y += 5 * g_1mu;
				}
				else
				{
					dpoint.y -= 5 * g_1mu;
				}
				
			}


			Bentley::DPoint3d dpoint2 = dpoint;

			dpoint2.x += 20*g_1mu;
			//管线编号线条1
			EditElementHandle eeh2;
			DSegment3d seg2;
			seg2.Init(lastPoint, dpoint);
			ICurvePrimitivePtr pCurve2 = ICurvePrimitive::CreateLine(seg2);
			Bentley::DgnPlatform::DraftingElementSchema::ToElement(eeh2, *pCurve2, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL);
			lastPoint = dpoint;
			//管线编号线条2
			EditElementHandle eeh3;
			DSegment3d seg3;
			seg3.Init(dpoint, dpoint2);
			ICurvePrimitivePtr pCurve3 = ICurvePrimitive::CreateLine(seg3);
			Bentley::DgnPlatform::DraftingElementSchema::ToElement(eeh3, *pCurve3, nullptr, ACTIVEMODEL->Is3d(), *ACTIVEMODEL);
		

			//管线编号文字
			DgnModelP       pActiveModel = ISessionMgr::GetActiveDgnModelP();
			TextBlockPropertiesPtr  pTBProp = Bentley::DgnPlatform::TextBlockProperties::Create(*pActiveModel);
			pTBProp->SetIsViewIndependent(false);
			ParagraphPropertiesPtr  pParaProp = Bentley::DgnPlatform::ParagraphProperties::Create(*pActiveModel);
			DgnTextStylePtr         pTextStyle = Bentley::DgnPlatform::DgnTextStyle::GetActive();
			RunPropertiesPtr        pRunProp = Bentley::DgnPlatform::RunProperties::Create(*pTextStyle, *pActiveModel);
		    
			
			TextBlockPtr pTextBlock = Bentley::DgnPlatform::TextBlock::Create(*pTBProp, *pParaProp, *pRunProp, *pActiveModel);
			
			Bentley::DPoint3d textPoint = dpoint;
			textPoint.x += 1 *g_1mu;
			textPoint.y += 4 *g_1mu;
			
			pTextBlock->SetUserOrigin(textPoint);

			CString CSGXBH(listStr[i]);
			Bentley::WString WSGXBH = CStringToBentleyWString(CSGXBH);
			pTextBlock->AppendText(WSGXBH.GetWCharCP());
			//将线条、文字加入单元
			EditElementHandle  eeh4;
			Bentley::DgnPlatform::TextHandlerBase::CreateElement(eeh4, nullptr, *pTextBlock);
			IAnnotationHandler* annotation0 = dynamic_cast<IAnnotationHandler*>(&eeh4.GetHandler());
			annotation0->RemoveAnnotationScale(eeh4);

			NormalCellHeaderHandler::AddChildElement(eehCell, eeh2);
			NormalCellHeaderHandler::AddChildElement(eehCell, eeh3);
			NormalCellHeaderHandler::AddChildElement(eehCell, eeh4);
	
			
		}
		NormalCellHeaderHandler::AddChildComplete(eehCell);
		//单元赋予比例
		eehCell.GetElementP()->cell_3d.flags.isAnnotation = true;
		IAnnotationHandler* annotation = dynamic_cast<IAnnotationHandler*>(&eehCell.GetHandler());
		if (annotation)
		{
			annotation->AddAnnotationScale(eehCell, ACTIVEMODEL);
			
			eehCell.AddToModel();

			auto pos = mdlModelRef_getEof(ACTIVEMODEL);
			ElementRefP ele = mdlModelRef_getElementRef(ACTIVEMODEL, pos - 1);
			Bentley::DgnPlatform::ElementId id = ele->GetElementId();
			listEleID->Add(id.ToString());
	
		}

		Bentley::DgnPlatform::Constraint2d::Constraint2dData    constraintData(Bentley::DgnPlatform::Constraint2d::Constraint2dType::Coincident);
		CurveVectorPtr cveVec1 = ICurvePathQuery::ElementToCurveVector(eeh);
	    
		CurveTopologyId::AddCurveVectorIds(*cveVec1, CurvePrimitiveId::Type_CurveVector, CurveTopologyId::FromCurveVector(), NULL);
		Bentley::DgnPlatform::Constraint2d::CurveEntityIdentifier   curveId(*cveVec1, NULL, 0, Bentley::DgnPlatform::Constraint2d::VertexType::Start,eeh.GetElementRef());
		CurveLocationDetail location = CurveLocationDetail(&*cveVec1->at(0), 0.0, basePt2, 0, 1, 0.0, 0.0);
		curveId.SetEdgeId(location.curve->GetId()->Clone().get());
		constraintData.AddCurveIdentifier(curveId);
		for (ChildEditElemIter childEh(eehCell); childEh.IsValid(); childEh = childEh.ToNext())
		{
			if (LINE_ELM == childEh.GetElementType())
			{
				ElementRefP eleRef = childEh.GetElementRef();
				CurveVectorPtr cveVec2 = ICurvePathQuery::ElementToCurveVector(eeh);
				CurveTopologyId::AddCurveVectorIds(*cveVec2, CurvePrimitiveId::Type_CurveVector, CurveTopologyId::FromCurveVector(), NULL);
				Bentley::DgnPlatform::Constraint2d::CurveEntityIdentifier   curveId2(*cveVec2, NULL, 0, Bentley::DgnPlatform::Constraint2d::VertexType::Start,
					eehCell.GetElementRef());
				CurveLocationDetail location2 = CurveLocationDetail(&*cveVec2->at(0), 0.0, basePt2, 0, 1, 0.0, 0.0);
				curveId2.SetEdgeId(location2.curve->GetId()->Clone().get());
				constraintData.AddCurveIdentifier(curveId2);
				break;
			}
		}
		Bentley::DgnPlatform::Constraint2d::Constraint2dSolverData   solverData;
		solverData.m_constraints.push_back(constraintData);
		T_StdElementRefSet  elementRefs;
		solverData.GetElementRefs(elementRefs);
		ElementHandle   anyMember(*elementRefs.begin());

		Bentley::StatusInt stas = Bentley::DgnPlatform::Constraint2d::Constraint2dManager::AddSolverData(anyMember, solverData);
		bvector<ElementRefP>    noChanges;
		bool    isDynamic = false;
		if (Bentley::DgnPlatform::Constraint2d::Constraint2dManager::EvaluateAndUpdate(solverData, *ACTIVEMODEL->GetDgnModelP(), noChanges, isDynamic, NULL))
		{
			mdlDialog_dmsgsPrint(L"SUCCESS");
		}
	
		return true;
	}
	
	
	public static void testConstriant()
        {

            DPoint3d dpoint1 = new DPoint3d(-7079361,4164530, - 3748880);
            DPoint3d dpoint2 = new DPoint3d(-7079361, -835470, -3748880);

            List<string> listStr = new List<string>();
            List<string> listID = new List<string>();
            listStr.Add("aaaaaaaaa");
            listStr.Add("bbbbbbbbb");
            listStr.Add("ccccccccc");
            listStr.Add("bbbbbbbbb");
            listStr.Add("ccccccccc");
            listStr.Add("bbbbbbbbb");
            myCLRProJ.KeyinCommands.createDimensionCell(dpoint1, dpoint2, listStr,ref listID);
        }

以上是代码

Parents
  • 我这边无法复现您的问题,如下录屏所示:

Reply
  • 我这边无法复现您的问题,如下录屏所示:

Children
  • 我的录屏会发生这样的情况,但是换一个dgn文件测试又行,不知道哪里出问题?

  • 我就是在您上边上传的dgn文件中测试的。

  • 我也是在上传的dgn文件中测试的呢,出现了上述问题

  • 能否远程看一下?可将远程ID发送至我的邮箱:hongqiang.guo@bentley.com