马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我想用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。下面是程序原文:-
- /* Include files */
- #if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
- # include <strstream>
- # include <iostream>
- using std::ostrstream;
- using std::endl;
- using std::ends;
- using std::cerr;
- #else
- # include <strstream.h>
- # include <iostream.h>
- #endif
- #include <uf.h>
- #include <ug_session.hxx>
- #include <ug_exception.hxx>
- #include <uf_defs.h>
- /*Your Code*/
- #include <NXOpen/NXException.hxx>
- #include <NXOpen/Session.hxx>
- #include <NXOpen/BasePart.hxx>
- #include <NXOpen/Builder.hxx>
- #include <NXOpen/Features_Feature.hxx>
- #include <NXOpen/Features_FeatureBuilder.hxx>
- #include <NXOpen/Features_FeatureCollection.hxx>
- #include <NXOpen/Features_GeometricConstraintData.hxx>
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
- #include <NXOpen/Part.hxx>
- #include <NXOpen/PartCollection.hxx>
- #include <NXOpen/PartSaveStatus.hxx>
- #include <NXOpen/Point.hxx>
- #include <NXOpen/PointCollection.hxx>
- #include <NXOpen/Preferences_PartModeling.hxx>
- #include <NXOpen/Preferences_PartPreferences.hxx>
- #include <NXOpen/Session.hxx>
- #include <NXOpen/Spline.hxx>
- #include <NXOpen/Update.hxx>
- using namespace NXOpen;
- /* Main routine */
- extern void main( char argc, char *argv[] )
- {
- Session *theSession = Session::GetSession();
- NXOpen::NXString partName = "NXcurve.prt";
- Part *workPart = theSession->Parts()->NewDisplay(partName, NXOpen::Part::UnitsInches);
- /*创建Studio Spline*/
- Point3d coordinates1(-60.9672168874869, -85.3444953331698, -16.2564577575515);
- Point *point1;
- point1 = workPart->Points()->CreatePoint(coordinates1);
- Point3d coordinates2(-36.7798197522759, -26.6915553863001, 28.8322080982988);
- Point *point2;
- point2 = workPart->Points()->CreatePoint(coordinates2);
- Point3d coordinates3(-3.3110308509701, -13.9095206113823, -15.3362809033505);
- Point *point3;
- point3 = workPart->Points()->CreatePoint(coordinates3);
- Point3d coordinates4(50.4956319822501, 34.6877235376336, -42.6348609113142);
- Point *point4;
- point4 = workPart->Points()->CreatePoint(coordinates4);
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
- Features::StudioSplineBuilder *studioSplineBuilder1;
- studioSplineBuilder1 = workPart->Features()->CreateStudioSplineBuilder(nullFeatures_StudioSpline);
- studioSplineBuilder1->SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
- studioSplineBuilder1->SetSplineMethod(Features::StudioSplineBuilder::MethodByPoles);
- studioSplineBuilder1->SetDegree(3);
- studioSplineBuilder1->SetPeriodic(false);
- std::vector<double> knots1(0);
- studioSplineBuilder1->SetKnots(knots1);
- std::vector<double> parameters1(0);
- studioSplineBuilder1->SetParameters(parameters1);
- Features::GeometricConstraintData *geometricConstraintData1;
- geometricConstraintData1 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
- geometricConstraintData1->SetPoint(point1);
- geometricConstraintData1->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
- geometricConstraintData1->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
- Direction *nullDirection(NULL);
- geometricConstraintData1->SetTangentDirection(nullDirection);
- Scalar *nullScalar(NULL);
- geometricConstraintData1->SetTangentMagnitude(nullScalar);
- Offset *nullOffset(NULL);
- geometricConstraintData1->SetCurvature(nullOffset);
- geometricConstraintData1->SetCurvatureDerivative(nullOffset);
- geometricConstraintData1->SetHasSymmetricModelingConstraint(false);
- Features::GeometricConstraintData *geometricConstraintData2;
- geometricConstraintData2 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
- geometricConstraintData2->SetPoint(point2);
- geometricConstraintData2->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
- geometricConstraintData2->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
- geometricConstraintData2->SetTangentDirection(nullDirection);
- geometricConstraintData2->SetTangentMagnitude(nullScalar);
- geometricConstraintData2->SetCurvature(nullOffset);
- geometricConstraintData2->SetCurvatureDerivative(nullOffset);
- geometricConstraintData2->SetHasSymmetricModelingConstraint(false);
- Features::GeometricConstraintData *geometricConstraintData3;
- geometricConstraintData3 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
- geometricConstraintData3->SetPoint(point3);
- geometricConstraintData3->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
- geometricConstraintData3->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
- geometricConstraintData3->SetTangentDirection(nullDirection);
- geometricConstraintData3->SetTangentMagnitude(nullScalar);
- geometricConstraintData3->SetCurvature(nullOffset);
- geometricConstraintData3->SetCurvatureDerivative(nullOffset);
- geometricConstraintData3->SetHasSymmetricModelingConstraint(false);
- Features::GeometricConstraintData *geometricConstraintData4;
- geometricConstraintData4 = studioSplineBuilder1->ConstraintManager()->CreateGeometricConstraintData();
- geometricConstraintData4->SetPoint(point4);
- geometricConstraintData4->SetAutomaticConstraintDirection(Features::GeometricConstraintData::ParameterDirectionIso);
- geometricConstraintData4->SetAutomaticConstraintType(Features::GeometricConstraintData::AutoConstraintTypeNone);
- geometricConstraintData4->SetTangentDirection(nullDirection);
- geometricConstraintData4->SetTangentMagnitude(nullScalar);
- geometricConstraintData4->SetCurvature(nullOffset);
- geometricConstraintData4->SetCurvatureDerivative(nullOffset);
- geometricConstraintData4->SetHasSymmetricModelingConstraint(false);
- std::vector<Features::GeometricConstraintData *> constraints1(4);
- constraints1[0] = geometricConstraintData1;
- constraints1[1] = geometricConstraintData2;
- constraints1[2] = geometricConstraintData3;
- constraints1[3] = geometricConstraintData4;
- studioSplineBuilder1->ConstraintManager()->SetContents(constraints1);
- Features::Feature *feature1;
- feature1 = studioSplineBuilder1->CommitFeature();
- Spline *spline1;
- spline1 = studioSplineBuilder1->Curve();
- studioSplineBuilder1->Destroy();
- /*Save*/
- NXOpen::PartSaveStatus *partSaveStatus;
- workPart->Save(NXOpen::Part::SaveComponentsTrue, NXOpen::Part::CloseAfterSaveTrue, &partSaveStatus);
- }
复制代码
|