admin 发表于 2014-2-19 20:30:21

PLM之家-NX9.0 二次开发实例视频31 NXOpen C++创建草图基本特征

PLM之家-NX9.0 二次开发实例视频31 NXOpen C++创建基本特征 <1>-草图的创建
内容:
草图作为参数化建模的基础,使用代码实现草图的创建过程,主要是对草图环境的初始化,以及草图约束的添加等问题。
目的:
在NX中,使用NXOpen C++可以很方便的进行JA的录制,从而发掘草图约束中尺寸约束和几何约束的规律,通过这种方式,可以快速的完成开发。

31 NXOpen C++创建基本特征-草图的创建(1)项目介绍
31 NXOpen C++创建基本特征-草图的创建(2)UI设计
31 NXOpen C++创建基本特征-草图的创建(3)项目创建
31 NXOpen C++创建基本特征-草图的创建(4)草图特征创建
31 NXOpen C++创建基本特征-草图的创建(5)添加几何到草图
31 NXOpen C++创建基本特征-草图的创建(6)添加草图几何约束
31 NXOpen C++创建基本特征-草图的创建(7)添加草图尺寸约束
31 NXOpen C++创建基本特征-草图的创建(8)尺寸和UI关联





关键代码分享:



void lesson31_createSketch::createIPSketch()
{

      Sketch *nullSketch(NULL);
    SketchInPlaceBuilder *sketchInPlaceBuilder1;
      sketchInPlaceBuilder1 = workPart->Sketches()->CreateNewSketchInPlaceBuilder(nullSketch);
      sketchInPlaceBuilder1->SetPlaneOption(Sketch::PlaneOptionNewPlane);

      //sketchInPlaceBuilder1->Plane()->SetMethod(PlaneTypes::MethodTypeFixedZ);


      // add preference

      theSession->Preferences()->Sketch()->SetContinuousAutoDimensioning(false);

      Drafting::PreferencesBuilder *preferencesBuilder1;
    preferencesBuilder1 = workPart->SettingsManager()->CreatePreferencesBuilder();
      preferencesBuilder1->AnnotationStyle()->DimensionStyle()->SetAngularDimensionValuePrecision(3);
      preferencesBuilder1->AnnotationStyle()->DimensionStyle()->SetDimensionValuePrecision(3);
      preferencesBuilder1->Commit();

      preferencesBuilder1->Destroy();


      NXObject *nXObject1;
      nXObject1 = sketchInPlaceBuilder1->Commit();

      Sketch *sketch1(dynamic_cast<Sketch *>(nXObject1));
    Features::Feature *feature1;
    feature1 = sketch1->Feature();
      feature1->SetName("XY-Plane-Sketch");
      
      sketchInPlaceBuilder1->Destroy();

      //1active sketch

      sketch1->Activate(Sketch::ViewReorientFalse);
      
         double height1 = this->expressionHeight1->GetProperties()->GetDouble("Value");
         double height2 = this->expressionHeight2->GetProperties()->GetDouble("Value");
         double length = this->expressionLength->GetProperties()->GetDouble("Value");
      // 2.1create geometry

      Point3d startPoint1(0.0, 0.0, 0.0);
    Point3d endPoint1(0, height1, 0.0);
    Point3d endPoint2(length, height1, 0.0);
      Point3d endPoint3(length, height1-height2, 0.0);
      Point3d origin = sketch1->Origin();
      Point *originPoint = workPart->Points()->CreatePoint(origin);

      Line *line1,*line2,*line3,*line4;
      line1 = workPart->Curves()->CreateLine(startPoint1, endPoint1);
      line2 = workPart->Curves()->CreateLine(endPoint1, endPoint2);
      line3 = workPart->Curves()->CreateLine(endPoint2, endPoint3);
      line4 = workPart->Curves()->CreateLine(endPoint3, startPoint1);
      // 2.2 add geometry

      sketch1->AddGeometry(line1,Sketch::InferConstraintsOptionInferCoincidentConstraints);
      sketch1->AddGeometry(line2,Sketch::InferConstraintsOptionInferCoincidentConstraints);
      sketch1->AddGeometry(line3,Sketch::InferConstraintsOptionInferCoincidentConstraints);
      sketch1->AddGeometry(line4,Sketch::InferConstraintsOptionInferCoincidentConstraints);

      //3add constraints ( gemo)

      Sketch::ConstraintGeometry geomline1;
      geomline1.Geometry = line1;
      geomline1.PointType = Sketch::ConstraintPointTypeNone;
      geomline1.SplineDefiningPointIndex = 0;
      sketch1->CreateVerticalConstraint(geomline1);

      Sketch::ConstraintGeometry geomline2;
      geomline2.Geometry = line2;
      geomline2.PointType = Sketch::ConstraintPointTypeNone;
      geomline2.SplineDefiningPointIndex = 0;
      sketch1->CreateHorizontalConstraint(geomline2);

      Sketch::ConstraintGeometry geomline3;
      geomline3.Geometry = line3;
      geomline3.PointType = Sketch::ConstraintPointTypeNone;
      geomline3.SplineDefiningPointIndex = 0;
      sketch1->CreateVerticalConstraint(geomline3);

      Sketch::ConstraintGeometry geomline1_startPoint;
      geomline1_startPoint.Geometry = line1;
      geomline1_startPoint.PointType = Sketch::ConstraintPointTypeStartVertex;
      geomline1.SplineDefiningPointIndex = 0;
      Sketch::ConstraintGeometry geomline2_originPoint;
      geomline2_originPoint.Geometry = originPoint;
      geomline2_originPoint.PointType = Sketch::ConstraintPointTypeNone;
      geomline2_originPoint.SplineDefiningPointIndex = 0;
      sketch1->CreateCoincidentConstraint(geomline1_startPoint,geomline2_originPoint);

      //4add constraints (dimension)

         NXObject *nullNXObject(NULL);


         stringstream s_height1,s_height2,s_length;
         s_height1 <<height1;
         s_height2 <<height2;
         s_length <<length;

         Expression *expression1,*expression2,*expression3;
         expression1 = workPart->Expressions()->CreateSystemExpression(s_height1.str());
    expression2 = workPart->Expressions()->CreateSystemExpression(s_length.str());
      expression3 = workPart->Expressions()->CreateSystemExpression(s_height2.str());

      // line1 dimension

      Sketch::DimensionGeometry dimLine1_startPoint;
    dimLine1_startPoint.Geometry = line1;
    dimLine1_startPoint.AssocType = Sketch::AssocTypeStartPoint;
    dimLine1_startPoint.AssocValue = 0;
    dimLine1_startPoint.HelpPoint.X = 0.0;
    dimLine1_startPoint.HelpPoint.Y = 0.0;
    dimLine1_startPoint.HelpPoint.Z = 0.0;
    dimLine1_startPoint.View = nullNXObject;

    Sketch::DimensionGeometry dimLine1_endPoint;
    dimLine1_endPoint.Geometry = line1;
    dimLine1_endPoint.AssocType = Sketch::AssocTypeEndPoint;
    dimLine1_endPoint.AssocValue = 0;
    dimLine1_endPoint.HelpPoint.X = 0.0;
    dimLine1_endPoint.HelpPoint.Y = 0.0;
    dimLine1_endPoint.HelpPoint.Z = 0.0;
    dimLine1_endPoint.View = nullNXObject;

      Point3d dimOrigin1(-100, height1/2, 0.0);

      sketch1->CreateDimension(Sketch::ConstraintTypeParallelDim, dimLine1_startPoint, dimLine1_endPoint, dimOrigin1, expression1, Sketch::DimensionOptionCreateAsDriving);


      
      // line2 dimension

      Sketch::DimensionGeometry dimLine2_startPoint;
    dimLine2_startPoint.Geometry = line2;
    dimLine2_startPoint.AssocType = Sketch::AssocTypeStartPoint;
    dimLine2_startPoint.AssocValue = 0;
    dimLine2_startPoint.HelpPoint.X = 0.0;
    dimLine2_startPoint.HelpPoint.Y = 0.0;
    dimLine2_startPoint.HelpPoint.Z = 0.0;
    dimLine2_startPoint.View = nullNXObject;

    Sketch::DimensionGeometry dimLine2_endPoint;
    dimLine2_endPoint.Geometry = line2;
    dimLine2_endPoint.AssocType = Sketch::AssocTypeEndPoint;
    dimLine2_endPoint.AssocValue = 0;
    dimLine2_endPoint.HelpPoint.X = 0.0;
    dimLine2_endPoint.HelpPoint.Y = 0.0;
    dimLine2_endPoint.HelpPoint.Z = 0.0;
    dimLine2_endPoint.View = nullNXObject;

      Point3d dimOrigin2(length /2,100 + height1, 0.0);

      sketch1->CreateDimension(Sketch::ConstraintTypeParallelDim, dimLine2_startPoint, dimLine2_endPoint, dimOrigin2, expression2, Sketch::DimensionOptionCreateAsDriving);


               
      // line3 dimension

      Sketch::DimensionGeometry dimLine3_startPoint;
    dimLine3_startPoint.Geometry = line3;
    dimLine3_startPoint.AssocType = Sketch::AssocTypeStartPoint;
    dimLine3_startPoint.AssocValue = 0;
    dimLine3_startPoint.HelpPoint.X = 0.0;
    dimLine3_startPoint.HelpPoint.Y = 0.0;
    dimLine3_startPoint.HelpPoint.Z = 0.0;
    dimLine3_startPoint.View = nullNXObject;

    Sketch::DimensionGeometry dimLine3_endPoint;
    dimLine3_endPoint.Geometry = line3;
    dimLine3_endPoint.AssocType = Sketch::AssocTypeEndPoint;
    dimLine3_endPoint.AssocValue = 0;
    dimLine3_endPoint.HelpPoint.X = 0.0;
    dimLine3_endPoint.HelpPoint.Y = 0.0;
    dimLine3_endPoint.HelpPoint.Z = 0.0;
    dimLine3_endPoint.View = nullNXObject;

      Point3d dimOrigin3( 100 + length, height1-height2+ height2 /2 , 0.0);
         
      sketch1->CreateDimension(Sketch::ConstraintTypeParallelDim, dimLine3_startPoint, dimLine3_endPoint, dimOrigin3, expression3, Sketch::DimensionOptionCreateAsDriving);



      //5 update & deactive
      sketch1->Update();

      sketch1->Deactivate(Sketch::ViewReorientFalse,Sketch::UpdateLevelModel);

      delete expression1;
      delete expression2;
      delete expression3;
      
}




admin 发表于 2014-2-19 20:30:29



PLM之家NX9.0二次开发视频教程 31 NXOpen C++草图的创建(1)项目介绍

http://player.youku.com/player.php/sid/XMzA4OTY2Mjk2NA==/v.swf


PLM之家NX9.0二次开发视频教程 31 NXOpen C++草图的创建(2)对话框UI设计

http://player.youku.com/player.php/sid/XMzA4OTY2NTE0OA==/v.swf



PLM之家NX9.0二次开发视频教程 31 NXOpen C++草图的创建(3)项目创建

http://player.youku.com/player.php/sid/XMzA4OTY2NTMwMA==/v.swf


PLM之家NX9.0二次开发视频教程 31 NXOpen C++草图的创建(4)草图特征创建

http://player.youku.com/player.php/sid/XMzA4OTY3OTIzNg==/v.swf


PLM之家NX9.0二次开发视频教程 31 NXOpen C++草图的创建(5)添加几何到草图

http://player.youku.com/player.php/sid/XMzA4OTY3ODk2NA==/v.swf


PLM之家NX9.0二次开发视频教程 31 NXOpen C++草图的创建(6)添加草图几何约束

http://player.youku.com/player.php/sid/XMzA4OTY5MjkwMA==/v.swf


admin 发表于 2017-10-18 20:07:01

<p></p><div><br></div><div><br></div><div><h3 style="margin-bottom: 8px; font-size: 18px; line-height: 28px; color: rgb(51, 51, 51); font-family: &quot;Microsoft Yahei&quot;, Simsun, Gotham-Medium, Arial;">PLM之家NX9.0二次开发视频教程 31 NXOpen C++草图的创建(7)添加草图尺寸约束</h3></div><div>http://player.youku.com/player.php/sid/XMzA5NDAyNzQzNg==/v.swf</div>

admin 发表于 2017-10-18 20:08:07

<p></p><div><br></div><div><h3 style="margin-bottom: 8px; font-size: 18px; line-height: 28px; color: rgb(51, 51, 51); font-family: &quot;Microsoft Yahei&quot;, Simsun, Gotham-Medium, Arial;">PLM之家-NX9.0二次开发实例31 NXOpen C++草图的创建(8)尺寸和UI关联</h3></div><div>http://player.youku.com/player.php/sid/XMzA5NDAyODAzMg==/v.swf</div>

guojie123 发表于 2014-2-20 09:37:02

支持,不过今天没视频啊

smthan 发表于 2014-2-26 08:55:50

:)老大,您的教程很给力哟,什么时候才能膜拜呢??

加持 发表于 2014-2-27 10:55:13

视频呢,我在等啊

admin 发表于 2014-3-30 21:32:04

这部分先更新到这里

45guop 发表于 2014-4-3 21:57:53


学习一下谢谢

leaf 发表于 2014-4-4 21:17:42

谢谢分享

璀璨の樱之雨 发表于 2014-4-11 10:07:00

想要看看啊

椰子酥 发表于 2014-4-14 09:48:42

奈斯啊。
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: PLM之家-NX9.0 二次开发实例视频31 NXOpen C++创建草图基本特征