|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
+ i8 D( b# z- x; F1 e7 ^# E- #include <uf_defs.h>. J# [- U& J! b/ ]: B
- #include <uf.h>
9 e# ?) r6 H ~! @$ B - #include <uf_modl.h>
) v* b8 W# ? S, |( G1 W& A - #include <uf_object_types.h>
' P7 t( I/ g1 Q! L5 I - #include <uf_ui.h>
1 \* a; \* S% m. a( S( | - #include <uf_modl.h>: c$ h8 O: j- y" M
- #include <NXOpen/NXException.hxx>
. e: G; [" U T G! }9 \/ E' T - #include <NXOpen/Session.hxx>$ _# f/ q- V! Z1 Z, D. ]/ z
- #include <NXOpen/Selection.hxx>
; x! ?! `0 i4 f9 ^8 D5 @ - #include <NXOpen/Builder.hxx>
' m! n9 d# m* N# f - #include <NXOpen/Features_Feature.hxx>
2 q) E6 F3 _& [& B8 R6 J - #include <NXOpen/Features_FeatureBuilder.hxx>
4 L2 e# G/ m, R; o. l+ E - #include <NXOpen/Features_FeatureCollection.hxx>
" w) [3 B3 Z; y4 l! k/ A" K1 B - #include <NXOpen/Features_GeometricConstraintData.hxx>
1 \( J2 A# Q5 ]0 [# h - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
4 |- m5 ?: M# E& K: z9 {) \* a - #include <NXOpen/Features_StudioSplineBuilder.hxx>4 e3 |3 [3 M' A& M% Z4 r) U, ]
- #include <NXOpen/Part.hxx>$ r( p% u. S \4 j. p- P3 h, e
- #include <NXOpen/ParTCollection.hxx>% B* R5 b& s( N. H# X
- #include <NXOpen/Point.hxx>
& K) ^* C- K1 D. `- \9 N - #include <NXOpen/PointCollection.hxx>
& R @, k- U8 I7 H- z6 W) P$ H+ n - #include <NXOpen/NXString.hxx>
; v; H& A A) ]. w. u! S - #include <NXOpen/UI.hxx>
U' S: C3 D2 I' y) h - #include <NXOpen/Spline.hxx>
& b+ T# T8 V7 b) S/ y7 ?6 [1 b - #include <NXOpen/NXObjectManager.hxx>
1 g( l" U9 M% ~ - X% J4 B! x9 @% V" n% ~
- using namespace NXOpen;# S& ~5 x# l6 k P
- using namespace std;
2 g9 [, z# b R
( h% e9 k% S8 i: C- extern "C" DllExport int ufusr_ask_unload()9 s @8 D3 W: n9 n: _( z
- {
. J2 A- w4 C4 M9 o8 G9 l0 b5 I2 E" G2 q1 p - return (int)Session::LibraryUnloadOptionImmediately;
0 [9 \) k7 Q. _ - }
& K$ m, r5 c8 _. c3 g - " O$ L" `4 E: n+ S9 D2 ?; S
- static vector<Point *> selectPoints(NXString prompt)
' J* i. ]' Q. n; g5 k" _ - {
& y8 f5 c6 N' Z - UI *ui = UI::GetUI();
% r$ }% C. @; @5 q - Selection *sm = ui->SelectionManager();
' f9 I0 |/ h0 E( O - std::vector<Selection::MaskTriple> mask(1);# l( }4 W: A$ @: K# a
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
% N }$ Q+ h* [, l. r( ?3 m' A! v - std::vector<NXObject *> objects;
# }. e+ B3 ?" ]5 Z4 |
* p! R: s: @: p& K9 [- sm->SelectObjects("Select Points", prompt,* I# X* X( h" `! ~
- Selection::SelectionScopeAnyInAssembly,6 d: t7 Y% l$ I- E, ^* G
- Selection::SelectionActionClearAndEnableSpecific,
% J$ Y: G' Y; b0 w - false, false, mask, objects);! U7 U% F6 J4 p; X* Z8 I/ M
, c' ]" X8 W6 @- vector<Point *>selPoints(objects.size());% I- {7 Q; @, P9 |( ]2 x; S
- for (unsigned int ii = 0; ii < objects.size(); ii++)
/ T3 r4 P# K. T# ? - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);. y- ?& a" M9 v9 m
- " a6 s* U* ~1 D* M
- return selPoints;
) F3 ]$ W, U! s/ W' E) q! z/ F* q - }
3 i# V, I% ^4 n2 x) ~
6 v% e0 d9 B+ T1 _- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
' X. {8 b% D$ U: X4 }6 y - {- P( [: t$ P! S2 ^- |
- Session *theSession = Session::GetSession();
- z1 [. `6 {5 X: p+ L& O0 y - Part *workPart(theSession->Parts()->Work());1 H3 ~) S; S$ f
- 9 [2 }' f6 k+ p# |
- Session::UndoMarkId markId1;8 u9 m z( I# |- }& k' k/ d! F
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
# X8 o0 T% \! y3 o+ a8 g' S$ f - "Studio Spline Thru Points");+ _8 k% s, i( V' _$ L
0 Z# K" T5 F { ]) f- Features::StudioSpline *nullFeatures_StudioSpline(NULL);& w) @' X7 [/ a
- / Z4 a: b1 a$ s7 _( {% f- b
- Features::StudioSplineBuilder *studioSplineBuilder1;8 }" ] ^* p4 I" C# r0 C' p6 e
- studioSplineBuilder1 = workPart->Features()->1 X& y ]% V5 L
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 [/ R" x0 ]- [! M( G9 m
- studioSplineBuilder1->SetAssociative(true);
$ |" E! Q+ u& S; I( } - studioSplineBuilder1->
. g. L( j# F" e) X - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);% {5 [; x' a) v r! i5 v2 p
- studioSplineBuilder1->
. }' }8 S6 s u# G) N2 {2 ?* { - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 d4 j9 S" G, f
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
3 K6 J5 O a2 ]- s, E - studioSplineBuilder1->SetPeriodic(false);
2 b. ^7 n: f8 e. R; j+ r - studioSplineBuilder1-># Z, A3 [, _3 Y9 d6 w
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
% ^# L: _% ~7 l O- c - std::vector<double> knots1(0);
8 z; f& e- k4 h( v/ X" A - studioSplineBuilder1->SetKnots(knots1);3 ~/ V7 W6 R9 l7 I+ F1 W
- std::vector<double> parameters1(0);& M) a0 S1 D1 [% j
- studioSplineBuilder1->SetParameters(parameters1);
2 a0 w3 V* e9 P2 Q; e1 {* @ - Direction *nullDirection(NULL);
# j5 l: \* V1 y( z o: G% y9 E - Scalar *nullScalar(NULL);8 q! e, |: B. p/ _8 D
- Offset *nullOffset(NULL);+ q) B( i [' ?& g$ A
1 X4 {8 D/ B3 B) ]- std::vector<Features::GeometricConstraintData *>$ c7 H; d: h4 l+ N
- geometricConstraintData(thePoints.size());
1 I ~) e7 [3 `2 r2 R! O - - ?5 |! I) M: m3 o6 q# i3 |0 S
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
8 Q" b5 w2 j; D, Y0 Q, G N9 F - {3 M& c0 r1 m: a# ?) L
- geometricConstraintData[ii] = studioSplineBuilder1->
; F" n$ Y1 g" ~7 ]& |7 ^5 \ - ConstraintManager()->CreateGeometricConstraintData();
. {" t; m: ?. `* `9 f7 O% l$ X } C - geometricConstraintData[ii]->SetPoint(thePoints[ii]);. @) B8 P) j% \! Z i$ G1 j$ m3 l
- geometricConstraintData[ii]->SetAutomaticConstraintDirection() r& V8 C& v8 m) g, w
- Features::GeometricConstraintData::ParameterDirectionIso);
# k$ E" i) C! b$ x9 ~* G, | - geometricConstraintData[ii]->SetAutomaticConstraintType(
( `- M/ X& X n - Features::GeometricConstraintData::AutoConstraintTypeNone);# A: z; b. C: H
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);8 Z5 e; `2 H. U4 K1 x
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);# c e# D& ~' G: T* K+ v! j
- geometricConstraintData[ii]->SetCurvature(nullOffset);
/ F* p% h( O' M4 z) P) S - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
g) R+ R/ |- a; |% B0 Y - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
$ p% I! M4 C* Q* e% z/ t! C3 j - }3 M( n0 v k, i9 d9 [
! u: t: |# O8 O; v! M! i. R- studioSplineBuilder1->ConstraintManager()->SetContents(
% [+ V7 Q& q2 h) V+ F - geometricConstraintData);
4 Y5 {* t" e5 N: ~: J$ ]
' a# V( k. v7 C: }7 F1 ~( j! I& G- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
1 Q1 Z1 _8 O" c# G1 M - Spline *theSpline = studioSplineBuilder1->Curve();) v; b" Q0 U" M
- 1 Z8 v) R$ i0 K8 ]9 ]7 K' P& Q
- studioSplineBuilder1->Destroy();& s7 p2 J4 x ?$ J2 o* v$ h( q
0 I1 p- A6 x% _% U- return theSpline;" {) M& M6 ?) J% w7 r6 [8 M
- }
, [3 ^. l. U3 J9 L
0 X- k0 D' u9 z9 L- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)7 l8 x% ?. j5 q
- {2 n E( u8 f% @/ v; z9 Q' ~
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
- W9 m- y+ U$ J/ B - if (!thePoints.size()) return;
. y0 X! P" Y1 B. n) @; P. Y - 4 e5 {5 s8 C5 Z
- Spline *theSpline = createStudioSplineThruPoints(thePoints);- w0 x' {! W1 h
$ T- v2 Y5 K& Q- if (theSpline)! j# o- R m; c" R2 h8 E( f
- {
( E* E% ^1 W0 m- y - theSpline->Highlight();! ~, `3 c8 k$ I ?0 w
- uc1601("Studio Spline Created Thru Points", TRUE);
1 y: y9 O7 t$ q - theSpline->Unhighlight();
! \# y* y# R6 F/ R4 {: l* w# b - }" O; H% J+ w6 B$ \
- }9 z& H3 A4 @2 b+ P2 {! h
复制代码
4 q* O5 k4 A O& Y0 E4 {6 R x+ x. v3 \. q! T. t
) V; y( k& W/ c1 n+ k3 L6 v( ~ |
|