UG/NX二次开发Siemens官方NXOPEN实例解析—2.5 QuickExtrude(拉伸)

本文详细介绍了UG/NX二次开发中如何利用NXOPEN库实现快速拉伸草图的功能,包括选择曲线、获取用户输入参数以及执行拉伸操作的步骤。通过`SelectSketch()`方法进行草图选择,使用`uc1609()`获取拉伸限制,然后利用`ExtrudeBuilder`类创建并设置拉伸特征,最终完成曲线的拉伸。案例提供了一个清晰的二次开发实例,适合学习和参考。
摘要由CSDN通过智能技术生成

 列文章目录

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/NX二次开发Siemens官方NXOPEN实例解析—2.6 CreateNote(注释)
UG/NX二次开发Siemens官方NXOPEN实例解析—2.7 DiameterSymbol(标注符号) 
UG/NX二次开发Siemens官方NXOPEN实例解析—2.8 DrawingCycle(图纸打印)
UG/NX二次开发Siemens官方NXOPEN实例解析—2.9 InteropCallCFromDotNet(VB调用VC++ DLL实践)
UG/NX二次开发Siemens官方NXOPEN实例解析—2.10 InteropNXOpenWithUFWrap(NXOPEN与Ufun混合使用)

 前言

        随着工业智能化的不断发展,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 sketch
	sketch1 =  SelectSketch();
	if(sketch1 == NULL)
	{
		return;
	}
	//Below method launches dialog for asking start and end limits from the user
	response = 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::vector<NXOpen::Selection::MaskTriple>selectionMask_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<Sketch *>(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 Create
    extrudeBuilder1->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 kept
    extrudeBuilder1->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<Features::Feature *> features1(1);
  	features1[0] = sketch1->Feature();
    CurveFeatureRule *curveFeatureRule1;
    curveFeatureRule1 = workPart->ScRuleFactory()->CreateRuleCurveFeature(features1);
    section1->AllowSelfIntersection(false);
    std::vector<SelectionIntentRule *> rules1(1);
    rules1[0] = curveFeatureRule1;

	//Accepting all the geometry from the sketch
	std::vector<NXObject *> 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 section
    section1->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 Extrude
    Features::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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MarcoPro

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值