NX二次开发培训源码分享: 通过选择指定特征,修改特征...
创建一个选择feature的功能,当用户选择的是sphere的时候,让用户选择更改球的直径!
Session *theSession = Session::GetSession();
UI *theUI = UI ::GetUI();
Part *workPart (theSession->Parts()->Work());
// initialize the select
std::vector <Selection::MaskTriple> masks(1);
Selection::MaskTriple mask;
mask.Type=UF_feature_type;
mask.Subtype =0;
mask.SolidBodySubtype=0;
masks.push_back(mask);
//masks = {{UF_feature_type,0,0}};
TaggedObject *object;
std::stringstream ss;
Point3d cursor;
Selection::SelectionScope scope =Selection::SelectionScopeUseDefault;
Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
Selection::Response res;
Features::Feature * getFeature = NULL;
res = theUI->SelectionManager()->SelectTaggedObject("select a feature:","feature select",scope,action,false,false,masks,&object,&cursor);
if(res == Selection::ResponseObjectSelected || res == Selection::ResponseObjectSelectedByName)
{
// get the information
getFeature = dynamic_cast<Features::Feature *>(object);
theSession->ListingWindow()->WriteLine("the select feature type is : " +getFeature->FeatureType() + "\n");
if (!strcmp(getFeature->FeatureType().GetUTF8Text(),"SPHERE"))
{
Features::Sphere *getSphere = dynamic_cast<Features::Sphere *>(getFeature);
std::vector<Expression *> exp =getSphere->GetExpressions();
ss << exp.size() <<endl;
theSession->ListingWindow()->WriteLine("the expression number is : "+ ss.str() );
for(unsigned int i =0 ; i< exp.size();i++)
{
theSession->ListingWindow()->WriteLine("The expressions are : " + exp->Equation()+"\n");
}
Session::UndoMarkId undomark = theSession->SetUndoMark(Session::MarkVisibilityVisible,"change the exp");
exp->SetRightHandSide("400");
theSession->UpdateManager()->DoUpdate(undomark);
theSession->ListingWindow()->WriteLine("The expressions are : " + exp->Equation()+"\n");
}
}
页:
[1]