1. 程式人生 > 實用技巧 >NX二次開發-UFUN建立掃掠UF_MODL_create_sweep

NX二次開發-UFUN建立掃掠UF_MODL_create_sweep

這個函式挺複雜的,我也是參考別人去做的。但是我還是沒有做出來多段引導線的。

我們在做鑽頭螺旋槽的時候,一般都是拿一個封閉截面,三條引導線去做掃掠。

後來我是錄製NXOPEN去做的

參考資料 https://www.ugapi.com/thread-10038.html

NX9+VS2012

#include <uf_object_types.h>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/Annotations.hxx>
#include 
<NXOpen/Assemblies_Component.hxx> #include <NXOpen/Assemblies_ComponentAssembly.hxx> #include <NXOpen/Body.hxx> #include <NXOpen/BodyCollection.hxx> #include <NXOpen/Face.hxx> #include <NXOpen/Line.hxx> #include <NXOpen/NXException.hxx> #include <NXOpen/NXObject.hxx> #include
<NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include <NXOpen/CartesianCoordinateSystem.hxx> #include <NXOpen/CoordinateSystemCollection.hxx> #include <NXOpen/Features_FeatureCollection.hxx> #include <NXOpen/Features_HelixBuilder.hxx> #include <NXOpen/XformCollection.hxx> #include
<uf.h> #include <uf_modl.h> #include <uf_curve.h> #include <uf_vec.h> tag_t CreateHelical(string strVal[5], double origin[3], double xDirection[3], double yDirection[3]) { Session *theSession = Session::GetSession(); Part *workPart(theSession->Parts()->Work()); Part *displayPart(theSession->Parts()->Display()); Features::Helix *nullFeatures_Helix(NULL); Features::HelixBuilder *helixBuilder1; helixBuilder1 = workPart->Features()->CreateHelixBuilder(nullFeatures_Helix); helixBuilder1->SetOrientationOption(Features::HelixBuilder::OrientationOptionsSpecified); helixBuilder1->StartAngle()->SetRightHandSide(strVal[0].c_str()); //角度 helixBuilder1->SizeLaw()->Value()->SetRightHandSide(strVal[1].c_str()); //直徑 helixBuilder1->PitchLaw()->Value()->SetRightHandSide(strVal[2].c_str());//螺距 helixBuilder1->StartLimit()->Expression()->SetRightHandSide(strVal[3].c_str());//起始 helixBuilder1->EndLimit()->Expression()->SetRightHandSide(strVal[4].c_str());//終止 Point3d originCoord(origin[0], origin[1], origin[2]); Vector3d xDirection1(xDirection[0], xDirection[1], xDirection[2]); Vector3d yDirection1(yDirection[0], yDirection[1], yDirection[2]); Xform *xform1; xform1 = workPart->Xforms()->CreateXform(originCoord, xDirection1, yDirection1, SmartObject::UpdateOptionWithinModeling, 1.0); CartesianCoordinateSystem *cartesianCoordinateSystem1; cartesianCoordinateSystem1 = workPart->CoordinateSystems()->CreateCoordinateSystem(xform1, SmartObject::UpdateOptionWithinModeling); helixBuilder1->SetCoordinateSystem(cartesianCoordinateSystem1); NXObject *nXObject1; nXObject1 = helixBuilder1->Commit(); helixBuilder1->Destroy(); return nXObject1->Tag(); } void MyClass::do_it() { // TODO: add your code here UF_initialize(); //設定螺旋線引數 string strVal[5] = { "0", "8.5", "56", "0", "285" }; double origin[3] = { 0.0, 0.0, 0.0 }; double xd[3] = { 1.0, 1.0, 0.0 }; double yd[3] = { 0.0, 1.0, 0.0 }; //建立螺旋線 tag_t helicalTag = CreateHelical(strVal, origin, xd, yd); //建立三點整圓 double first_point1[3] = { -2.0, 0.0, 0.0 }; double second_point1[3] = { 0.0, 2.0, 0.0 }; double third_point1[3] = { 2.0, 0.0, 0.0 }; tag_t arc_tag1 = NULL_TAG; UF_CURVE_create_arc_thru_3pts(2, first_point1, second_point1, third_point1, &arc_tag1); //定義引導線 UF_STRING_t s_guide; UF_MODL_init_string_list(&s_guide); UF_MODL_create_string_list(1, 1, &s_guide);//第二個引數為引導線數量 s_guide.num = 1; s_guide.string[0] = 1;//引導線數量 s_guide.dir[0] = 1; s_guide.id[0] = helicalTag; //將前面建立的螺旋線tag作為引導線 //定義截面線 UF_STRING_t s_section; UF_MODL_init_string_list(&s_section); UF_MODL_create_string_list(1, 1, &s_section);//第二個引數為截面線數量 s_section.num = 1; s_section.string[0] = 1;//截面線數量 s_section.dir[0] = 1; s_section.id[0] = arc_tag1;//輸入截面線tag //定義脊線 UF_STRING_t s_spine; UF_MODL_init_string_list(&s_spine); //設定定位方法 UF_METHOD_t orientation; orientation.method = 4;//定位方法(方向)4是固定 orientation.value[0] = 0; orientation.value[1] = 1; orientation.value[2] = 0; orientation.id = 0; orientation.inter = 0; //設定縮放方法 UF_METHOD_t scaling; scaling.method = 1; scaling.value[0] = 1; scaling.value[1] = 0; scaling.value[2] = 0; scaling.id = 0; scaling.inter = 0; int alignment = 1;//調整方法,引數還是弧長 int inter = 1;//插值方法,線性還是立方 int body_type = 1;//設定掃掠片體還是實體 double tol[3] = { 0, 0, 0 };//指定公差(全為0就是勾選保留形狀) tag_t body_id = NULL_TAG; //建立掃掠 UF_MODL_create_sweep(&s_guide, &s_section, &s_spine, &orientation, &scaling, &alignment, &inter, &body_type, UF_NULLSIGN, tol, &body_id); //釋放 UF_MODL_free_string_list(&s_guide); UF_MODL_free_string_list(&s_section); UF_MODL_free_string_list(&s_spine); UF_terminate(); } Caesar盧尚宇 2020年8月8日