|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
; b) K& m1 a s1 p- #include <uf_defs.h>- }8 o, `0 q# E8 C; l% |+ n- e9 x0 j" c
- #include <uf.h>
& v0 |; q; H6 g8 U& e$ j0 [ - #include <uf_modl.h>
! i' l$ \" R; u - #include <uf_object_types.h># T) r! W. Y# e6 S- r
- #include <uf_ui.h>
. F: `" Z. @$ \: u- u, j6 q$ N - #include <uf_modl.h>
+ h7 ^( | c" U4 D6 g: g- n - #include <NXOpen/NXException.hxx>
( M% J" u3 o+ u$ v. O - #include <NXOpen/Session.hxx>
1 ]0 @( C3 j# N g& x1 N" { - #include <NXOpen/Selection.hxx>* P! D$ C) B: B
- #include <NXOpen/Builder.hxx># K8 @* u, c# s. c. c: x: H9 C# d, |
- #include <NXOpen/Features_Feature.hxx>
2 Z; @; @/ z3 Q0 v: ? - #include <NXOpen/Features_FeatureBuilder.hxx>
' u" E9 o/ Q9 s: ]3 s* i - #include <NXOpen/Features_FeatureCollection.hxx>
" [( k) e3 o6 Z/ i - #include <NXOpen/Features_GeometricConstraintData.hxx>7 K, t2 i3 l) ]# x Y4 H
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
4 H2 }# c% \& N - #include <NXOpen/Features_StudioSplineBuilder.hxx>
' y! j; k- u. } - #include <NXOpen/Part.hxx>. { E( x, A5 `7 Y0 T& r
- #include <NXOpen/ParTCollection.hxx>
3 Y: g3 K/ S5 k% ^/ S - #include <NXOpen/Point.hxx>* d4 X. I5 E, ^% q2 l
- #include <NXOpen/PointCollection.hxx>
6 _4 \' g3 C2 x4 e |) _7 ] - #include <NXOpen/NXString.hxx>. d9 K1 ]' b0 {, v. e
- #include <NXOpen/UI.hxx>7 P$ u. |7 Y+ f Y# M
- #include <NXOpen/Spline.hxx>
5 u d& H# \2 ^0 Q* A3 K3 T# V - #include <NXOpen/NXObjectManager.hxx>3 _' y% R) ~# W% V
- 2 A" v, T; C# }5 l3 E' _
- using namespace NXOpen;/ m2 s% Z# @# G( ^( e0 M# R
- using namespace std;6 \+ e5 Z8 T9 f3 L: X
( Q. S, d D4 t1 I4 X+ }, ^- extern "C" DllExport int ufusr_ask_unload()
6 K8 D# @# R# W0 H- @8 Q8 m" ^" x - {: ?8 h; q# s ~0 \+ q, s0 h' x
- return (int)Session::LibraryUnloadOptionImmediately;5 }3 j1 v: U' [7 @0 L
- }+ J& J) ]4 D* ~3 x( L: u
- T8 d8 d! c4 N
- static vector<Point *> selectPoints(NXString prompt)5 r0 u. C( l& S( h& g
- {
7 U t" m; v; z' c$ C1 d ` - UI *ui = UI::GetUI();
7 H' d. @2 J2 P: W! W _ - Selection *sm = ui->SelectionManager();8 A5 x" T" o% S4 K2 `5 G/ v% X( H
- std::vector<Selection::MaskTriple> mask(1);
9 W& ~8 \) h! Y4 u9 l! Z* q9 s - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- \: Y+ ]) s2 C9 T7 x" |
- std::vector<NXObject *> objects;2 V }+ y `9 w# @- k0 I; w
- 8 w u+ r0 `% q8 U, X, {7 ]% o1 U
- sm->SelectObjects("Select Points", prompt,; I! B# X8 w& ]- ^6 R
- Selection::SelectionScopeAnyInAssembly,
4 s2 R4 O; N( w( y - Selection::SelectionActionClearAndEnableSpecific,( H E6 W) p" R% Y
- false, false, mask, objects);' S5 |3 m/ t3 z, ?
8 \$ ~2 ]# V4 ]+ N( A" B- vector<Point *>selPoints(objects.size());# m- a! k W0 U4 ~" L8 M( O; w0 F8 ^1 q1 i
- for (unsigned int ii = 0; ii < objects.size(); ii++)
; P8 k, K. y5 ^- }, B - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
3 J. ~9 r9 |+ X5 F" T$ s' p - # D# o7 o& l h, ^, L
- return selPoints;/ a' U% r A" b
- }
" n" v7 b c4 `) b5 u2 A - + b* W# {! ^3 A/ G+ D- v
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)& `+ \* c, v9 B1 j2 ?1 o
- {( L9 ~! Y5 y$ G
- Session *theSession = Session::GetSession();
6 u" w2 D' B( Z8 x: \+ C - Part *workPart(theSession->Parts()->Work());5 a6 V1 D# L2 n4 l4 A
- , R. [- x3 u5 i& V9 g: c7 |4 F9 a
- Session::UndoMarkId markId1;
9 i n: M4 ]9 M! O9 B - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible," `- u, O0 L# e5 u1 G8 K
- "Studio Spline Thru Points"); q' g/ B& y, ^! V( {1 K
- * l; Y7 i" I( o1 C
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
/ Z- ?7 O+ L+ d- y( G+ N1 Z+ [ - ' A0 o$ X# v4 F- m6 G5 f a
- Features::StudioSplineBuilder *studioSplineBuilder1;
( b! R, j; L6 C: X+ g3 c m - studioSplineBuilder1 = workPart->Features()->
d+ I2 k2 F* O$ h- [/ X - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
# }4 d, n) g# R" V: C - studioSplineBuilder1->SetAssociative(true);
3 V. D- A d M5 L - studioSplineBuilder1->& ?& a3 ?. ~- p9 K( v
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);" z5 g. ~. ^$ D# B- _
- studioSplineBuilder1->
: ?1 S* C" ?: i. e5 v - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
3 H% M: H/ f2 {; T9 ]5 } - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
; [/ f. F* Z1 T0 w. _ - studioSplineBuilder1->SetPeriodic(false);8 a) Q' \5 i0 S. D5 D5 j5 q
- studioSplineBuilder1->
o5 `6 s* N H3 E7 s7 d" f - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ T+ x2 ?7 S5 C- H# e* }! A% b
- std::vector<double> knots1(0);
$ p( ]0 Y- U- [, s% i - studioSplineBuilder1->SetKnots(knots1);5 K9 D6 o9 k* o1 Q) Y" u8 Z5 s
- std::vector<double> parameters1(0);5 k& ~/ o# f0 ?- Y1 m1 C2 _
- studioSplineBuilder1->SetParameters(parameters1);) T% }& A5 S2 u, e
- Direction *nullDirection(NULL);
: Q' b+ A8 t3 ?+ n$ I8 { - Scalar *nullScalar(NULL);
3 g% D' K/ I$ R$ e - Offset *nullOffset(NULL);! T' ]2 V# U& {6 d
- , ^+ N' F. e4 e& I
- std::vector<Features::GeometricConstraintData *>. a8 S7 t1 T2 d: i
- geometricConstraintData(thePoints.size());
$ R) D0 e% w+ N0 U8 g. T) U. x! V9 E - - \( J3 i# x* r5 Y0 C% W
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
( Y. Q7 F4 [/ r" W9 O - {
1 y! I% s1 f9 P7 M - geometricConstraintData[ii] = studioSplineBuilder1->
' j5 d% M! D* J" y0 Y! n - ConstraintManager()->CreateGeometricConstraintData();
4 x) p( `2 }( D e - geometricConstraintData[ii]->SetPoint(thePoints[ii]);; ]# v" T7 O# }2 D' k9 N' H
- geometricConstraintData[ii]->SetAutomaticConstraintDirection( p0 d5 }$ C- R9 M
- Features::GeometricConstraintData::ParameterDirectionIso);
/ m% ^" B3 U* b5 n) m - geometricConstraintData[ii]->SetAutomaticConstraintType(
: C# @. a) S+ s* f* { - Features::GeometricConstraintData::AutoConstraintTypeNone);
3 S& }. d- x9 z" Q- w6 X$ | - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
* j$ t4 F/ y% X$ O$ O4 l - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);( z8 q; I v+ _+ o, }( i
- geometricConstraintData[ii]->SetCurvature(nullOffset);" g+ j& m4 I# w3 o7 ?
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- d8 v& k% l# p) Z7 T8 l+ @- @
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);; c. F3 }& B1 |# E- P
- }
) n( W5 C; c3 W/ s- ]
# S8 B' Y# Q6 j0 \8 `" c' Y- studioSplineBuilder1->ConstraintManager()->SetContents(2 U1 q r7 p+ H7 W9 Z9 w" }
- geometricConstraintData);9 R, C( d. G$ C+ r' I4 K# N J
0 C" w+ _8 r& L! [& d" T& ^' d- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
% a- t6 B- P/ I" y' b - Spline *theSpline = studioSplineBuilder1->Curve();- S% o1 J9 a* D0 G1 T' P
- 4 w7 p, X" C6 [$ Q; y
- studioSplineBuilder1->Destroy();
2 B% a% H5 L+ D* ]+ `6 Y( E - 0 C+ w! C+ x9 O
- return theSpline;% x; f5 ^ x; U8 B, J
- }4 b) Y! ~. U1 I4 v% i% R7 k6 f
- . z1 A) X4 V- H* o, i( N
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)( P' F0 d7 q# {/ D2 e( T
- {2 S; ^( P$ z7 @
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
3 N& o6 s2 }# k U" U - if (!thePoints.size()) return;1 E6 N9 \# I5 r* ~1 l
3 `, ^9 \/ t; p0 P( m, e- Spline *theSpline = createStudioSplineThruPoints(thePoints);: n5 [! e3 h# X0 P9 E" Y
7 C0 b$ T5 D1 L d$ F- if (theSpline)" r) K; r4 K$ P1 a; F1 p
- {
0 ]% K( ~, X2 I$ t( Z% T& r - theSpline->Highlight();
2 ^" R: B. [7 u* C6 h3 d - uc1601("Studio Spline Created Thru Points", TRUE);
/ X4 c* P/ g$ A- Z1 \$ Z" C - theSpline->Unhighlight();
) ^* N1 B( o6 A% q - }4 V( t* |+ V3 V" S+ {2 g& l3 r; [
- }
: @+ G# ]$ J5 B: R. w" Z! o8 j
复制代码
0 W( _. I% l, [* I1 w, h
, t4 a% j( b% R4 j
0 e/ P% @! K/ V+ x! C: Y2 H |
|