UG/NX二次开发Siemens官方NXOPEN实例解析—2.1 AssemblyViewer
UG/NX二次开发Siemens官方NXOPEN实例解析—2.2 Selection
UG/NX二次开发Siemens官方NXOPEN实例解析—2.3 Selection_UIStyler
UG/NX二次开发Siemens官方NXOPEN实例解析—2.4 File2Points
UG/NX二次开发Siemens官方NXOPEN实例解析—2.5 QuickExtrude
随着工业智能化的不断发展,UG二次开发的需求越来越多,也吸引了大批的二开从业人员,本人作为一名资深IT从业者(10年+)也毅然加入二次开发大军。
然而,和流行IT行业(互联网、金融、医疗等)相比,工业智能化的门槛显得更高一点,专业的工业软件,相对封闭的开发理念和更小的开发圈子,让刚进入二开的从业者有点举步维艰。边学边整理,希望通过这系列文章的整理能给二开的生态增添一叶绿。
本案例实现了快速拉伸草图,主要知识点如下:
1)不使用blockui实现选择草图功能
2)返回输入参数
3)快速拉伸草图
1)选择曲线
2)拉伸曲线
UGOPEN\SampleNXOpenApplications\C++\QuickExtrude
1)选择曲线,输入拉伸参数的实现(不使用blockui)
char labels[][16] = {"Start Limit","End Limit"};int noOfitems = 2;double limits[2] = {0.0,1.0};int *ip5 = NULL;int response;NXOpen::Sketch* sketch1 = NULL;//Method SelectSketch is called for user to select sketchsketch1 = SelectSketch();if(sketch1 == NULL){return;}//Below method launches dialog for asking start and end limits from the userresponse = uc1609("Start and End Limit", labels ,noOfitems,limits, ip5);//Method that returns sketch after user selection
NXOpen::Sketch* SelectSketch()
{ UI *theUI = UI::GetUI();NXOpen::Selection::SelectionScope scope = Selection::SelectionScopeWorkPart;NXOpen::Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;std::vectorselectionMask_array(1);selectionMask_array[0].Type = UF_sketch_type;selectionMask_array[0].Subtype = 0;selectionMask_array[0].SolidBodySubtype = 0;NXOpen::NXObject *selectedObject = NULL;Point3d cursor;cursor.X = 0.0;cursor.Y = 0.0;cursor.Z = 0.0;theUI->SelectionManager()->SelectObject("Select Sketch","Sketch Selection",scope,action,true,false,selectionMask_array,&selectedObject,&cursor);Sketch *sketch1(dynamic_cast(selectedObject));if(sketch1==NULL){return NULL;}return sketch1;
}
这里主要使用了2个内部方法:
1、theUI->SelectionManager()->SelectObject() , 实现选择对象的功能,可以通过参数控制对象过滤
2、uc1609(), 显示输入菜单并获得响应, 这个方法可以用来收集输入参数
2、 快速拉伸曲线功能
//Inititalizing ExtrudeBuilder with NULL Feature.Features::ExtrudeBuilder *extrudeBuilder1;extrudeBuilder1 = workPart->Features()->CreateExtrudeBuilder(nullFeatures_Feature);extrudeBuilder1->SetSection(section1);//Boolean Type is set to CreateextrudeBuilder1->BooleanOperation()->SetType(GeometricUtilities::BooleanOperation::BooleanTypeCreate);//Stat end Endlimits are the inputs from the user in the strings start and end.extrudeBuilder1->Limits()->StartExtend()->Value()->SetRightHandSide(start.str()); extrudeBuilder1->Limits()->EndExtend()->Value()->SetRightHandSide(end.str());//Default offset values are keptextrudeBuilder1->Offset()->StartOffset()->SetRightHandSide("0"); extrudeBuilder1->Offset()->SetStartOffset("0"); extrudeBuilder1->Offset()->EndOffset()->SetRightHandSide("0.25"); extrudeBuilder1->Offset()->SetEndOffset("0.25");theSession->SetUndoMarkName(markId1, "'Extrude Dialog");section1->SetAllowedEntityTypes(Section::AllowTypesOnlyCurves);std::vector features1(1);features1[0] = sketch1->Feature();CurveFeatureRule *curveFeatureRule1;curveFeatureRule1 = workPart->ScRuleFactory()->CreateRuleCurveFeature(features1);section1->AllowSelfIntersection(false);std::vector rules1(1);rules1[0] = curveFeatureRule1;//Accepting all the geometry from the sketchstd::vector geoms = sketch1->GetAllGeometry();NXObject *nXObject1 = geoms[0];NXObject *nullNXObject(NULL);Point3d helpPoint1(4.0, 2.58864289093996, 2.22930704874002);//The selected sketch is added to the sectionsection1->AddToSection(rules1, nXObject1, nullNXObject, nullNXObject, helpPoint1, Section::ModeCreate);//Setting up the direction Direction *direction1;direction1 = workPart->Directions()->CreateDirection(sketch1, SenseForward, SmartObject::UpdateOptionWithinModeling);extrudeBuilder1->SetDirection(direction1);extrudeBuilder1->SetParentFeatureInternal(false);//CommitFeature emethod will create ExtrudeFeatures::Feature *feature1;feature1 = extrudeBuilder1->CommitFeature();
这里用到了ExtrudeBuilder类,实现曲线拉伸。拉伸方法需要关注以下几点:
1)拉伸的起止限制
extrudeBuilder1->Limits()->StartExtend()->Value()->SetRightHandSide(start.str());
extrudeBuilder1->Limits()->EndExtend()->Value()->SetRightHandSide(end.str());2)偏置设置
extrudeBuilder1->Offset()->StartOffset()->SetRightHandSide("0");
extrudeBuilder1->Offset()->SetStartOffset("0");
extrudeBuilder1->Offset()->EndOffset()->SetRightHandSide("0.25");
extrudeBuilder1->Offset()->SetEndOffset("0.25");3)拉伸方向设置
Direction *direction1;
direction1 = workPart->Directions()->CreateDirection(sketch1, SenseForward, SmartObject::UpdateOptionWithinModeling);
extrudeBuilder1->SetDirection(direction1);
extrudeBuilder1->SetParentFeatureInternal(false);