|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
+ G+ j" r- E0 b; |' M5 C- #include <uf_defs.h>
' R+ d! B) q' |0 e: x - #include <uf.h>% d. O1 u* W' y* N3 ]* t. b0 V
- #include <uf_modl.h>
* Q6 w: Y3 r4 k$ \9 ?# I - #include <uf_object_types.h>7 J. q7 ?1 H# ?2 w
- #include <uf_ui.h>
. b9 t) E1 |2 |0 C - #include <uf_modl.h>
/ `; _. J* ^6 H3 ?0 K - #include <NXOpen/NXException.hxx>
& z* _: e3 a/ E3 Y - #include <NXOpen/Session.hxx>
8 f& B; r1 g1 @6 l9 T0 e8 _ - #include <NXOpen/Selection.hxx> |& F7 V% @8 a7 v1 _
- #include <NXOpen/Builder.hxx>
7 d$ r- O; A; C( ~ - #include <NXOpen/Features_Feature.hxx>: w5 [! m! j5 Y2 c
- #include <NXOpen/Features_FeatureBuilder.hxx>
7 K) V* \2 G: k4 y9 e- t7 J - #include <NXOpen/Features_FeatureCollection.hxx>
) m3 E" I& G' Y1 r( @- n - #include <NXOpen/Features_GeometricConstraintData.hxx>
- |9 m9 b* J0 \0 b' \: E$ O9 O - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
1 J- d) v3 L8 C% R" Y; { - #include <NXOpen/Features_StudioSplineBuilder.hxx>9 C1 ]) {) y h# k \8 p/ Q: c9 X
- #include <NXOpen/Part.hxx>
3 o1 ~# C1 x( ?2 { - #include <NXOpen/ParTCollection.hxx>$ I( j+ v$ {9 m8 {
- #include <NXOpen/Point.hxx>8 J/ S0 [ i" P7 r3 j
- #include <NXOpen/PointCollection.hxx>
# C$ ]2 H b% {# S* | - #include <NXOpen/NXString.hxx>
. W5 A7 `4 i2 K: z# I' k; k - #include <NXOpen/UI.hxx>+ H) }2 a1 u/ H+ K* e
- #include <NXOpen/Spline.hxx>' ?6 |* L1 D/ ~9 K4 G6 {1 C
- #include <NXOpen/NXObjectManager.hxx>
) k2 l3 G( q, q5 A
: ]) ~8 R& b, {, w1 U, I- using namespace NXOpen;
$ J) ]. K- c" U# \+ O' o, s( X - using namespace std;
. E+ o4 m. g5 U* P) m3 B( w% N+ n - - q( G# |+ R( Y+ _8 R4 B! S. |
- extern "C" DllExport int ufusr_ask_unload()' n5 N$ C8 Q- N% d; ~7 J2 @
- {
& w( k8 R+ \; W - return (int)Session::LibraryUnloadOptionImmediately;
* n, l t5 L, s3 f. Q8 d$ C+ x - }
! b" c' N5 W. A9 `
: M0 U0 k! Y* T( [" |3 G- static vector<Point *> selectPoints(NXString prompt)2 f* S& R/ K3 r4 K1 q, Y+ N; A7 }
- {
2 |+ t1 j) q8 J* w! ?: O - UI *ui = UI::GetUI();
, K3 j* j: A) t3 j - Selection *sm = ui->SelectionManager();. t+ A* t4 V0 |7 ^
- std::vector<Selection::MaskTriple> mask(1);
7 k: K2 n/ }2 O S" ?2 f! i! q - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
$ A" Y: L, |: {( w: _% n - std::vector<NXObject *> objects;& F5 `# p/ r+ \0 w# f4 @
5 r5 S8 I( v) h4 H: |1 F8 J- sm->SelectObjects("Select Points", prompt,* I% U. I, \0 x) l8 l
- Selection::SelectionScopeAnyInAssembly,; n. H/ K/ d3 x/ S0 E# P% }! e
- Selection::SelectionActionClearAndEnableSpecific,* V3 P! o0 R1 H5 \9 k
- false, false, mask, objects);$ N$ l/ g0 Y4 u) I( ?9 L- R
/ i) I& s; c# L# \) v- vector<Point *>selPoints(objects.size());
% d2 t& _' t- S - for (unsigned int ii = 0; ii < objects.size(); ii++)$ }& v8 \- _2 M. Y/ L6 U
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);) |8 T! j' _! y
- / S8 h4 C, A& Y% U
- return selPoints;
4 C t1 i& C& d0 d5 s. m7 ~ - }
1 l y0 \ v& W7 W
% A* X* @5 ~$ P$ b* @- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)! R* S5 X3 C+ B9 O/ H8 h( R4 P* ~
- {7 \( ]7 I# V7 {+ \( p) V; @8 S
- Session *theSession = Session::GetSession();! P2 u1 N5 \2 Z) d) E" W r I
- Part *workPart(theSession->Parts()->Work());
4 N$ k' C2 G" B* [7 n
: K9 W0 t, Z8 @2 i) o$ V- Session::UndoMarkId markId1;
9 Q5 V1 _1 h. {9 e - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,/ x9 F V" l% f6 I0 a8 q, E0 \
- "Studio Spline Thru Points");4 m; m! i$ {$ J' S
- 2 }7 H/ @5 j, ^4 x q( a
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);4 M/ p0 C- Z3 R; W ^
- 5 x, \6 F9 t3 {: g2 `2 c; L, g# G
- Features::StudioSplineBuilder *studioSplineBuilder1;' w' F) e+ ?5 u9 b
- studioSplineBuilder1 = workPart->Features()->1 ]/ @! N+ v7 y* U' c8 ~
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);; J, b: V* Z2 {- Y+ L4 e
- studioSplineBuilder1->SetAssociative(true);
9 ?4 b' s* F8 P/ k/ s+ e% T - studioSplineBuilder1->
! h9 t0 T0 ?- h2 D8 @7 m - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
% J, n" E& {6 L- p/ l7 }) a - studioSplineBuilder1->
+ Z) b+ v0 e5 K' u$ P' j( {# [ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
+ W3 ^+ ^ \+ v" l% N) \ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
% q' m3 G8 I( x' [) S# _ - studioSplineBuilder1->SetPeriodic(false);
3 }6 I4 ~" l1 r$ p$ u( k3 ? - studioSplineBuilder1->/ t9 p$ a( x8 B; |" }* [8 S
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);3 R( L3 h$ e6 N7 I8 F
- std::vector<double> knots1(0);8 ^& X( f7 c* d/ A
- studioSplineBuilder1->SetKnots(knots1);
4 p9 z1 M- ^8 k2 @ - std::vector<double> parameters1(0);
& F- ^' K% h: g. @+ X - studioSplineBuilder1->SetParameters(parameters1);# e2 T/ M& v/ x; S/ G2 x; x
- Direction *nullDirection(NULL);( U8 t) ?2 u* D6 T' V
- Scalar *nullScalar(NULL);) ?& n" j) I( D" T9 R
- Offset *nullOffset(NULL);* O2 F: w; V' M# M
- ' [+ j r; F7 g: O* m7 `6 K0 x2 z
- std::vector<Features::GeometricConstraintData *>
" b' Q) l! v, y$ b: D# Z - geometricConstraintData(thePoints.size());) a# ~3 U9 t$ t- o& n' j/ I
- 7 d) m/ Y7 z3 F7 u# J1 A& w
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)( j4 k0 t. q: v% I
- {
1 e3 n& x. v+ I9 B1 {& }# c - geometricConstraintData[ii] = studioSplineBuilder1->
* v8 V. y- D. N" f1 \0 q5 F - ConstraintManager()->CreateGeometricConstraintData();
i8 _/ W/ h% N3 A' U+ M) S2 f' H - geometricConstraintData[ii]->SetPoint(thePoints[ii]);& s' n8 T+ X1 i1 W( @4 Q/ N
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
* K; Z3 ?, A# e - Features::GeometricConstraintData::ParameterDirectionIso);
) _1 ~* D! ^& u( L5 M - geometricConstraintData[ii]->SetAutomaticConstraintType(
5 E% I2 S' ~! r1 t& Z* _5 q, T - Features::GeometricConstraintData::AutoConstraintTypeNone);
/ S( S F. @2 V/ K' D5 r$ v - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
7 q* J6 @" ?8 I5 j2 n; q! y - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);& z" c& M1 u, U( t$ |
- geometricConstraintData[ii]->SetCurvature(nullOffset);
7 S% p$ Q9 E3 X! h - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);9 K, B$ B8 M0 M& b/ v( ?
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 R" m0 p! l S% z3 n2 @ M
- }' h. x# Y) _4 U, v5 x
: S; l% N% }: G" e- studioSplineBuilder1->ConstraintManager()->SetContents(! U: t& Z5 q& o# B: E
- geometricConstraintData);
. [0 k# t& m: c' R7 r2 q+ H: z
- C7 B# t/ ]9 B4 t# |; p# R- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
$ _8 C% e( ~0 p: }* N9 i+ z4 n - Spline *theSpline = studioSplineBuilder1->Curve();
* `# h' K& P+ m7 X - + w4 p; i4 U7 r0 A
- studioSplineBuilder1->Destroy();3 e0 u# m+ D# i; ~' X" V. j' P: e
# k( W$ d* _0 H( @1 T- return theSpline;0 x# m! X. o( M
- }
! m; q9 U' `; ?. j' C
. ~2 F( g* x& O! f T- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
% h2 s- w' \5 Y) g2 ] - {- K3 G Y1 c6 m) }
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
( G, n. K! P& w7 S* p$ u - if (!thePoints.size()) return;6 }% E" Y# D r$ E ^# A
" L% c, i% c. w- Spline *theSpline = createStudioSplineThruPoints(thePoints);1 h2 v9 ]% J, Q" Z* N* D
% A2 N# i( |% g+ e! d- if (theSpline)
; X* @' R% o+ X$ Z0 X - {" h) s( r6 R/ d: @9 m% D2 f* g% c2 G; p: G
- theSpline->Highlight();, t# o' N, o1 S- \6 @; A7 r
- uc1601("Studio Spline Created Thru Points", TRUE);
7 w8 _8 s m: y' w: p - theSpline->Unhighlight();" T4 L1 E6 b9 Q7 v# f9 U1 p
- }1 K7 r4 |4 L: r9 W6 d8 B
- }
0 w H, ~* d0 T A3 y0 q
复制代码 . \: I: |0 C. ?) Q, b3 `, K3 @0 X
( J. B. S2 _: `- ~- s6 C* Y: Q/ X, y, k8 a5 G. t
|
|