|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( [5 n# n9 s7 m- D7 vNX二次开发源码:通过选择点创建样条曲线
2 H% K! q/ O0 Q2 {2 q% z2 p; L0 _
% q, F8 s3 U% ]# k V9 x# V X$ G
- . o( `) |% w' ^4 B% @% n: o+ z4 J+ Z
- #include <uf_defs.h>
; J$ U4 f% C3 ^5 i - #include <uf.h>
. |+ G& p; F7 T. C - #include <uf_modl.h>
8 P7 Q' Q8 l* J5 t4 d0 R2 @0 H4 d2 ? - #include <uf_object_types.h>
& M V7 c9 O9 E3 r - #include <uf_ui.h>
. T/ m T5 z% v6 T; E3 ~ - #include <uf_modl.h>7 }* E7 f$ j1 `6 C5 K8 j! ?) B1 g
- #include <<em>NXOpen</em>/NXException.hxx>) L! p! t7 m: B. h
- #include <<em>NXOpen</em>/Session.hxx>0 Z7 h0 O Y y& ], A$ r! i
- #include <<em>NXOpen</em>/Selection.hxx>3 b% c, `7 s2 z' y; h
- #include <<em>NXOpen</em>/Builder.hxx>6 V; H- a* V& X' C# m: ?6 k! r
- #include <<em>NXOpen</em>/Features_Feature.hxx>. Q7 G1 m5 {+ q" A7 O
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
' ^* N2 J- U- d" F+ r9 v, Y) y - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>- W: w; w8 |- Z. }- i" C/ X( v& m
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>3 J9 c+ v, m: C9 R, n
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
( t6 N* E' z7 Q5 w7 a( c - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
, W5 D6 Z' m, t - #include <<em>NXOpen</em>/Part.hxx>
: I5 b1 {$ ]& X' X$ x$ f9 T - #include <<em>NXOpen</em>/ParTCollection.hxx>$ @; K# h& y9 G3 I
- #include <<em>NXOpen</em>/Point.hxx>
; m( I% D6 ]6 T" P4 \ - #include <<em>NXOpen</em>/PointCollection.hxx>
) w7 q0 E& \- w0 q5 L4 y' { - #include <<em>NXOpen</em>/NXString.hxx>
! Y" N: N+ G M$ O4 R7 c - #include <<em>NXOpen</em>/UI.hxx>$ O0 A& ~% B# D; a( w4 D3 F- U( a! x
- #include <<em>NXOpen</em>/Spline.hxx>
$ w0 R7 M$ Y( k9 i, l. U8 W! n% ^6 s - #include <<em>NXOpen</em>/NXObjectManager.hxx>- Q* e; i+ T& W! ~5 u% y1 n$ F
* e$ m! M, x, z O5 q- using namespace <em>NXOpen</em>;
' g. N* t0 k. H9 `# _ - using namespace std;
- I$ k+ B2 {. _- ~% n
8 K' a* K" w( ^) G7 R9 E- extern "<em>C</em>" DllExport int ufusr_ask_unload()0 m% Z- J2 G; k0 d
- {& V! y7 N @+ E3 O) `& w7 |! Y+ w
- return (int)Session::LibraryUnloadOptionImmediately;; _+ f5 H- ?3 C$ l. U! k) i6 g
- }
/ y" D R+ X& w) C - / v& E( ^) `! O+ G; X0 \, W0 m
- static vector<Point *> selectPoints(NXString prompt)- `2 P4 f( Q3 D! r( W
- {
q: v5 s1 ]$ W - UI *ui = UI::GetUI();/ \- _( ~+ R q* v8 _: R: w
- Selection *sm = ui->SelectionManager();2 \! O0 Z9 E1 q- a. }7 q% {. W) x
- std::vector<Selection::MaskTriple> mask(1);/ J/ U$ `! |& D9 c5 E9 J; `7 @
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
) Q N, o( p, i- ^- d& @ - std::vector<NXObject *> objects;( c1 o) r% I: f* H) D9 B
- , ^( ~) @6 O/ O4 I; V6 [! G8 ]) k' D( C* ^
- sm->SelectObjects("Select Points", prompt,
0 F: r( o& b. V# j3 q - Selection::SelectionScopeAnyInAssembly,
% R C1 _0 a- W1 `8 Y - Selection::SelectionActionClearAndEnableSpecific,
. A, z: z$ [" X ?% E+ M - false, false, mask, objects);6 B9 r% g) x1 Q' [1 v" x7 T
- 3 z) h+ l) d4 |
- vector<Point *>selPoints(objects.size());7 ?5 v! h" Q) `: N7 H; R
- for (unsigned int ii = 0; ii < objects.size(); ii++)
. k% M8 r, C+ C' R* u6 T - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);) h8 K! R8 g; k$ M4 W
- , z6 P6 t! @: j
- return selPoints;) T9 v, C/ R/ N% ^- ^1 l' x
- }. X. X6 T% c ?; c h
- ( L9 o8 Z; F4 t8 \: w
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)5 }( m$ {5 z( D: c
- {
- |6 j" Q( w6 z4 ^" j; S( S: Y - Session *theSession = Session::GetSession();
+ i3 l9 w6 x% d9 i) Z7 T - Part *workPart(theSession->Parts()->Work());8 h: y* W/ m9 @$ e5 t
' }$ U$ R# _: h" s1 O- g7 b3 m/ p- Session::UndoMarkId markId1;
1 Y- z2 Z4 I4 j6 z5 G* P - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
" S/ ^! y( B" L+ @# y- m) c& q - "Studio Spline Thru Points");0 Q' b/ Y& V) o2 w& P6 u2 e
# i. v% D/ o7 L2 A8 U& G8 P$ H$ Z$ B2 u- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
' w+ M. ?! }% O/ T8 {3 q6 A - ) A3 N9 T# _ T$ i3 z7 n
- Features::StudioSplineBuilder *studioSplineBuilder1;
/ ~. b2 y5 V. {$ y1 [: i - studioSplineBuilder1 = workPart->Features()->
2 \" [0 {' w% l, Y2 B8 r5 O - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
! X+ a* V$ d' c - studioSplineBuilder1->SetAssociative(true);
" U9 e/ H" a' I/ G! [( K - studioSplineBuilder1->
5 J: Q z! u- b7 S - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; ^9 Q% d9 H1 L3 H
- studioSplineBuilder1->. K* g4 P% j, {6 F% G+ z% d
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
3 i) `$ f( v$ h, ~! a - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);: E6 L ~2 d1 W, j
- studioSplineBuilder1->SetPeriodic(false);4 S, ?2 j% D$ G
- studioSplineBuilder1->. g, }! \* i, J' P6 T% |# d
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);) z- E# G. L: [8 ~5 o) r0 ?3 X: ^
- std::vector<double> knots1(0);! X- ?3 A6 p7 G( o9 p( b
- studioSplineBuilder1->SetKnots(knots1);3 B. H$ I" _) S8 T& D
- std::vector<double> parameters1(0);/ l5 q2 r# T$ L3 y5 ~. r2 S% N
- studioSplineBuilder1->SetParameters(parameters1);
) u/ H" {' q4 C' r/ \2 N8 z& l - Direction *nullDirection(NULL);" Y' U" ~3 p# I) U! ?; N
- Scalar *nullScalar(NULL);9 M; ], x. P5 _1 ^& T
- Offset *nullOffset(NULL);. o" N+ R( |( _; J
3 q1 b( R u8 C% r- std::vector<Features::GeometricConstraintData *>
! f m4 m$ v; Z/ T# V* D - geometricConstraintData(thePoints.size());
) D9 E! ^8 H: s* I a - / ?$ d. }. N/ Q1 x7 Y& L( X
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)7 L& y, Q! J- N7 g
- {# V9 x6 ?" p) l
- geometricConstraintData[ii] = studioSplineBuilder1->; S5 \" I& Q3 N
- ConstraintManager()->CreateGeometricConstraintData();
3 \ i# T" ^+ E6 U2 M' r - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
m# b1 P# ?! Q# F - geometricConstraintData[ii]->SetAutomaticConstraintDirection(. ~$ ?' R# Y) y1 C/ d
- Features::GeometricConstraintData::ParameterDirectionIso);. R7 C5 w D4 @. I4 F, W; U" r4 C
- geometricConstraintData[ii]->SetAutomaticConstraintType(
% v. b0 p: w6 z& u# }* j; R - Features::GeometricConstraintData::AutoConstraintTypeNone);1 a0 |# D! Y5 j: ~
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
+ O7 P/ J1 A2 N* V; t - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
, V7 m# E2 }( v - geometricConstraintData[ii]->SetCurvature(nullOffset); e e, V+ m+ N; N' W
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);& m: L7 q" j; @! z' h1 Q2 Q
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);* T" {2 H/ A4 {3 i; c0 t
- }& v7 s8 k% @3 |
- 3 b' J- {! s' p* P% M N
- studioSplineBuilder1->ConstraintManager()->SetContents(
! J+ C3 N# l- f - geometricConstraintData);
. T. ~" D- S) }2 X5 b- h9 l" }
4 h5 K# g D; i$ R- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
0 P) F# }4 n! Z# k3 z - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();& ?/ Q$ u1 {, E: M
- $ i2 g8 N1 ?$ d! x, `
- studioSplineBuilder1->Destroy();
) i) K1 o; V) I+ Y8 |- r - : u( i1 @9 Z7 m: Z. p$ J
- return theSpline;
9 |6 u- T W$ m6 j - }
8 v: V' k; O% n5 \% \0 |0 p" M - - ~1 g6 I5 l3 @1 e
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)/ |+ k; D4 I5 L; i9 P
- {2 |1 L M: ] k
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
, i9 h& P; J# i: K) I) u - if (!thePoints.size()) return;' k4 J9 V3 ^* w6 Q. U, b* H& R& b
8 X" b7 V2 u- L0 E- Spline *theSpline = createStudioSplineThruPoints(thePoints);
- q4 M- `+ G% c+ k
+ Y4 P" h0 L9 G5 G5 ?1 T) L" ~- if (theSpline)# c2 @# G# ]: ?/ q! M+ o/ Y
- {
# a$ \2 a1 a4 w M9 k) J( \ - theSpline->Highlight();
. z! U* |/ X- ~% a8 n - uc1601("Studio Spline Created Thru Points", TRUE);7 M& V! X- ~1 v* B
- theSpline->Unhighlight();
9 I- Q" Q1 W2 `6 O! L7 _8 ]8 q - }
. ?0 H4 U/ [% ^4 z' \' o# R - }
# S0 y0 d) m7 n( L - <p> </p>
复制代码
( v( J$ q/ k+ }' c, w |
|