UG/NX二次开发Siemens官方NXOPEN实例解析—2.5 QuickExtrude
创始人
2024-04-27 22:48:00
0次

 列文章目录

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、需求分解

1)选择曲线

2)拉伸曲线

三、程序分析

1、源码所在目录

UGOPEN\SampleNXOpenApplications\C++\QuickExtrude

2、主要功能分析 

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);

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...