NX二次开发源码分享:选择体导出Step格式
NX二次开发源码分享:选择体导出Step格式
void StepExport::do_it()
{
std::vector<TaggedObject*> objectArray;
if (select_bodies(objectArray))
{
NXOpen::Session::UndoMarkId markId1;
markId1 = theSession->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Start");
NXString sBaseDir = theSession->GetEnvironmentVariableValue("UGII_BASE_DIR");
NXString sCfgFile = sBaseDir + "\\step214ug\\ugstep214.def";
NXString sPartSpec = displayPart->FullPath();
std::string sFolder = sPartSpec.GetText();
std::size_t found = sFolder.find_last_of(".");
NXString sStepSpec = sFolder.substr(0, found) + ".stp";
NXOpen::StepCreator *stepCreator1;
stepCreator1 = theSession->DexManager()->CreateStepCreator();
stepCreator1->SetExportAs(NXOpen::StepCreator::ExportAsOptionAp214);
stepCreator1->ExportSelectionBlock()->SetSelectionScope(NXOpen::ObjectSelector::ScopeSelectedObjects);
stepCreator1->ObjectTypes()->SetSolids(true);
stepCreator1->SetSettingsFile(sCfgFile);
stepCreator1->SetInputFile(sPartSpec);
stepCreator1->SetOutputFile(sStepSpec);
stepCreator1->SetFileSaveFlag(false);
stepCreator1->SetLayerMask("1-256");
std::stringstream sBodyList("");
std::vector<TaggedObject*>::iterator iter;
bool added1;
for (iter = objectArray.begin(); iter != objectArray.end(); ++iter)
{
Body* theBody = dynamic_cast<NXOpen::Body*>(*iter);
if (theBody)
{
added1 = stepCreator1->ExportSelectionBlock()->SelectionComp()->Add(theBody);
sBodyList << "Adding Body " << (theBody)->Tag() << std::endl;
}
}
// Debug output
print("UGII_BASE_DIR = " + sBaseDir);
print("Settings File = " + sCfgFile);
print("Input File = " + sPartSpec);
print("Output File = " + sStepSpec);
print(sBodyList.str());
NXOpen::NXObject *nXObject1 = stepCreator1->Commit();
stepCreator1->Destroy();
}
}
页:
[1]