创建TXT文字

void DZWEIZHI::CreaTxt(string str, double note_origin[3])////创建TXT文字
{
try
{
//---- Enter your callback code here -----

NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());


Features::Text *nullFeatures_Text(NULL);
Features::TextBuilder *textBuilder1;
textBuilder1 = workPart->Features()->CreateTextBuilder(nullFeatures_Text);


//textBuilder1->SetScript(Features::TextBuilder::ScriptOptionsWestern);
textBuilder1->PlanarFrame()->SetAnchorLocation(GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeMiddleCenter);//锚点位置
textBuilder1->PlanarFrame()->Height()->SetRightHandSide("3"); //设置字体的高度
textBuilder1->PlanarFrame()->SetWScale(100.0);//设置长宽比例
textBuilder1->PlanarFrame()->Shear()->SetRightHandSide("0");//剪切(角度)

//textBuilder1->PlanarFrame()->Length()->SetRightHandSide("5");//会根据比例自动生成,所以不用设置
//textBuilder1->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");//不知道啥设置
//textBuilder1->FrameOnPath()->Offset()->SetRightHandSide("0");//不知道啥设置
//textBuilder1->FrameOnPath()->Length()->SetRightHandSide("1");//不知道啥设置
//textBuilder1->FrameOnPath()->Height()->SetRightHandSide("10");//不知道啥设置


textBuilder1->SelectFont("Arial", Features::TextBuilder::ScriptOptionsWestern);//设置字体

char msg[256];

sprintf(msg, "%s", str.c_str());

textBuilder1->SetTextString(msg);//设置要刻的文本


Point3d theOrigin = { note_origin[0],note_origin[1],note_origin[2] };

//Point3d OriginalWcsOrigin;//WCS 原点

//OriginalWcsOrigin = workPart->WCS()->Origin();//获得WCS原点

NXOpen::Vector3d OriginalxDirection;//WCS X轴

NXOpen::Vector3d OriginalyDirection;//WCS Y轴

NXOpen::CartesianCoordinateSystem* OriginalWcsData = workPart->WCS()->CoordinateSystem();

OriginalWcsData->GetDirections(&OriginalxDirection, &OriginalyDirection);//获得WCS的XY

//NXOpen::Matrix3x3 OriginalWsmtx;//WCS 矩阵

//OriginalWsmtx = workPart->WCS()->CoordinateSystem()->Orientation()->Element();//获得WCS的矩阵


Xform *xform1;

xform1 = workPart->Xforms()->CreateXform(theOrigin, OriginalxDirection, OriginalyDirection, SmartObject::UpdateOptionWithinModeling, 1.0);//创建转换

CartesianCoordinateSystem *cartesianCoordinateSystem1;

cartesianCoordinateSystem1 = workPart->CoordinateSystems()->CreateCoordinateSystem(xform1, SmartObject::UpdateOptionWithinModeling);//创建坐标系

textBuilder1->PlanarFrame()->SetCoordinateSystem(cartesianCoordinateSystem1);
textBuilder1->PlanarFrame()->UpdateOnCoordinateSystem();


NXObject *textnXObject1;
textnXObject1 = textBuilder1->Commit();

textBuilder1->Destroy();

vecTAGtxt.insert(vecTAGtxt.begin(), textnXObject1);//往容器的第一个位置添加元素

//vecTAGtxt.push_back(textnXObject1);
//if (vecTAGtxt.size() > 0)
//{
// vecTAGtxt.clear();
//}

}
catch (exception& ex)
{
//---- Enter your exception handling code here -----
DZWEIZHI::theUI->NXMessageBox()->Show("创建文字曲线", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}


}

posted @ 2023-02-18 11:58  firetuo  阅读(249)  评论(0)    收藏  举报