|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
4 J) c1 d- c& Y" x$ |" f- D' q1 W8 cNX二次开发源码:通过选择点创建样条曲线2 i0 f& K8 _" z/ }/ L R/ x" ]
6 v' u1 A9 } R4 h4 o- A
6 ?( a: W/ l# U; B" J7 b4 g" @- 0 @$ X4 r0 K( ]) F3 N$ s+ y
- #include <uf_defs.h>6 @; s% j* V9 }/ a/ l
- #include <uf.h>
4 p' M8 ?- [) X" J0 M) Z' R8 r - #include <uf_modl.h>
0 O+ g; @* j, m) O+ s4 _6 K - #include <uf_object_types.h>
- N- @( ]3 r+ S' _/ r$ e3 X - #include <uf_ui.h>
2 l' J" H- H6 \6 k$ x - #include <uf_modl.h>
2 r6 J. h* B' A& a l, ~+ M. U6 w - #include <<em>NXOpen</em>/NXException.hxx>* V2 U- r; t. ?' ~( C1 D, g2 _
- #include <<em>NXOpen</em>/Session.hxx>
" s# F) w2 v2 D% h - #include <<em>NXOpen</em>/Selection.hxx>: V* I; u, | d
- #include <<em>NXOpen</em>/Builder.hxx> m E( q7 S7 E. B7 i1 V% O# m3 s
- #include <<em>NXOpen</em>/Features_Feature.hxx>
/ h! z/ e6 L( h# O - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>9 O/ {# N( H6 L9 x- _4 o: M
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
1 `/ S( T, L' q' w - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
& n- U; t; L4 O7 a! b2 i - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
9 r1 p9 d: C0 |0 n - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>8 O7 {: @1 A: o9 I. q# @
- #include <<em>NXOpen</em>/Part.hxx>
% W/ J$ c) E( F# s1 U W - #include <<em>NXOpen</em>/ParTCollection.hxx>6 T+ T! T& K- n! {$ k3 ]5 }5 x
- #include <<em>NXOpen</em>/Point.hxx>% x" o5 S7 k/ e' d6 z t* }
- #include <<em>NXOpen</em>/PointCollection.hxx>+ t- k. j$ {7 N5 N3 ^9 y% G4 @
- #include <<em>NXOpen</em>/NXString.hxx>
- A8 O0 D* U2 @2 K - #include <<em>NXOpen</em>/UI.hxx>
2 {# C, m- j; M# v8 ~/ h& ?5 y - #include <<em>NXOpen</em>/Spline.hxx>
' ?6 C' j, W+ a( J3 b. | - #include <<em>NXOpen</em>/NXObjectManager.hxx>
0 n4 D# x9 ^( Z9 t
3 h! y" n; v' q3 s. Q- Q- using namespace <em>NXOpen</em>;
; q5 {, S1 m2 D+ |6 F9 { - using namespace std; _" y: x) {7 s- k$ c
- , W: @% o! \0 I0 X
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
+ A$ p, B" K+ C( s1 m- f) g8 u - {
& A. K) e5 [! l8 A - return (int)Session::LibraryUnloadOptionImmediately;
3 w3 ^8 o. v6 r7 Y - }1 Z, {9 O n* D
& `+ x5 b+ t. b" x+ g, a' R( Y- static vector<Point *> selectPoints(NXString prompt)7 L' d' |0 }: d6 |; f: s2 {
- {
' o: X7 D/ o' o - UI *ui = UI::GetUI();
% w$ L# Q1 n1 s6 q8 P, G/ i/ j - Selection *sm = ui->SelectionManager();6 @5 o4 c2 Q# ~- N9 r. `
- std::vector<Selection::MaskTriple> mask(1);( u$ R7 l* ?0 V6 w1 M
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);( S1 m# e( G5 D% K: \, d/ v& G
- std::vector<NXObject *> objects;
. S0 F/ S; g5 D2 I9 I - 9 w. d e! `9 \3 U! \0 `
- sm->SelectObjects("Select Points", prompt,
Z) J$ Z4 k6 X8 j5 b6 E - Selection::SelectionScopeAnyInAssembly,$ `" @; `+ I R7 L `$ @" L" U
- Selection::SelectionActionClearAndEnableSpecific,
2 A+ K! K+ Q" [0 n( D1 M) A5 x0 j4 q - false, false, mask, objects);1 N0 N8 D! t# e* t& Y# P
- 3 F% f/ J O8 R
- vector<Point *>selPoints(objects.size());
* _* h( C* @' x/ {6 Q - for (unsigned int ii = 0; ii < objects.size(); ii++)
3 d# D0 Q8 h% G - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
: N: g9 B2 Y! ?2 S6 e/ j - 4 f. S' J2 X1 P: X
- return selPoints;
$ H0 i: b% _1 C; s" b - }
* T4 G% s6 m4 T7 N W$ Z
* }1 m4 ]& C5 x+ q- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
5 B0 g# b5 \3 o- A9 J - {- t- r- N7 m! b) g% U9 u$ l
- Session *theSession = Session::GetSession();
: O/ Q1 a" T4 Z% W1 y - Part *workPart(theSession->Parts()->Work());! d5 _6 L9 u4 b, u( B& b
- , h5 \8 t2 K9 U% A
- Session::UndoMarkId markId1;
8 p; d2 F& u- m- k& y' S# c0 T( m3 p - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,6 L F# @- E# S1 ]6 j. B
- "Studio Spline Thru Points");
) z6 y0 _0 ^; b: d. R: d0 H! b2 X - 3 x7 H& d' C) {% J" _: t
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
; k/ {, w8 A5 z7 H3 B+ ?
; k$ E F, C- c# O2 b: [0 H1 k- Features::StudioSplineBuilder *studioSplineBuilder1;
* Y( H7 S. q! Z. s8 w& g' I0 @6 x - studioSplineBuilder1 = workPart->Features()->9 o$ t) ^; G" a2 w) l! ` y) V
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
! V+ V" R1 O7 o# @4 Y! D$ T - studioSplineBuilder1->SetAssociative(true);
6 D, B7 x5 h- P1 K - studioSplineBuilder1->/ |; s0 y" l! F$ h
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
9 R! @3 R6 W! d4 o6 x' X" i' G7 ^ - studioSplineBuilder1->4 \* f1 l) X/ N( ?
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
0 W# ]7 C! ?9 r: K+ w - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);8 {, n7 a, O T4 h1 @# m
- studioSplineBuilder1->SetPeriodic(false);. n8 u i( C* @* z K& y! }' ?
- studioSplineBuilder1->
$ ?, Y/ X) F t# X - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# P7 N$ |, q* U& b+ x! V( j/ H) L
- std::vector<double> knots1(0);
3 T' d- {. i, ~+ q1 Q' | - studioSplineBuilder1->SetKnots(knots1);9 N! H% V. F! ^& z( }
- std::vector<double> parameters1(0);
- w; k* _+ T, q( z, \ - studioSplineBuilder1->SetParameters(parameters1);
9 x' z) w* w( O# Z S9 M% U+ U' p - Direction *nullDirection(NULL);6 G) w+ b3 c' k$ I C% d9 j
- Scalar *nullScalar(NULL);9 q3 {2 s! N t; B, I I0 p+ W
- Offset *nullOffset(NULL);
% A {0 v: v" Q D5 F1 M
" W7 E) _2 ~; L- X' h; B3 t- std::vector<Features::GeometricConstraintData *>
+ {6 n# W/ k0 d$ D6 h# U - geometricConstraintData(thePoints.size());& D( O3 x0 |- A* C
- 9 m7 C2 `( N$ S, X& Z3 v
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
% F( y$ \& ^, { - {
' }2 u. u- |0 o" T) [3 U - geometricConstraintData[ii] = studioSplineBuilder1->
v" C' ~# [$ h3 ]- J% H - ConstraintManager()->CreateGeometricConstraintData();
, ~) \0 u: l: ?8 \ - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
3 R5 s: _. s+ b' r7 |$ h! a" J& d - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
: k4 Q. `/ m1 t% ]4 \) w - Features::GeometricConstraintData::ParameterDirectionIso);# |+ A0 _) I% x& F
- geometricConstraintData[ii]->SetAutomaticConstraintType(
0 J3 R/ p' k; M, e6 }& y F - Features::GeometricConstraintData::AutoConstraintTypeNone);
$ `, w8 Y! t7 u. L3 } - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
6 ]7 J0 \# z5 k v: c5 G7 A - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);( V) p/ C7 A% Z1 c
- geometricConstraintData[ii]->SetCurvature(nullOffset);7 a3 |/ G# }, p7 h. U I! y
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset); `( F' p% m4 ? k4 h2 }; A3 c+ g
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
% B, ?5 d% L2 F R) M - }) m. O- {" m) t. T, \( M
- $ R E# h3 G5 {& K1 `
- studioSplineBuilder1->ConstraintManager()->SetContents(+ {! e# H! ]% i; D0 {. ~* C. `* H- }
- geometricConstraintData);
" K4 N: A3 b/ z. J- D
5 l/ I- P8 r% t* i1 w- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();5 `% d" y* a$ l
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
) X6 [; ]/ [1 D - " E S/ b- T* t6 g
- studioSplineBuilder1->Destroy();
7 F/ d& q3 B$ X8 H* y8 q b2 y" ~
+ O5 G. C6 g9 Z# d$ R- return theSpline;
5 V9 @5 Z: X* |; e: | u+ M) j- Q - }4 d3 N- m! r7 U, {% W3 ?. k ^) f
- , @* z7 F1 m8 d$ }; O
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)1 ]4 G+ o. I. K \ F
- {
8 R9 [3 e( R' t! `# H h, m6 c - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
( c5 ^" r$ G7 V" ~8 C3 J6 v* _. A1 w - if (!thePoints.size()) return;
9 [2 s' c2 D/ | q; C8 Z y( v$ ~ - ' s+ a8 G7 V2 L
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
8 Y! f7 v' r. V - ! D$ R6 y# t5 E+ v2 I
- if (theSpline)
8 A5 b Z4 m0 t0 c: h4 `4 z - {9 }: E( }4 C( I! h6 Q" V! a
- theSpline->Highlight();1 K( C* ^$ _) a+ D( }
- uc1601("Studio Spline Created Thru Points", TRUE);
! P+ e( |7 b9 M- o- \( X - theSpline->Unhighlight();
) L" g$ U0 |6 G y4 C: O - }
+ M3 Z- W; ~ @& Q* A - }
! P* i( f6 b5 w* x, @ - <p> </p>
复制代码
: w4 D4 W0 x. @& f |
|