NX二次开发源码: 通过点创建样条曲线
NX二次开发源码: 通过点创建样条曲线#include <uf_defs.h>
#include <uf.h>
#include <uf_modl.h>
#include <uf_object_types.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Selection.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/Point.hxx>
#include <NXOpen/PointCollection.hxx>
#include <NXOpen/NXString.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/Spline.hxx>
#include <NXOpen/NXObjectManager.hxx>
using namespace NXOpen;
using namespace std;
extern "C" DllExport int ufusr_ask_unload()
{
return (int)Session::LibraryUnloadOptionImmediately;
}
static vector<Point *> selectPoints(NXString prompt)
{
UI *ui = UI::GetUI();
Selection *sm = ui->SelectionManager();
std::vector<Selection::MaskTriple> mask(1);
mask = Selection::MaskTriple(UF_point_type, 0, 0);
std::vector<NXObject *> objects;
sm->SelectObjects("Select Points", prompt,
Selection::SelectionScopeAnyInAssembly,
Selection::SelectionActionClearAndEnableSpecific,
false, false, mask, objects);
vector<Point *>selPoints(objects.size());
for (unsigned int ii = 0; ii < objects.size(); ii++)
selPoints = dynamic_cast<Point *>(objects);
return selPoints;
}
static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
{
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Session::UndoMarkId markId1;
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
"Studio Spline Thru Points");
Features::StudioSpline *nullFeatures_StudioSpline(NULL);
Features::StudioSplineBuilder *studioSplineBuilder1;
studioSplineBuilder1 = workPart->Features()->
CreateStudioSplineBuilder(nullFeatures_StudioSpline);
studioSplineBuilder1->SetAssociative(true);
studioSplineBuilder1->
SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
studioSplineBuilder1->
SetSplineMethod(Features::StudioSplineBuilder::MethodThroughPoints);
studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
studioSplineBuilder1->SetPeriodic(false);
studioSplineBuilder1->
SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
std::vector<double> knots1(0);
studioSplineBuilder1->SetKnots(knots1);
std::vector<double> parameters1(0);
studioSplineBuilder1->SetParameters(parameters1);
Direction *nullDirection(NULL);
Scalar *nullScalar(NULL);
Offset *nullOffset(NULL);
std::vector<Features::GeometricConstraintData *>
geometricConstraintData(thePoints.size());
for (unsigned int ii = 0; ii < thePoints.size(); ii++)
{
geometricConstraintData = studioSplineBuilder1->
ConstraintManager()->CreateGeometricConstraintData();
geometricConstraintData->SetPoint(thePoints);
geometricConstraintData->SetAutomaticConstraintDirection(
Features::GeometricConstraintData::ParameterDirectionIso);
geometricConstraintData->SetAutomaticConstraintType(
Features::GeometricConstraintData::AutoConstraintTypeNone);
geometricConstraintData->SetTangentDirection(nullDirection);
geometricConstraintData->SetTangentMagnitude(nullScalar);
geometricConstraintData->SetCurvature(nullOffset);
geometricConstraintData->SetCurvatureDerivative(nullOffset);
geometricConstraintData->SetHasSymmetricModelingConstraint(false);
}
studioSplineBuilder1->ConstraintManager()->SetContents(
geometricConstraintData);
Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
Spline *theSpline = studioSplineBuilder1->Curve();
studioSplineBuilder1->Destroy();
return theSpline;
}
extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
{
std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
if (!thePoints.size()) return;
Spline *theSpline = createStudioSplineThruPoints(thePoints);
if (theSpline)
{
theSpline->Highlight();
uc1601("Studio Spline Created Thru Points", TRUE);
theSpline->Unhighlight();
}
}
页:
[1]