NX二次开发源码分享:使用NXOpen C++创建加工型腔铣
这段代码可以参考看看哦,显然比ufun的代码长点,但是是新的也是最好的方法{
/* Initialize the API environment */
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
Session *theSession = Session::GetSession();
Part *workPart = theSession->Parts()->Work();
/*Get the existing group objects to create the operation under*/
CAM::NCGroup *programGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("PROGRAM");
CAM::NCGroup *methodGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("METHOD");
CAM::NCGroup *toolGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("MILL");
CAM::NCGroup *geometryGroup = workPart->CAMSetup()->CAMGroupCollection()->FindObject("WORKPIECE");
/*Create the Cavity Mill operation*/
CAM::Operation *operation = workPart->CAMSetup()->CAMOperationCollection()->Create(programGroup, methodGroup, toolGroup, geometryGroup, "mill_contour", "CAVITY_MILL", CAM::OperationCollection::UseDefaultNameTrue, "CAVITY_MILL");
/*Create the Cavity Milling builder*/
CAM::CavityMillingBuilder *cavityMillingBuilder = workPart->CAMSetup()->CAMOperationCollection()->CreateCavityMillingBuilder(operation);
/*Get the solid body named PART*/
tag_t partSolid = NULL_TAG;
UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "PART", UF_solid_type, false, &partSolid);
Body *partBody = dynamic_cast<Body *> (NXObjectManager::Get(partSolid));
std::vector<Body *> partBodies(1);
partBodies = partBody;
/*Set the part geometry*/
cavityMillingBuilder->PartGeometry()->InitializeData(false);
CAM::GeometrySet *partGeometrySet = cavityMillingBuilder->PartGeometry()->GeometryList()->FindItem(0);
BodyDumbRule *partBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(partBodies);
std::vector<SelectionIntentRule *> partRules(1);
partRules = partBodyDumbRule;
partGeometrySet->ScCollector()->ReplaceRules(partRules, false);
/*Get the solid body named BLANK*/
tag_t blankSolid = NULL_TAG;
UF_OBJ_cycle_by_name_and_type(workPart->Tag(), "BLANK", UF_solid_type, false, &blankSolid);
Body *blankBody = dynamic_cast<Body *> (NXObjectManager::Get(blankSolid));
std::vector<Body *> blankBodies(1);
blankBodies = blankBody;
/*Set the blank geometry*/
cavityMillingBuilder->BlankGeometry()->InitializeData(false);
CAM::GeometrySet *blankGeometrySet = cavityMillingBuilder->BlankGeometry()->GeometryList()->FindItem(0);
BodyDumbRule *blankBodyDumbRule = workPart->ScRuleFactory()->CreateRuleBodyDumb(blankBodies);
std::vector<SelectionIntentRule *> blankRules(1);
blankRules = blankBodyDumbRule;
blankGeometrySet->ScCollector()->ReplaceRules(blankRules, false);
cavityMillingBuilder->Commit();
cavityMillingBuilder->Destroy();
/*Generate the tool path*/
std::vector<CAM::CAMObject *> operations(1);
operations = operation;
workPart->CAMSetup()->GenerateToolPath(operations);
/* Terminate the API environment */
UF_CALL(UF_terminate());
}
页:
[1]