|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* O8 N2 _4 e$ d
NX二次开发源码:通过选择点创建样条曲线
; t- d0 o0 I' ~' x5 |- `! |; T! p7 j: k$ ^9 s
6 L ?# |# `3 `
0 s' p5 `: {: b& N- #include <uf_defs.h>
5 l6 d: U* [9 c% X6 k& H: M - #include <uf.h>
' z3 Q D0 A) x, B; {' F - #include <uf_modl.h>$ {2 |9 v. | z3 S
- #include <uf_object_types.h>
M# ^0 f: h- e' ?" J; p - #include <uf_ui.h>, G! K! O' a& H
- #include <uf_modl.h>" J! A9 [$ w' ]" k# v; {. J7 v# e
- #include <<em>NXOpen</em>/NXException.hxx>8 _ y+ I) ]4 }# i; B
- #include <<em>NXOpen</em>/Session.hxx>
& ]. w0 x# E4 M: l) w( B - #include <<em>NXOpen</em>/Selection.hxx>
2 T9 K& v( @. S$ w - #include <<em>NXOpen</em>/Builder.hxx>
. p/ W9 Q! D$ [5 ^" @$ \ - #include <<em>NXOpen</em>/Features_Feature.hxx>4 H0 Q7 {* a& d" m: o* S
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
7 `/ r8 Y8 [ k, c7 q: S( d - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
! Z2 e2 `+ p e6 \& g - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
$ [; j6 h; Z5 F* f! G$ J' E - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>+ R7 {$ Y- x% z1 H
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
- x, c+ I+ ?* M$ g7 y, C% g0 z+ B4 q - #include <<em>NXOpen</em>/Part.hxx>
+ [! K* _! S" j% P - #include <<em>NXOpen</em>/ParTCollection.hxx>
0 F2 ^2 M* ?5 |$ y* q; `$ y' q6 [ - #include <<em>NXOpen</em>/Point.hxx># K! O! f) l9 w3 I9 n
- #include <<em>NXOpen</em>/PointCollection.hxx>' ?# e9 N- N# u: t$ w3 K
- #include <<em>NXOpen</em>/NXString.hxx>/ l Z% k& ^& s, H/ n$ J, }
- #include <<em>NXOpen</em>/UI.hxx>
4 f* Q q9 K7 v B6 ]+ _* n - #include <<em>NXOpen</em>/Spline.hxx>; f" b4 j# \# K2 J9 k+ S8 {
- #include <<em>NXOpen</em>/NXObjectManager.hxx>6 |8 T5 ^0 l3 P8 W% q) P
) E S4 L$ |' I" A% g5 H- using namespace <em>NXOpen</em>;% A3 ~ |! z! J5 w/ I( S% ^
- using namespace std;$ P+ G. p, U: j( k1 [5 f i; U1 D* T
+ a f# u* [0 M- extern "<em>C</em>" DllExport int ufusr_ask_unload(): N" d2 a. R" K; I- H' j
- {7 ^5 g6 X! G2 f/ |6 m" Z
- return (int)Session::LibraryUnloadOptionImmediately;# u0 `6 I! O# }
- }
7 A5 N1 c" f9 c9 D6 i5 ^ - # m3 {4 D" H. C6 U
- static vector<Point *> selectPoints(NXString prompt)
9 H8 i6 ^1 P1 ~/ ]: C - {
: e. D+ e# |- c4 P - UI *ui = UI::GetUI();
. Z2 ]6 _+ B1 S - Selection *sm = ui->SelectionManager();% W$ }" p( b* p1 _
- std::vector<Selection::MaskTriple> mask(1);/ Z2 q6 p, W/ \" i
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
8 d1 b/ P. @1 [3 }2 r - std::vector<NXObject *> objects;
! U% W' k- [: b r j3 r( E - 1 j4 m% `$ H& S3 o4 f( O4 ^
- sm->SelectObjects("Select Points", prompt,9 Y6 e h$ k+ W6 I7 e# y3 p
- Selection::SelectionScopeAnyInAssembly,
) n I% Y7 j6 k) ?2 w# g1 W+ J - Selection::SelectionActionClearAndEnableSpecific,
) F, ^4 j h; D# z. b5 j" @/ N/ Z5 q - false, false, mask, objects);
. m: t7 Y* Z' b6 B. O4 F: a - 0 [7 m7 a0 |# a# a1 ^: N
- vector<Point *>selPoints(objects.size());6 O1 I8 D6 t# U9 a' R1 I% o7 X
- for (unsigned int ii = 0; ii < objects.size(); ii++)0 P9 H9 m4 L( o3 ^2 D# V9 {
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
W( k/ E4 T3 x - 9 x" B$ w% x. m8 c% K2 Y6 G @
- return selPoints;" M8 l3 r5 K) x3 k1 K0 ~
- }* |) K. \, A, [
- 2 c8 f9 p$ ?' g; S8 X
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
7 I' v }" k- b - {( J5 `2 ~) e+ O/ ]2 \
- Session *theSession = Session::GetSession();
7 C) U( V' i# W - Part *workPart(theSession->Parts()->Work());+ r! Z- @3 }1 \1 t/ X' o
- 3 _; l; y/ b G k
- Session::UndoMarkId markId1;& c/ s, u7 Q. c( f' b
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,( D" r% e& V* g
- "Studio Spline Thru Points");
9 @+ b; C4 ` `& }1 _ - 5 `* [6 Y7 v6 \3 p$ g* P1 E8 K- z% @
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
7 V" O2 Q2 |; }
! i: d3 m8 k" Z2 l" l* c- Features::StudioSplineBuilder *studioSplineBuilder1;
; B7 R7 T7 I) \- S3 o1 u' i. u - studioSplineBuilder1 = workPart->Features()->
7 |# P* k6 G# R9 @/ {3 y! H2 O' g - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
7 ^3 r: t7 B; B( l: R - studioSplineBuilder1->SetAssociative(true);
" U0 S6 J6 n( f& _$ r- i - studioSplineBuilder1->+ @3 r- s9 [5 E1 X0 U
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain); S& L; G6 Z! ]$ N4 G! v, |& L
- studioSplineBuilder1->
. B* G+ f' f# Q' u$ g! b% }3 U - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
/ M% r- v9 f: F2 X* S1 h B* @ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
8 s3 G! w9 g1 U; m: t: H1 N - studioSplineBuilder1->SetPeriodic(false);
/ Y; n' P4 i/ R) |* ` Q/ a% D& Y - studioSplineBuilder1->
{9 _4 \. q, q6 u2 h3 i - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
3 T6 I( F: f1 D* E - std::vector<double> knots1(0);
! o) K& I0 H1 Z7 ? - studioSplineBuilder1->SetKnots(knots1);
) f( V: C0 R' u; O' D6 ~& R5 r; X - std::vector<double> parameters1(0);, ]6 p, i: u* O+ |
- studioSplineBuilder1->SetParameters(parameters1);0 `. d+ U7 A6 c8 J; V/ I; w
- Direction *nullDirection(NULL);! j! T7 Y* q8 H9 L6 _( n
- Scalar *nullScalar(NULL);
! `& i" c( u+ q, c- `# p - Offset *nullOffset(NULL);" u" c+ v2 y" _# v, u
: d1 L8 p# f& ?1 k$ [+ Q" n- std::vector<Features::GeometricConstraintData *>
2 M: u+ z( ^2 A9 p: x1 f - geometricConstraintData(thePoints.size());
# _0 h0 A, i. g( c7 a: _ T
4 F# z1 a' T$ h; G, t- E- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
& }' p( C* v0 J - {
+ f$ l; H* c9 D& \ - geometricConstraintData[ii] = studioSplineBuilder1->
9 B; o5 k2 d9 |: r/ I - ConstraintManager()->CreateGeometricConstraintData();8 D6 ^) X3 h) N' V, p6 ]
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);# O3 `3 w0 y& }
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(: W" _) V; n8 c" q7 v: z" T& \
- Features::GeometricConstraintData::ParameterDirectionIso);
# B0 K7 O+ Y& U. p - geometricConstraintData[ii]->SetAutomaticConstraintType(+ U2 m* _8 ^$ {% S% }! ]/ @* w
- Features::GeometricConstraintData::AutoConstraintTypeNone);
- ]9 ^/ Q4 o8 i" x2 l4 n( P5 {3 t5 c - geometricConstraintData[ii]->SetTangentDirection(nullDirection);- A3 Z" I: h! i( B, X; y% X# Z
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
$ P8 b) s3 V8 x7 b" C: W% u2 g - geometricConstraintData[ii]->SetCurvature(nullOffset);+ P# h3 Z# T4 M/ b
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ c8 m8 ~- `& p: j. [
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
8 } n4 s \# ]- S6 n - }
9 S, A3 d) i4 O; S1 X Z
# e3 B+ K8 R2 x% ?1 {7 G- studioSplineBuilder1->ConstraintManager()->SetContents(+ R" `% \+ I$ ]+ |- y+ z
- geometricConstraintData);
. q c' G0 \! J& `/ X
9 ^6 ~8 {8 c; Y7 X2 w5 a$ Y p8 J- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
% o* J" G7 V6 k - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
- {6 D) H& A8 Y h6 k9 w# A& q4 T
# t: a' T: m( m4 H) \3 a3 X% t- studioSplineBuilder1->Destroy();
4 ?) [+ a$ _$ ?2 ?
' ^) ?/ G' e' `3 Q7 b3 P- return theSpline;
- @/ H; l% K( i( G5 S/ p" g' l! z - }& M ?, V6 \+ j
0 O2 O& a6 o5 o5 n7 Z' x ~- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
$ k8 |- w6 H2 q3 s+ ~/ u( x - {3 Q( d& g2 O" Y1 C+ I
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
8 {; A' S: [9 F) I( ?! |' h/ H2 O - if (!thePoints.size()) return;
7 d- T- u8 ^ s5 I7 e$ ~! m% \ - : z+ p+ F3 h! R5 Z- d
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
* R8 k% y% R6 N+ Z7 l8 S
* ?4 j# l% \, y& L5 d2 W7 {- if (theSpline) A% {. h! E. K4 q5 I
- {, S- j5 L0 _- I) a* v
- theSpline->Highlight();1 {9 D# S, J/ }. C
- uc1601("Studio Spline Created Thru Points", TRUE);* q! [9 i7 {! Z' q; ?% a, s3 S# U
- theSpline->Unhighlight();4 X1 h& M. x; Y/ V0 b
- }
( ?- H1 ]- A' P) w7 A) N# u - }
' o5 s$ h- C8 y$ ~; t8 T/ N - <p> </p>
复制代码 : X$ E, w5 R5 j" r Y
|
|