iCAx开思工具箱

标题: 用NX Open C++画Studio Spline的访问冲突中断 [打印本页]

作者: p36288    时间: 2010-9-10 22:55
标题: 用NX Open C++画Studio Spline的访问冲突中断
我想用NX Open C++编个简单的外部程序生成一条Studio Spline曲线,直接用操作记录稍微改了一下。程序没有报错,但是调试的时候在“studioSplineBuilder1->CommitFeature()”这句(代码倒数第九行)跳出来这个中断:“***.exe 中的 0x2031f7eb 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突”(Unhandled exception at 0x2031f7eb in test.exe: 0xC0000005: Access violation reading location 0x00000000.)。请高手指教。
我尝试过生成直线或圆弧,都没有这个问题。
我的邮箱:p36288@gmail.com,用的是NX7.0,中文Visual Studio 2008,系统WinXP。下面是程序原文:

  1. /* Include files */
  2. #if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
  3. #   include <strstream>
  4. #   include <iostream>
  5.     using std::ostrstream;
  6.     using std::endl;   
  7.     using std::ends;
  8.     using std::cerr;
  9. #else
  10. #   include <strstream.h>
  11. #   include <iostream.h>
  12. #endif
  13. #include <uf.h>
  14. #include <ug_session.hxx>
  15. #include <ug_exception.hxx>
  16. #include <uf_defs.h>
  17. /*Your Code*/
  18. #include <NXOpen/NXException.hxx>
  19. #include <NXOpen/Session.hxx>
  20. #include <NXOpen/BasePart.hxx>
  21. #include <NXOpen/Builder.hxx>
  22. #include <NXOpen/Features_Feature.hxx>
  23. #include <NXOpen/Features_FeatureBuilder.hxx>
  24. #include <NXOpen/Features_FeatureCollection.hxx>
  25. #include <NXOpen/Features_GeometricConstraintData.hxx>
  26. #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
  27. #include <NXOpen/Features_StudioSplineBuilder.hxx>
  28. #include <NXOpen/Part.hxx>
  29. #include <NXOpen/PartCollection.hxx>
  30. #include <NXOpen/PartSaveStatus.hxx>
  31. #include <NXOpen/Point.hxx>
  32. #include <NXOpen/PointCollection.hxx>
  33. #include <NXOpen/Preferences_PartModeling.hxx>
  34. #include <NXOpen/Preferences_PartPreferences.hxx>
  35. #include <NXOpen/Session.hxx>
  36. #include <NXOpen/Spline.hxx>
  37. #include <NXOpen/Update.hxx>
  38. using namespace NXOpen;

  39. /* Main routine */
  40. extern void main( char argc, char *argv[] )
  41. {
  42.     Session *theSession = Session::GetSession();
  43.     NXOpen::NXString partName = "NXcurve.prt";
  44.     Part *workPart = theSession->Parts()->NewDisplay(partName, NXOpen::Part::UnitsInches);
  45. /*创建Studio Spline*/
  46.     Point3d coordinates1(-60.9672168874869, -85.3444953331698, -16.2564577575515);
  47.     Point *point1;
  48.     point1 = workPart->Points()->CreatePoint(coordinates1);
  49.     Point3d coordinates2(-36.7798197522759, -26.6915553863001, 28.8322080982988);
  50.     Point *point2;
  51.     point2 = workPart->Points()->CreatePoint(coordinates2);
  52.     Point3d coordinates3(-3.3110308509701, -13.9095206113823, -15.3362809033505);
  53.     Point *point3;
  54.     point3 = workPart->Points()->CreatePoint(coordinates3);
  55.     Point3d coordinates4(50.4956319822501, 34.6877235376336, -42.6348609113142);
  56.     Point *point4;
  57.     point4 = workPart->Points()->CreatePoint(coordinates4);

  58.     Features::StudioSpline *nullFeatures_StudioSpline(NULL);
  59.     Features::StudioSplineBuilder *studioSplineBuilder1;
  60.     studioSplineBuilder1 = workPart->Features()->CreateStudioSplineBuilder(nullFeatures_StudioSpline);
  61.     studioSplineBuilder1->SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
  62.     studioSplineBuilder1->SetSplineMethod(Features::StudioSplineBuilder::MethodByPoles);
  63.     studioSplineBuilder1->SetDegree(3);
  64.     studioSplineBuilder1->SetPeriodic(false);
  65.     std::vector<double> knots1(0);
  66.     studioSplineBuilder1->SetKnots(knots1);
  67.     std::vector<double> parameters1(0);
  68.     studioSplineBuilder1->SetParameters(parameters1);

  69.     Features::GeometricConstraintData *geometricConstraintData1;
  70.     geometricConstraintData1 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
  71.     geometricConstraintData1->SetPoint(point1);
  72.     geometricConstraintData1->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
  73.     geometricConstraintData1->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
  74.     Direction *nullDirection(NULL);
  75.     geometricConstraintData1->SetTangentDirection(nullDirection);
  76.     Scalar *nullScalar(NULL);
  77.     geometricConstraintData1->SetTangentMagnitude(nullScalar);
  78.     Offset *nullOffset(NULL);
  79.     geometricConstraintData1->SetCurvature(nullOffset);
  80.     geometricConstraintData1->SetCurvatureDerivative(nullOffset);
  81.     geometricConstraintData1->SetHasSymmetricModelingConstraint(false);

  82.     Features::GeometricConstraintData *geometricConstraintData2;
  83.     geometricConstraintData2 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
  84.     geometricConstraintData2->SetPoint(point2);
  85.     geometricConstraintData2->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
  86.     geometricConstraintData2->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
  87.     geometricConstraintData2->SetTangentDirection(nullDirection);
  88.     geometricConstraintData2->SetTangentMagnitude(nullScalar);
  89.     geometricConstraintData2->SetCurvature(nullOffset);
  90.     geometricConstraintData2->SetCurvatureDerivative(nullOffset);
  91.     geometricConstraintData2->SetHasSymmetricModelingConstraint(false);

  92.     Features::GeometricConstraintData *geometricConstraintData3;
  93.     geometricConstraintData3 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
  94.     geometricConstraintData3->SetPoint(point3);
  95.     geometricConstraintData3->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
  96.     geometricConstraintData3->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
  97.     geometricConstraintData3->SetTangentDirection(nullDirection);
  98.     geometricConstraintData3->SetTangentMagnitude(nullScalar);
  99.     geometricConstraintData3->SetCurvature(nullOffset);
  100.     geometricConstraintData3->SetCurvatureDerivative(nullOffset);
  101.     geometricConstraintData3->SetHasSymmetricModelingConstraint(false);

  102.     Features::GeometricConstraintData *geometricConstraintData4;
  103.     geometricConstraintData4 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
  104.     geometricConstraintData4->SetPoint(point4);
  105.     geometricConstraintData4->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
  106.     geometricConstraintData4->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
  107.     geometricConstraintData4->SetTangentDirection(nullDirection);
  108.     geometricConstraintData4->SetTangentMagnitude(nullScalar);
  109.     geometricConstraintData4->SetCurvature(nullOffset);
  110.     geometricConstraintData4->SetCurvatureDerivative(nullOffset);
  111.     geometricConstraintData4->SetHasSymmetricModelingConstraint(false);

  112.     std::vector<Features::GeometricConstraintData *> constraints1(4);
  113.     constraints1[0] = geometricConstraintData1;
  114.     constraints1[1] = geometricConstraintData2;
  115.     constraints1[2] = geometricConstraintData3;
  116.     constraints1[3] = geometricConstraintData4;
  117.     studioSplineBuilder1->ConstraintManager()->SetContents(constraints1);

  118.     Features::Feature *feature1;
  119.     feature1 = studioSplineBuilder1->CommitFeature();

  120.     Spline *spline1;
  121.     spline1 = studioSplineBuilder1->Curve();
  122.     studioSplineBuilder1->Destroy();
  123. /*Save*/
  124.     NXOpen::PartSaveStatus *partSaveStatus;
  125.     workPart->Save(NXOpen::Part::SaveComponentsTrue, NXOpen::Part::CloseAfterSaveTrue, &partSaveStatus);
  126. }
复制代码






欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3