|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线( z7 Z1 y l! R4 H7 K
- #include <uf_defs.h>
) W" Z; _( I! m$ t9 Q2 y - #include <uf.h>. M+ ~; n" B3 U. c, X
- #include <uf_modl.h>5 _. n$ b# O$ t" i2 b, C- j
- #include <uf_object_types.h>9 F, k$ |' P- h& z, ^6 i
- #include <uf_ui.h>
, e2 M8 j5 W. i$ y- p0 q - #include <uf_modl.h>1 k) |/ j. A3 q2 [. ^
- #include <NXOpen/NXException.hxx>% V& ~8 \6 T3 M" ]7 W
- #include <NXOpen/Session.hxx>4 N9 k4 |: }# g/ f
- #include <NXOpen/Selection.hxx>
% b' ~. f4 P+ \" A( k* W: f - #include <NXOpen/Builder.hxx> t7 U/ M* Y& I
- #include <NXOpen/Features_Feature.hxx>
2 I, u8 W' W) e6 f - #include <NXOpen/Features_FeatureBuilder.hxx>
6 L% U p: Y; _8 o( ? - #include <NXOpen/Features_FeatureCollection.hxx>, z. U4 G8 ]' E1 C* E
- #include <NXOpen/Features_GeometricConstraintData.hxx>& S& k+ r# n" B' u
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>0 ]! I6 G7 S2 q2 S- h$ N8 s
- #include <NXOpen/Features_StudioSplineBuilder.hxx>+ a5 ~8 B8 U: q
- #include <NXOpen/Part.hxx>
4 H! p4 c/ R$ Z8 \) i+ u - #include <NXOpen/ParTCollection.hxx> M9 [: h: X0 ?+ {
- #include <NXOpen/Point.hxx>7 N9 O, Q: ^/ @& F
- #include <NXOpen/PointCollection.hxx>
6 m: j Z7 Y8 m+ v' q - #include <NXOpen/NXString.hxx>
7 x8 h/ T& T9 V; I; H# f8 L- K - #include <NXOpen/UI.hxx>( Q( `: h& ]% K; A( J* e' ?
- #include <NXOpen/Spline.hxx># T: d* X; G a* [) }
- #include <NXOpen/NXObjectManager.hxx>
4 B1 t" n/ B; b. r - $ e0 u, G6 z K! a
- using namespace NXOpen; X9 G9 t$ a4 Q6 l+ L+ c
- using namespace std;
& j7 T( _( n1 U+ i9 l
7 ~5 ^3 m D( W* K- extern "C" DllExport int ufusr_ask_unload()
4 J+ B6 d3 [) `- Q; k# ~% k* E4 v - {
/ H; F! b# l. Q' `: f - return (int)Session::LibraryUnloadOptionImmediately;
/ E: P" z+ I1 G3 r9 k$ ^% I- b* M - }' _5 \+ r+ a6 q
/ E+ J' ^& u+ B8 \" @' l8 n- static vector<Point *> selectPoints(NXString prompt)( ?6 G! |+ O K. o5 r
- {
) B, j9 n- n* P! j( n - UI *ui = UI::GetUI();/ k/ H# @, N% y& P% x+ F
- Selection *sm = ui->SelectionManager();: Z" h) A) p2 C
- std::vector<Selection::MaskTriple> mask(1);. I" B7 H' e& B
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
4 z P! p* d& C1 F! n5 U - std::vector<NXObject *> objects;
( q6 M+ O+ K9 F9 L; m; M+ g - 4 I6 Y3 ?1 ~. Y: `
- sm->SelectObjects("Select Points", prompt,
1 B$ h, p1 U- W - Selection::SelectionScopeAnyInAssembly,
/ H1 _2 k: G! U' j - Selection::SelectionActionClearAndEnableSpecific,
' f) b+ c! x5 y' z/ m+ ~ - false, false, mask, objects);6 s) C& ~+ o" b0 q6 x( J
6 g6 I% e; R. }0 N# I ?3 [. R; ?8 }- vector<Point *>selPoints(objects.size());
8 q$ S% V& d2 g3 l - for (unsigned int ii = 0; ii < objects.size(); ii++)# i7 t$ g* F2 ]7 M4 \* d% s
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
2 i! ~; {/ v: w - 6 l+ r! x+ F' x
- return selPoints;
9 A& a# o% O5 `( {$ \' {; A [ - }
3 |# \- i2 z: Y - 7 Y7 [. m V0 Q" Y0 s' O
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)8 g$ B$ s; X6 B6 ^3 H) y, M
- {
4 |& f5 s2 N% W/ h/ h/ ?6 t% d7 @ - Session *theSession = Session::GetSession();
1 b2 r; N* s( S- A - Part *workPart(theSession->Parts()->Work());
4 s" c8 ^7 ~: U - 5 @3 l1 [/ V" n$ y e! ?
- Session::UndoMarkId markId1;
) v" Y5 `1 n7 h7 m U5 w# P! y - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
1 ? E3 K k* @1 o: d, O R - "Studio Spline Thru Points");
% [, I" v* d. |9 x' Y# H6 V( t/ @ - ! H$ f# d4 Z. P) D5 S+ t3 h
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
2 w! e+ t. M) F; i - 5 h7 M" Q" a1 A% i
- Features::StudioSplineBuilder *studioSplineBuilder1;
$ e3 {- }5 |9 H6 Z) P, o, b - studioSplineBuilder1 = workPart->Features()->. C" P: c# ~0 u- Z4 v
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
6 v4 @( w9 I H# d+ L - studioSplineBuilder1->SetAssociative(true);
0 c. C) y% O' O6 C1 x2 h! \6 K' H - studioSplineBuilder1->
" W. q/ M8 Y$ V' x0 G. O( v - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
1 z' z/ y5 s$ P; ?$ \4 p - studioSplineBuilder1->
* j" V& Z3 `4 \4 M5 r/ S' c0 M - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
! H. u: K i% e: V0 L# U - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; |! w6 \: E# }
- studioSplineBuilder1->SetPeriodic(false);" F$ r# m# ]# A$ i+ P
- studioSplineBuilder1->: q8 `9 p' d' z- S- {$ ]- r
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
5 s1 I2 v! h' q" c! A/ w - std::vector<double> knots1(0);- n; F/ v! s) X' t. [+ r8 `7 T
- studioSplineBuilder1->SetKnots(knots1);& s) j# A9 }0 {6 u) Y5 d$ j
- std::vector<double> parameters1(0);# e* z% _ m4 J) [1 W
- studioSplineBuilder1->SetParameters(parameters1);
& u" R& x" y& ^0 } - Direction *nullDirection(NULL);
, l0 K3 B6 x K, p8 ]3 n% b* a+ w9 J" Y$ Y - Scalar *nullScalar(NULL);9 z+ h9 @5 g- ]0 j3 V) y, u4 i8 {
- Offset *nullOffset(NULL);/ u9 H3 y0 [/ N- o7 V
4 T# C" ~! i; A7 m! Q- std::vector<Features::GeometricConstraintData *>% q5 b; Y4 ]3 _9 i, h
- geometricConstraintData(thePoints.size());1 n# m# o% P: L% f* y3 b* g$ [
% k8 d4 b+ t# q# t6 V& U- for (unsigned int ii = 0; ii < thePoints.size(); ii++)5 s% O" {4 |( e b
- {
+ ^1 V7 G- ?; X. H4 z - geometricConstraintData[ii] = studioSplineBuilder1->. k' C$ t- P" N) v
- ConstraintManager()->CreateGeometricConstraintData();: U7 |/ s& G. h- }* i0 f/ O }
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);/ _. x; q' x/ p8 {$ D2 e
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 b3 R' R9 @$ N$ i
- Features::GeometricConstraintData::ParameterDirectionIso);: _5 d0 s5 M0 _9 S/ @( [
- geometricConstraintData[ii]->SetAutomaticConstraintType(3 O4 k. {: p* ~
- Features::GeometricConstraintData::AutoConstraintTypeNone);1 u9 r5 B% T! h, g" x6 p
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);! s- _) V. M- d7 z9 Z6 c
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);9 F* Y* ]* k# f. h
- geometricConstraintData[ii]->SetCurvature(nullOffset);
0 J$ d' E( C; Y$ P. ?2 M Z8 z. } - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
# [5 ]. ^2 \) c1 O; K1 }/ i - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);: q8 V. ]) e8 k( X) e7 }
- }( q3 O/ Q- z: m: u
7 T. W) m4 B$ h+ V: D' N' A- v& ?- studioSplineBuilder1->ConstraintManager()->SetContents(& ~! i& p1 F5 z8 S8 Z: B
- geometricConstraintData);: b) l) p4 w& O7 V. a& A: m
- % |+ B0 K1 e$ w! s' `
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
, Q3 J) j+ e4 I( `. y$ K - Spline *theSpline = studioSplineBuilder1->Curve();
9 g9 Z4 m1 O+ T G
8 o1 N G- ?3 q5 H' e- |- studioSplineBuilder1->Destroy();
0 H. V% z9 v n' W3 e" N
) p1 i( V) |; |( J; X q; f! R5 Q- return theSpline;+ `3 g4 G8 w0 T7 U" R
- }; N+ t, m I' g3 [# R
1 A: G% S J0 h x( m- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)5 d, o; Q6 o, l5 ^% E- w6 e3 `
- {. K0 y7 f" r3 O
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
9 r# n' f& ?/ V2 A - if (!thePoints.size()) return;2 l1 h% F, x$ X3 x7 b7 z- u
5 Q) l. \* J w- Spline *theSpline = createStudioSplineThruPoints(thePoints);
" l5 c$ r, ~/ e7 o2 H/ ~* |' d; n
2 I$ [9 X; w- d. q7 [3 ? q3 C- if (theSpline). ~' O7 T( V' T! Y0 ]2 u; g3 } c
- {
# y( {: b" w& k. B3 w - theSpline->Highlight();
9 d; [& n- T% a: H - uc1601("Studio Spline Created Thru Points", TRUE);
0 m$ i p$ j7 Z - theSpline->Unhighlight();
3 d g6 v- l, r0 |. v - }& ^+ x$ _5 I, C2 E# _6 d( z6 Z Y2 ^
- }6 d: s; r# v! a7 l; \, `
复制代码 O- R1 C/ G; Q' N8 M' E+ x
M) y8 ~, O; f0 K0 Y( c) u
) L/ Z( h3 _$ y |
|