C++ 2010
HPP
//用户头文件
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/CartesianCoordinateSystem.hxx>
#include <NXOpen/CoordinateSystem.hxx>
#include <NXOpen/CoordinateSystemCollection.hxx>
#include <NXOpen/Features_DatumCsysBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/Xform.hxx>
#include <NXOpen/XformCollection.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/Features_DatumCsys.hxx>
#include <NXOpen/Features_DatumCsysBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
//用户代码
Features::Feature * datumCsysfeature1;//定义基准座标
void createdatumCsys();//创建基准座标
void editdatumCsys();//编辑基准座标
Part *workPart;
bool isdatumCsysCreated;
CPP
//用户代码
datumCsysfeature1 = NULL;
isdatumCsysCreated =false ;
workPart = theSession->Parts()->Work();
//创建基准座标
void CreateWCS::createdatumCsys()
{
try
{
if (isdatumCsysCreated)
{
editdatumCsys();//编辑基准座标
return;
}
Features::Feature *nullFeatures_Feature(NULL);
Features::DatumCsysBuilder *datumCsysBuilder1;
datumCsysBuilder1 = workPart->Features()->CreateDatumCsysBuilder(nullFeatures_Feature);
Point3d origin1 = manip0->Origin();
Vector3d xDirection1 = manip0->XAxis();
Vector3d yDirection1 = manip0->YAxis();
Xform *xform1;
xform1 = workPart->Xforms()->CreateXform(origin1, xDirection1, yDirection1, SmartObject::UpdateOptionWithinModeling, 1.0);
CartesianCoordinateSystem *cartesianCoordinateSystem1;
cartesianCoordinateSystem1 = workPart->CoordinateSystems()->CreateCoordinateSystem(xform1, SmartObject::UpdateOptionWithinModeling);
datumCsysBuilder1->SetCsys(cartesianCoordinateSystem1);
datumCsysBuilder1->SetDisplayScaleFactor(1.25);
datumCsysfeature1 = datumCsysBuilder1->CommitFeature();
datumCsysBuilder1->Destroy();
isdatumCsysCreated = true ;
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
CreateWCS::theUI->NXMessageBox()->Show("创建基准座标", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}
//编辑基准座标
void CreateWCS::editdatumCsys()
{
try
{
Features::DatumCsys *datumCsys1(dynamic_cast<Features::DatumCsys *>(workPart->Features()->FindObject(datumCsysfeature1->JournalIdentifier())));
Features::DatumCsysBuilder *datumCsysBuilder2 = workPart->Features()->CreateDatumCsysBuilder(datumCsys1);
Point3d origin1 = manip0->Origin();
Vector3d xDirection1 = manip0->XAxis();
Vector3d yDirection1 = manip0->YAxis();
Xform *xform1;
xform1 = workPart->Xforms()->CreateXform(origin1, xDirection1, yDirection1, SmartObject::UpdateOptionWithinModeling, 1.0);
CartesianCoordinateSystem *cartesianCoordinateSystem1;
cartesianCoordinateSystem1 = workPart->CoordinateSystems()->CreateCoordinateSystem(xform1, SmartObject::UpdateOptionWithinModeling);
datumCsysBuilder2->SetCsys(cartesianCoordinateSystem1);
datumCsysBuilder2->SetDisplayScaleFactor(1.25);
datumCsysfeature1 = datumCsysBuilder2->CommitFeature();
datumCsysBuilder2->Destroy();
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
CreateWCS::theUI->NXMessageBox()->Show("编辑基准座标", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}