|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 L5 k4 m/ E) Y$ _5 H
NX二次开发源码:通过选择点创建样条曲线
; I+ n( \0 S; D% }% k6 A0 |( ~. C2 @+ K% J
& w1 {" h/ E) c
3 ]# \0 _0 E3 `0 x9 K4 a% u) P1 A1 E) G- #include <uf_defs.h>- S# K- x5 o: L
- #include <uf.h>7 J" s8 r1 X( P; r; O0 X7 Y
- #include <uf_modl.h>
7 F% ?/ B3 c2 R$ i% G - #include <uf_object_types.h>" G; T; `% b8 v4 }
- #include <uf_ui.h>
q" U! Y# ~1 Z4 w" _" u+ E - #include <uf_modl.h>
/ y; o5 {, p3 L8 y% g - #include <<em>NXOpen</em>/NXException.hxx>
, K. a# W4 l2 V: U2 J- N - #include <<em>NXOpen</em>/Session.hxx>
, J' S; N9 h+ J - #include <<em>NXOpen</em>/Selection.hxx>
+ y/ v' ?+ ^* a$ c - #include <<em>NXOpen</em>/Builder.hxx>
" [" T7 D" u. a2 C+ D - #include <<em>NXOpen</em>/Features_Feature.hxx>1 P. p `9 o. O; y8 t
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
+ q6 {$ t. M& o) B0 q; t& V- C# n - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
1 `$ L! i7 _- d6 j) c( q - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>7 P( Q" A* z+ H1 L# v ~* v, m" S* [
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>7 K) _" V; |2 K7 x, L
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
! s. n; N: P: h% l. B - #include <<em>NXOpen</em>/Part.hxx>" ^, y- J" e& |$ x. n/ @2 H( N- Y
- #include <<em>NXOpen</em>/ParTCollection.hxx>$ R3 Z+ F( C2 K9 ]1 G
- #include <<em>NXOpen</em>/Point.hxx># W' B/ H$ m& G0 ^8 P! e
- #include <<em>NXOpen</em>/PointCollection.hxx>, l. M* B; Z% \& I8 l# s
- #include <<em>NXOpen</em>/NXString.hxx>$ w) y& R& ]7 d3 C) \
- #include <<em>NXOpen</em>/UI.hxx>' j( o3 e# G9 Q* I- \0 L# w9 D9 `
- #include <<em>NXOpen</em>/Spline.hxx>
$ k( J2 O0 w' |2 p$ P - #include <<em>NXOpen</em>/NXObjectManager.hxx>, Q( [/ B2 f. S% O+ j
9 s9 _/ W8 w2 j; f, q c9 |4 H- using namespace <em>NXOpen</em>;' C6 B7 b% r1 h
- using namespace std;
8 e/ Z) J4 v1 X7 w- X! J/ p
. L! l% i) a( | A( b+ Q$ O- extern "<em>C</em>" DllExport int ufusr_ask_unload()
; z4 ~/ M! `+ K+ D4 n* T0 ]" w - {. B: P! I) l3 b9 [" g! k# E
- return (int)Session::LibraryUnloadOptionImmediately;, {8 N7 B. `- ?; n" E
- }# q2 v4 d' L, C% t8 A
$ O+ h/ D! o" d e- static vector<Point *> selectPoints(NXString prompt)# U% C/ r7 ^" X8 W! {. \2 q
- {( f0 c( U/ j+ Z- K9 ?
- UI *ui = UI::GetUI();
, O: u/ S' s! ?8 d& R0 N) o - Selection *sm = ui->SelectionManager(); ?- o }) ~2 f$ r& F# d8 C
- std::vector<Selection::MaskTriple> mask(1);. F- Q' w3 C0 k1 R _/ R
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 @# b8 |8 c4 Z5 B/ V
- std::vector<NXObject *> objects;# }, S# U' x X6 M* J7 s
- * T: Z8 |2 i7 g" r, `
- sm->SelectObjects("Select Points", prompt,
1 u* z5 F7 {" t$ k$ D - Selection::SelectionScopeAnyInAssembly,
; y6 X. z5 I3 s5 ~2 B1 ` - Selection::SelectionActionClearAndEnableSpecific,
9 j3 n' y2 Y( g! O2 {" a# @ - false, false, mask, objects);0 h. `$ {" {% t2 K9 [8 c% ^' [1 x
# a' @, g$ e# ?* O v4 H- vector<Point *>selPoints(objects.size());! M6 r( D% h1 _1 ^1 r1 o8 q4 O4 r
- for (unsigned int ii = 0; ii < objects.size(); ii++)
' A, E2 R, I: M7 W& \/ z: r - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
7 W; z6 l0 n$ |' y
. s) ^6 Z+ G! p) b1 f( L- return selPoints;5 c$ n/ Q6 U% R) T/ H
- }( J4 w1 r0 H( E7 L& h
- - H" T8 O% Y5 \( L' |
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)* D1 O) N n5 |5 ]
- {
" N' v% L# x) E9 a4 B0 g - Session *theSession = Session::GetSession();
- l3 i9 n) f0 S+ a7 `, T - Part *workPart(theSession->Parts()->Work());
* s& O2 T# S: e& q4 ?2 { - # o2 ~6 C7 v3 a& k( O
- Session::UndoMarkId markId1;/ k, J1 C" U! J3 p
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
. @" u% g/ ^9 Q8 [8 q - "Studio Spline Thru Points");
9 I! A1 S0 `8 Y- o - 8 \6 h# j! }" {1 D! C
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 f- s: R* ~" _6 \- d
- $ e) x' Y5 B; _0 H/ I
- Features::StudioSplineBuilder *studioSplineBuilder1;2 m6 N% E0 P$ B) b4 ?
- studioSplineBuilder1 = workPart->Features()->7 a/ G2 n3 {7 a# E
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
+ t9 N e/ r1 F# g+ k& O& p1 f - studioSplineBuilder1->SetAssociative(true);( p0 E0 d6 z% Q# M6 z
- studioSplineBuilder1->
2 S8 ^ O! ]& b4 {0 E$ w8 d; i - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain); O1 c- i/ c( s0 E, |5 {
- studioSplineBuilder1->
! j8 @6 d9 p" X - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
- u! b% U0 W8 I, k }; u1 h - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! R* |- p2 E& V7 K
- studioSplineBuilder1->SetPeriodic(false);
9 @* F i1 U2 p- G - studioSplineBuilder1->! y }5 A$ i* w0 r/ q( Z" |
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
4 h, G0 S8 d4 B' |; o( K) Q" Z9 E - std::vector<double> knots1(0);9 c) b$ g5 a0 X5 {" f" a9 K5 w
- studioSplineBuilder1->SetKnots(knots1);
8 {% b* a# m4 t4 N7 J9 \7 T - std::vector<double> parameters1(0);: N1 _3 B8 K& W. O
- studioSplineBuilder1->SetParameters(parameters1);
/ c; y8 V- h2 e - Direction *nullDirection(NULL);% @' n4 e& Z# z" j8 h
- Scalar *nullScalar(NULL);, l# W" H2 S" |* o, ?, ]7 I
- Offset *nullOffset(NULL);, a/ }5 N& f$ X% P$ H
4 ^/ Z. c& z4 M2 M, n- std::vector<Features::GeometricConstraintData *>4 y. X9 U0 Z. H4 i* _/ L/ a! G
- geometricConstraintData(thePoints.size());, `* N5 G' T8 z I
- 9 e' E, E" m1 M8 }( n
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)* h: c) q) k7 b8 J7 n: }
- {& X9 D) I' P8 k7 ]% v
- geometricConstraintData[ii] = studioSplineBuilder1->
. V5 z, |1 ~, i" z( w3 a3 D - ConstraintManager()->CreateGeometricConstraintData();
2 ?- ^3 z' B# Y! T5 r$ ? - geometricConstraintData[ii]->SetPoint(thePoints[ii]);4 T! s+ b3 |! q
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(' d( l+ }6 j% D7 @& h- G
- Features::GeometricConstraintData::ParameterDirectionIso);
0 [* f% U+ W+ V2 U" J' Y! l' ] - geometricConstraintData[ii]->SetAutomaticConstraintType(
2 ?& ~0 c2 |( y5 j7 S7 r4 z - Features::GeometricConstraintData::AutoConstraintTypeNone);0 B/ [5 B( G) W) x; E' Z% ]
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
3 k1 c# d6 B+ x - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
9 s4 `0 D% n& ]' R9 g' t3 Q+ E H - geometricConstraintData[ii]->SetCurvature(nullOffset);
1 X1 }9 B+ z3 l8 Y [9 C y! _ - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 S3 Y$ [* S5 K
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 F% a: V8 _" ?5 n4 _
- }3 u5 x' B- F' c
- , M" m5 O3 R$ P( f9 A7 \
- studioSplineBuilder1->ConstraintManager()->SetContents(
' t6 k* b* v8 B6 L" `& x - geometricConstraintData);0 C# j+ n9 X' ~, d% y. h5 j5 B2 j
3 O' g0 i) W/ ~- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ K+ t6 u& p/ q$ }' [* z. l
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();7 |6 n( r1 j+ s7 h' C6 u0 L
2 [+ S& b6 P& f- studioSplineBuilder1->Destroy();# B: u) P& t, h9 \1 ~/ Z0 k
- 3 r# l" N& T$ \! p. L7 q
- return theSpline;9 {! q) B& L) {
- }
: X" v, C5 V0 Q
5 g, `) s: w% ]1 k9 j- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)& W$ P+ W9 O+ w6 G
- {
1 V9 [, J5 E6 ~* y$ r - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");! ?8 H% F1 T/ k: f2 m. Y
- if (!thePoints.size()) return;9 W7 R# Y6 E& L' j `4 F- \
- 3 M! R! p8 Y! H5 w: q
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
8 P! r2 l9 f6 k+ c8 J# L' ~ - 3 d! l1 ]5 r. W# V2 p8 D
- if (theSpline)
9 h6 V' r) X" q6 S) Q" X - {8 P$ R3 M' v% z |" p
- theSpline->Highlight();+ [+ n7 c6 z' w3 u E, l
- uc1601("Studio Spline Created Thru Points", TRUE);
$ D' [. g' N j' I - theSpline->Unhighlight();
( z8 H. }0 ^' Z! u! y - }
5 K: |( K" X6 F/ Q& n( k3 Q0 ~* r m - }
$ ~3 W! n' F& A( ^ - <p> </p>
复制代码
* y5 ]5 X9 i- ~# Z6 C' e |
|