|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线3 c. Z7 w/ c7 M" j. Z
- #include <uf_defs.h>
6 n9 i7 [7 o2 w* w0 [7 e+ p - #include <uf.h>! V, {! B: Z9 I& Y' {
- #include <uf_modl.h>* v( _9 k% _/ W7 |# G- k
- #include <uf_object_types.h>) f; p5 T2 T' m6 {4 r2 |
- #include <uf_ui.h>
0 \0 O/ \1 @* ^! U3 M7 A7 B - #include <uf_modl.h>
, i% q& l( m; `2 F0 t/ n) N - #include <NXOpen/NXException.hxx>
2 b" P: Z2 n* \+ M - #include <NXOpen/Session.hxx>
3 i+ Q. S, ~# N0 Q" f- {3 h% I - #include <NXOpen/Selection.hxx>/ a) r1 w, l* X! P3 v
- #include <NXOpen/Builder.hxx>
h' `' O' H0 }+ A2 H9 I' X) G - #include <NXOpen/Features_Feature.hxx>
; R7 o" u& D' h- R- y0 q0 a - #include <NXOpen/Features_FeatureBuilder.hxx>% J" Y$ k, D5 T P/ ^
- #include <NXOpen/Features_FeatureCollection.hxx>6 D& o5 t* B$ P
- #include <NXOpen/Features_GeometricConstraintData.hxx>
S" e7 l- H$ [1 y - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
& K, B a* q* E3 C( ~/ M" r - #include <NXOpen/Features_StudioSplineBuilder.hxx>$ ~3 }: N/ V. U% L% M2 x
- #include <NXOpen/Part.hxx>3 b0 k2 O) P" D9 l( [8 X0 l2 k! Q
- #include <NXOpen/ParTCollection.hxx>
) q4 \7 b$ i- g2 j3 | - #include <NXOpen/Point.hxx>
0 ^! U3 q$ S: f4 a6 P) c% H( z - #include <NXOpen/PointCollection.hxx>. `- @, b$ S2 a6 s# G. L5 Z
- #include <NXOpen/NXString.hxx>8 I1 j- {4 y5 }$ e
- #include <NXOpen/UI.hxx>. C: g9 f2 _( V& K6 z
- #include <NXOpen/Spline.hxx>
! m) W7 l% p) s - #include <NXOpen/NXObjectManager.hxx>
, g$ A6 o4 u2 Q5 r ^& i
* A9 X- j; Z" [$ _& t/ [; U# q7 g- L2 v0 }- using namespace NXOpen;
) G& b: [0 p' N% N, z - using namespace std;
0 b8 W& F0 C+ R/ U/ a) p F - 4 [% e0 {7 f; m$ Z: f c
- extern "C" DllExport int ufusr_ask_unload()
7 b7 N/ w6 c0 J+ c5 R - {
( H( ]/ f1 f& l5 B. P C1 i5 ~ - return (int)Session::LibraryUnloadOptionImmediately;7 U* V# y5 r4 ?# K; }8 |2 Y
- }
1 `9 z& q" |$ Z* _$ y7 R- w) q, M
5 O4 s9 S G5 ~- static vector<Point *> selectPoints(NXString prompt)
0 q; ]) n- e) y I3 b1 @ - {/ P% j. p: }3 p7 x/ U$ V8 l
- UI *ui = UI::GetUI();5 S# A, `! s1 G/ W2 Q
- Selection *sm = ui->SelectionManager();
/ E! f: a$ U/ s3 p, J& f - std::vector<Selection::MaskTriple> mask(1); R! W* n5 R w* `2 l, y* v
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);( m6 z) X( O7 _$ p3 P
- std::vector<NXObject *> objects;. k4 B a; a% y3 H: ]- d
- 2 s: e4 h! N* W% p7 z
- sm->SelectObjects("Select Points", prompt," r" h: M% t/ i
- Selection::SelectionScopeAnyInAssembly,* t. K1 {& G6 s0 b2 o6 F& r
- Selection::SelectionActionClearAndEnableSpecific,- Q3 |& P8 M- U7 Q
- false, false, mask, objects);
( i* E6 _( G, p4 ^$ x1 y* V - - W8 E* z. ?+ O+ n/ K# g6 e
- vector<Point *>selPoints(objects.size());
( v, n# l" a8 z8 s- r3 J - for (unsigned int ii = 0; ii < objects.size(); ii++)
7 S2 I6 |% M6 s+ a+ ?1 D6 U9 _4 u - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
9 O. _- [. s* F8 ~5 y1 l! l+ m
1 G- j+ m, B( ]8 ]! O( E) N0 A- return selPoints;8 F7 L- u& v! Z% Z# l* c% p" W/ P
- }* V4 u+ e' m, Z4 y9 q4 f1 H) r
- 1 S4 m; s! H U; g0 s @
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
; W! Q: e+ S5 u, \) W6 ~ - {
' ]- X+ B5 X! ^' Z( ?: N - Session *theSession = Session::GetSession();- U4 q+ D' V0 j+ q$ w, l1 h
- Part *workPart(theSession->Parts()->Work());
: B- b5 n5 n7 @/ Y" _5 e
: W8 |: k1 q* M/ r+ z6 \* i- Session::UndoMarkId markId1;
. k m- a) {: | - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,/ c/ {7 B" A% k$ u I; \( P
- "Studio Spline Thru Points");
7 h, X4 L, R T5 x$ P$ [+ F$ m' g
+ h4 d& u0 l) l1 A- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
$ p' z2 `9 ~- G4 P, j
3 X" @0 ^3 u0 J8 d) w B- Features::StudioSplineBuilder *studioSplineBuilder1;* t; n* y. |3 ^, V9 N$ P9 w
- studioSplineBuilder1 = workPart->Features()->( M. j0 q- l" y, f4 w! @; p u# |
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
* S8 F" g* R# l! F6 W - studioSplineBuilder1->SetAssociative(true);
* m$ C l9 v! g2 X0 f* q - studioSplineBuilder1->6 e" T5 R2 ]7 a9 o0 k6 U
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);1 B, o. ~% A5 C: X
- studioSplineBuilder1->" ~/ t. l7 v4 `* E
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);( R) [+ J6 e4 Y. o* F4 ^
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" T2 Y' n/ c& [
- studioSplineBuilder1->SetPeriodic(false);9 z6 x) \1 a; U6 K5 x5 @
- studioSplineBuilder1->
/ d4 v5 s- _! {6 {* z& X# X - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
7 S& m* v" c: C( K* Q. X+ a8 s - std::vector<double> knots1(0);* B) `' V! s' V. V$ M2 T0 g4 P. a
- studioSplineBuilder1->SetKnots(knots1);: r9 n! g# \: j% ?7 N- |
- std::vector<double> parameters1(0);% b$ ~* J j }. Y( s7 n2 O
- studioSplineBuilder1->SetParameters(parameters1);/ g2 V/ s, e5 n/ n
- Direction *nullDirection(NULL);. o- z: V, E/ j8 Z+ ]+ S" T% T
- Scalar *nullScalar(NULL);. a/ f% l& Y9 q- m5 o* P& a5 a, v
- Offset *nullOffset(NULL);3 ?8 I7 |- Z1 W! a3 v
- 0 Z0 s- P" P. g) F, l
- std::vector<Features::GeometricConstraintData *>
* B- ?- T' D) J& L1 Q! O - geometricConstraintData(thePoints.size());+ Z# F, F9 N' w% H3 ~: P& k7 f; j+ d
- . D1 V% ^. }8 R
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
) ?6 X* `' N. ^6 [ - {- z5 Q: N2 r$ z6 L M t
- geometricConstraintData[ii] = studioSplineBuilder1->
) c, e; j2 b. A9 I - ConstraintManager()->CreateGeometricConstraintData();
! @& N) n. v6 r - geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 k+ `' R' d; Z% k5 g! f0 {
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
0 m- L: C/ f5 W' e9 f0 L, n- V# h - Features::GeometricConstraintData::ParameterDirectionIso);1 Y& I. v* f8 S! `, D
- geometricConstraintData[ii]->SetAutomaticConstraintType(5 f+ H$ u& N1 G j) T* `
- Features::GeometricConstraintData::AutoConstraintTypeNone);
! p9 D& u1 @3 h; J- Z3 \ - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
& C. [2 u4 q( u2 ]# _- P - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 i& h) }1 i( c* N* E6 b
- geometricConstraintData[ii]->SetCurvature(nullOffset);& z- Q+ b0 M$ |; p
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
# z; K8 Z' I) d5 b! h% z - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
1 @4 J6 ]7 t/ [, }0 X3 [ - }& q3 Q: o/ Q" o- ^5 L ~% V# f0 l
- 8 e4 ~7 L- O+ Q) `
- studioSplineBuilder1->ConstraintManager()->SetContents(
" J& `# I! d+ y0 ~( Z; ~+ l - geometricConstraintData);
0 s9 F+ ~8 Z, X) y - " \# \, Y) b7 A4 k: j3 B. H T. Z. d
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature(); U* e* e5 Z7 }8 B3 b/ G
- Spline *theSpline = studioSplineBuilder1->Curve();9 A! o, E/ Q, n( ]4 f, \
- - G( e2 Q, k# p# y
- studioSplineBuilder1->Destroy();/ g. _( a; G; U. W- h
4 R; o, v% C" H4 V( M- return theSpline;/ a4 K( w* j2 u9 v3 ~0 k
- }
' t3 s0 o" o. W7 b) P) _ - , p) l0 f" o8 @4 `/ ?
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
( y# `( Y: y; Q - {
3 c9 T( B- i# R( U2 q' q% A, u - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");0 G; ^' I U" a5 N
- if (!thePoints.size()) return;
, x. P4 ]' S/ h: f7 O9 h$ y) } - % @! \: g; ^7 V) Z6 u0 b
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
! b$ v9 m* L- k* F - 5 N& O. T6 C6 n) r2 M
- if (theSpline)* l# ]! U& f8 C8 m
- {
. N3 ?9 j5 f$ O ~4 Y - theSpline->Highlight();( x, D/ o" }8 C, b0 u
- uc1601("Studio Spline Created Thru Points", TRUE);! n% n) z7 }( _% l Z2 S& B+ A
- theSpline->Unhighlight();
9 U, z3 D, t8 p7 y0 a; R. R5 E; e - }3 z8 F. w# F' |* P! S
- }+ L6 f9 b0 ~0 x3 C" K* d* ~6 z2 x
复制代码
9 _7 e+ [/ a! L& f* T ~! V
, A: e3 b0 s8 f: l5 g: [- e# S' f" M1 V: ?/ @! t
|
|