NX二次开发源码分享: 创建CSYS坐标系并进行颜色设置
NX二次开发源码分享: 创建CSYS坐标系并进行颜色设置
再对整个CSYS进行颜色设置的时候,需要分别对自对象进行颜色设置,否则结果是失败的!
NXOpen::ListingWindow*lw = theSession->ListingWindow();
stringstream ss;
NXOpen::Vector3d xdir,ydir;
NXOpen::Point3d originPoint;
lw->Open();
ss << ("创建的坐标系统信息如下:\n");
std::vector<NXOpen::TaggedObject *> coordObjects = this->coord_system0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
NXOpen::CartesianCoordinateSystem *coord = dynamic_cast<NXOpen::CartesianCoordinateSystem *>(coordObjects);
coord->GetDirections(&xdir,&ydir);
ss<<"返回的坐标系X方向矢量是:"<<xdir.X<<"\t"<<xdir.Y<<"\t"<<xdir.Z<<endl;
ss<<"返回的坐标系Y方向矢量是:"<<ydir.X<<"\t"<<ydir.Y<<"\t"<<ydir.Z<<endl;
originPoint = coord->Origin();
ss<<"返回的坐标系中心是:"<<originPoint.X<<"\t"<<originPoint.Y<<"\t"<<originPoint.Z<<endl;
lw->WriteLine(ss.str());
// create the csys
Part *workpart(theSession->Parts()->Work());
Features::Feature *null_feature(NULL);
Features::DatumCsysBuilder *datumCsysBuilder ;
datumCsysBuilder = workpart->Features()->CreateDatumCsysBuilder(null_feature);
datumCsysBuilder->SetCsys(coord);
datumCsysBuilder->SetDisplayScaleFactor(1.5);
datumCsysBuilder->Commit();
std::vector< NXOpen::NXObject * >GetCommittedObjects;
GetCommittedObjects=datumCsysBuilder->GetCommittedObjects();
datumCsysBuilder->Destroy();
// set the color
NXOpen::DisplayModification *displayObject;
displayObject = theSession->DisplayManager()->NewDisplayModification();
displayObject->SetApplyToAllFaces(true);
displayObject->SetNewColor(200);
std::vector <DisplayableObject *> csysObject;
ss.clear();
ss.str("");
ss<<"一个坐标系生成的对象有几个:"<< GetCommittedObjects.size()<<endl;
lw->WriteLine(ss.str());
for(unsigned int i = 0 ; i < GetCommittedObjects.size();i ++ )
{
csysObject.push_back( dynamic_cast<DisplayableObject *>(GetCommittedObjects));
}
displayObject->Apply(csysObject);
delete displayObject;
页:
[1]