• 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日

  • 相关阅读:
    微软推出Silverlight 5.2版本
    C# 安装部署,关于自定义操作,不能被执行。
    SQL_server_2000安装时挂起的解决办法,其实很简单。
    最全Microsoft JET Database Engine(0x80004005)未指定错误的解决方法
    WP博客wordpress,robots.txt写法
    2012年Web设计和开发的15个趋势
    SEO优化应该如何使用nofollow属性
    WordPress如何做SEO?WordPress博客怎样做网站优化。
    windowsXP SP3安装Photoshop CS 3字体输入没反应的问题及解决办法
    打开网页 错误 2147467259 : 错误描述: 未指定的错误 IIS 限XP系统
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/13458899.html
Copyright © 2020-2023  润新知