【OBD C++】将创建的批注元素关联

我使用自己的代码创建批注时,尺寸标注以及批注不是关联的。但是使用OBD自带的批注创建的是关联的。如何让这2个关联呢?

代码如下

    EditElementHandle dimElemnote;
	bvector<DPoint3d> m_dimPoints;

	//mdlArc_extract(NULL,NULL,NULL,NULL,NULL,NULL, &centerpoint, msArcelemcp);
	if (SUCCESS != CreateNoteDimension(dimElemnote, 0, modelref))
	{
		return ERROR;
	}

	double              witLength1;
	DVec3d              delta1, corner1, yvec1;
	RotMatrix           rMatrix1;

	DPoint3d* startPoint1 = &centerpoint;
	DPoint3d endPoint1;
	endPoint1.x = centerpoint.x + 2000000;
	endPoint1.y = centerpoint.y + 2000000;

	DPoint3d point1 = centerpoint;
	m_dimPoints.push_back(*startPoint1);
	m_dimPoints.push_back(endPoint1);

	//计算两个点或向量之间的分量差
	mdlVec_subtractPoint(&delta1, &point1, startPoint1);
	//计算两个输入点或向量的分量之和。
	mdlVec_addPoint(&corner1, &m_dimPoints.front(), &delta1);

	//Creates Rotation matrix
	mdlDim_defineRotMatrix(&rMatrix1, dimElemnote.GetElementP(), &m_dimPoints.front(), &corner1, &m_dimPoints.back());
	mdlRMatrix_getColumnVector(&yvec1, &rMatrix1, 1);

	//Gets witness length
	mdlVec_subtractPoint(&delta1, &point1, &m_dimPoints.front());
	witLength1 = mdlVec_dotProduct(&yvec1, &delta1);


	//Inserts points for dimension element
	InsertPoints(dimElemnote, m_dimPoints);

	//IDimensionEdit required to set the dimension element height
	IDimensionEdit* dimEdit1 = dynamic_cast <IDimensionEdit*> (&dimElemnote.GetHandler());
	if (nullptr == dimEdit1)
		return ERROR;
	RotMatrix rMatrix2 = { 0,1,0 };
	dimEdit1->SetRotationMatrix(dimElemnote, rMatrix2);
	dimEdit1->SetHeight(dimElemnote, 2000000);

	//Apply active settings to dimension element
	ElementPropertyUtils::ApplyActiveSettings(dimElemnote);

	//Adds dimension element to the model
	dimElemnote.AddToModel();

	//设置文本内容
	EditElementHandle   eeh;
	TextBlockPtr textBlock = CreateText(L"", endPoint1,text,0);

	if (textBlock.IsValid())
	{
		if (TEXTBLOCK_TO_ELEMENT_RESULT_Success != TextHandlerBase::CreateElement(eeh, NULL,modelref, *textBlock))
		{
			return ERROR;
		}
	}
	eeh.AddToModel();
	EditElementHandle   eehnote;
	EditElementHandle   eehlead;

	//CreateNote(EditElementHandleR noteElem, EditElementHandleCR leaderElement, TextBlockCR text, bool is3d, DgnModelRefR modelRef, DPoint3dCR leaderCellOrigin
	BentleyStatus bstatus;

	StatusInt sint;
	DimensionStylePtr  textStyle = nullptr;
	textStyle = textStyle->GetActive();
	
	//NoteCellHeaderHandler::AddToModel(eehnote, dimElemnote, modelref->GetDgnModelP);
	bstatus = NoteCellHeaderHandler::CreateNote(eehnote, eehlead, *textBlock, *textStyle,false, *modelref, m_dimPoints);

	//bstatus = NoteCellHeaderHandler::CreateNote(eehnote, dimElemnote, *textBlock, false, *modelref, endPoint1);
	eehlead.AddToModel();
	//eehnote.AppendElementLinkage();
	sint = eehnote.AddToModel();

Parents
  • 附上我的完整代码

    int CreateNoteDim(DgnModelRefP modelref, DPoint3d centerpoint,WCharCP text)
    {
    	BentleyStatus bstatus;
    	DPoint3d startPoint = centerpoint;
    	DPoint3d endPoint = {0,0,0};
    	endPoint.x = centerpoint.x + 2000000;
    	endPoint.y = centerpoint.y + 2000000;
    
    
    	DgnFilePtr    pActiveDgnFile = ISessionMgr::GetActiveDgnFile();
    
    	DimensionStylePtr pDimStyle = DimensionStyle::GetSettings(*pActiveDgnFile);
    
    	DgnTextStylePtr textStyle = DgnTextStyle::GetSettings(*pActiveDgnFile);
    	
    	EditElementHandle noteElem, leaderElement;
    	TextBlockPropertiesPtr txtBlockProp = TextBlockProperties::Create(*textStyle, *(ACTIVEMODEL->AsDgnModelP()));
    	ParagraphPropertiesPtr paragraphProperties = ParagraphProperties::Create(*textStyle, *(ACTIVEMODEL->AsDgnModelP()));
    	RunPropertiesPtr runProp = RunProperties::Create(*textStyle, *(ACTIVEMODEL->AsDgnModelP()));
    	TextBlockPtr textbock = TextBlock::Create(*txtBlockProp, *paragraphProperties, *runProp, *(ACTIVEMODEL->AsDgnModelP()));
    	textbock->AppendText(text);
    
    	NoteCellHeaderHandler::StdDPointVector  noteLeaderPoints;
    	noteLeaderPoints.push_back(startPoint);
    	noteLeaderPoints.push_back(endPoint);
    	bstatus = NoteCellHeaderHandler::CreateNote(noteElem, leaderElement, *textbock, *pDimStyle, false, *ACTIVEMODEL, noteLeaderPoints);
    	IDimensionEdit* iDimEdit = dynamic_cast<IDimensionEdit*>(&leaderElement.GetHandler());
    
    	EditElementHandle lineEeh;
    	
    	DPoint3d ptArr[2] = { startPoint,startPoint };
    	bstatus = LineStringHandler::CreateLineStringElement(lineEeh, NULL, ptArr,2, false, *ACTIVEMODEL);
    	lineEeh.AddToModel();
    	AssocPoint assocPt1;
    	AssociativePoint::InitKeypoint(assocPt1, 1, 2, 0, 1);
    	bstatus = AssociativePoint::SetRoot(assocPt1, lineEeh.GetElementId(), 0);
    
    	if (SUCCESS != iDimEdit->SetPoint(leaderElement, nullptr, &assocPt1, 0))
    	{
    		return ERROR;
    	}
    
    	if (iDimEdit->GetNumPoints(leaderElement) > 0)
    	{
    		iDimEdit->DeletePoint(leaderElement, 0);
    		iDimEdit->InsertPoint(leaderElement, &startPoint, nullptr, *pDimStyle, 0);
    	}
    
    	iDimEdit->SetRotationMatrix(leaderElement, RotMatrix::FromIdentity());
    	bstatus = NoteCellHeaderHandler::AddToModel(noteElem, leaderElement, *(ACTIVEMODEL->AsDgnModelP()));
    	lineEeh.DeleteFromModel();
    	return SUCCESS;
    }

Reply
  • 附上我的完整代码

    int CreateNoteDim(DgnModelRefP modelref, DPoint3d centerpoint,WCharCP text)
    {
    	BentleyStatus bstatus;
    	DPoint3d startPoint = centerpoint;
    	DPoint3d endPoint = {0,0,0};
    	endPoint.x = centerpoint.x + 2000000;
    	endPoint.y = centerpoint.y + 2000000;
    
    
    	DgnFilePtr    pActiveDgnFile = ISessionMgr::GetActiveDgnFile();
    
    	DimensionStylePtr pDimStyle = DimensionStyle::GetSettings(*pActiveDgnFile);
    
    	DgnTextStylePtr textStyle = DgnTextStyle::GetSettings(*pActiveDgnFile);
    	
    	EditElementHandle noteElem, leaderElement;
    	TextBlockPropertiesPtr txtBlockProp = TextBlockProperties::Create(*textStyle, *(ACTIVEMODEL->AsDgnModelP()));
    	ParagraphPropertiesPtr paragraphProperties = ParagraphProperties::Create(*textStyle, *(ACTIVEMODEL->AsDgnModelP()));
    	RunPropertiesPtr runProp = RunProperties::Create(*textStyle, *(ACTIVEMODEL->AsDgnModelP()));
    	TextBlockPtr textbock = TextBlock::Create(*txtBlockProp, *paragraphProperties, *runProp, *(ACTIVEMODEL->AsDgnModelP()));
    	textbock->AppendText(text);
    
    	NoteCellHeaderHandler::StdDPointVector  noteLeaderPoints;
    	noteLeaderPoints.push_back(startPoint);
    	noteLeaderPoints.push_back(endPoint);
    	bstatus = NoteCellHeaderHandler::CreateNote(noteElem, leaderElement, *textbock, *pDimStyle, false, *ACTIVEMODEL, noteLeaderPoints);
    	IDimensionEdit* iDimEdit = dynamic_cast<IDimensionEdit*>(&leaderElement.GetHandler());
    
    	EditElementHandle lineEeh;
    	
    	DPoint3d ptArr[2] = { startPoint,startPoint };
    	bstatus = LineStringHandler::CreateLineStringElement(lineEeh, NULL, ptArr,2, false, *ACTIVEMODEL);
    	lineEeh.AddToModel();
    	AssocPoint assocPt1;
    	AssociativePoint::InitKeypoint(assocPt1, 1, 2, 0, 1);
    	bstatus = AssociativePoint::SetRoot(assocPt1, lineEeh.GetElementId(), 0);
    
    	if (SUCCESS != iDimEdit->SetPoint(leaderElement, nullptr, &assocPt1, 0))
    	{
    		return ERROR;
    	}
    
    	if (iDimEdit->GetNumPoints(leaderElement) > 0)
    	{
    		iDimEdit->DeletePoint(leaderElement, 0);
    		iDimEdit->InsertPoint(leaderElement, &startPoint, nullptr, *pDimStyle, 0);
    	}
    
    	iDimEdit->SetRotationMatrix(leaderElement, RotMatrix::FromIdentity());
    	bstatus = NoteCellHeaderHandler::AddToModel(noteElem, leaderElement, *(ACTIVEMODEL->AsDgnModelP()));
    	lineEeh.DeleteFromModel();
    	return SUCCESS;
    }

Children
No Data