|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
; V7 C* v @) N/ ~( z* F- #include <uf_defs.h>
5 N$ v" Z# z( g; R4 } - #include <uf.h>
, W( s& H7 C; [4 t" B3 m - #include <uf_modl.h>2 R4 B" ?: }7 |1 b( o: L: E. r3 ?% a
- #include <uf_object_types.h>
| f/ @( n8 ?6 {' H1 \. A- [ - #include <uf_ui.h>
, b; u7 m- g$ A$ S' A3 r2 F; ~ - #include <uf_modl.h>
9 Q3 I# V' h/ B7 X. f9 w$ s4 d - #include <NXOpen/NXException.hxx>( o1 g) [$ J% }% x- U+ ]) D
- #include <NXOpen/Session.hxx>9 l& j( j& L8 K4 ~2 R7 g7 ~
- #include <NXOpen/Selection.hxx>
B) f3 K9 B4 R1 s- h) G8 F7 U - #include <NXOpen/Builder.hxx>' h, S" G6 D5 `/ q8 H
- #include <NXOpen/Features_Feature.hxx>
, \1 Z, s" B4 m9 T( i' F$ c - #include <NXOpen/Features_FeatureBuilder.hxx>
5 A* D( h6 |4 \3 Y1 F2 w! n6 g - #include <NXOpen/Features_FeatureCollection.hxx>
/ ]2 l* o3 f- _" u& N5 ] - #include <NXOpen/Features_GeometricConstraintData.hxx>: l N/ j% t6 F; t
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>' y* r9 i- \. ^/ C/ t, ~
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
$ K2 S- Q2 c( _, P2 U& ] - #include <NXOpen/Part.hxx>$ |) [; N- `( y& u8 `/ d
- #include <NXOpen/ParTCollection.hxx>0 G9 @9 C/ c5 ?$ w) [+ \- k9 X
- #include <NXOpen/Point.hxx>: Z* U* O, ?! v& }$ F8 I/ e: {3 f! f
- #include <NXOpen/PointCollection.hxx>
) s5 f- k' c. _ - #include <NXOpen/NXString.hxx>
: {+ L! E- \. x# e - #include <NXOpen/UI.hxx>( ~" z# O6 x( }: x
- #include <NXOpen/Spline.hxx>3 F) B: G- O7 C' g
- #include <NXOpen/NXObjectManager.hxx>- D/ r9 V* e" ~" Z5 ]6 a* u" [
+ ]+ w- {9 a. B4 f% ^ q4 ~- using namespace NXOpen;9 Q, ^0 x% q* \
- using namespace std;
+ n5 s9 k# R8 T( T A/ N# M# G - 3 ?7 S9 @7 U( D4 d
- extern "C" DllExport int ufusr_ask_unload()
3 s0 o9 [3 G; R8 j v$ m - {' q) N1 p. P: ~/ I) A3 Q
- return (int)Session::LibraryUnloadOptionImmediately;# O, n: M( K; t& P/ {4 l8 s
- }
& X2 F5 d* W3 A* L& m9 p' K
. W% u @6 J! n9 u1 @1 Y- static vector<Point *> selectPoints(NXString prompt): h* {4 e8 n* o5 l9 w+ ^5 W
- {
7 N4 F2 g2 ^& J - UI *ui = UI::GetUI();
# I9 o0 {& t& X# Y0 S+ o( v - Selection *sm = ui->SelectionManager();0 h/ x- v( v; ?9 D! \: |2 y
- std::vector<Selection::MaskTriple> mask(1);$ K" ~3 y# ]3 ~- L7 F) W
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
3 m/ F+ j3 N0 E" x, W - std::vector<NXObject *> objects;( H; h3 b5 I( R1 O
- / t& M. a7 \, g2 X/ l$ g
- sm->SelectObjects("Select Points", prompt,
( {+ i& B- w+ l. f+ ]% |2 f# x - Selection::SelectionScopeAnyInAssembly,
1 j5 N# X" s: t6 E - Selection::SelectionActionClearAndEnableSpecific,
+ r' J( o, I7 L5 M - false, false, mask, objects);
- S5 ?& ?( B: I, T8 p. X
* S0 X, ]2 ]; h0 s" w4 V5 W- vector<Point *>selPoints(objects.size());
* Q' A: O& V6 G, R" v/ z! d - for (unsigned int ii = 0; ii < objects.size(); ii++)$ f. p2 |( u1 D( w4 D
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
! p/ k& H3 N0 }8 f" q - $ n: Z5 B$ f4 k, W$ e3 w
- return selPoints;
% h* ? G! L2 }" O - }
z0 p4 ]- G5 \ X% W
5 ]3 E E/ w5 t% Q9 y6 S# w- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints), V# d- X A. D w+ E M
- {
9 f3 U1 K7 w* b0 c7 ~" E - Session *theSession = Session::GetSession(); U% N* @0 a9 s& V. u* F. e. n& @
- Part *workPart(theSession->Parts()->Work());
1 G, @3 P1 E2 m3 ^" A - ; V# K# J: t* j# m
- Session::UndoMarkId markId1;9 ?: \6 |2 z) E
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,. n( M6 H% J: t7 H' i% B
- "Studio Spline Thru Points");1 ^% A7 s! k; O( f) j s" R2 C
# X4 x6 Y6 j0 W2 H- Features::StudioSpline *nullFeatures_StudioSpline(NULL);) D4 L' [, t& X8 n
0 p% U/ D& d- @# D4 J8 |- Features::StudioSplineBuilder *studioSplineBuilder1;4 p" i7 m3 |, Q% Y# p3 \- \' m% t
- studioSplineBuilder1 = workPart->Features()->8 X0 u3 {) f1 u. D0 v# X: M7 I
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
# b% _# t. \3 `4 @$ L - studioSplineBuilder1->SetAssociative(true);
3 O* \7 Z$ n$ {% L - studioSplineBuilder1->
9 m! W, x" r* r5 j ] - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
) _" X' W/ G$ p# g P - studioSplineBuilder1->
; C, _7 g Z; w, j; x7 ^. M - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);6 r' [% D( G! M, D4 O
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
+ g+ o/ {& n5 g7 f$ v6 ] - studioSplineBuilder1->SetPeriodic(false);
/ f7 S% |! Y) C, i( I+ w& p - studioSplineBuilder1->5 }! l' g/ [/ U8 }6 X# s
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
2 r6 `3 |- d3 X# @% w7 a1 s5 B - std::vector<double> knots1(0);4 n0 B) t& t$ w9 y* ?6 y0 k/ o
- studioSplineBuilder1->SetKnots(knots1);4 C, D; c# J7 L }8 j$ _
- std::vector<double> parameters1(0);* m8 ?0 P8 s1 p1 f9 c
- studioSplineBuilder1->SetParameters(parameters1);9 ^/ R" n1 I1 _+ u5 ?
- Direction *nullDirection(NULL);1 J4 Q* B* u' X& y9 f1 j
- Scalar *nullScalar(NULL);0 h3 i( s1 R5 D% g- @4 L0 \" Z
- Offset *nullOffset(NULL);
# o: N! D, i0 d3 m - % y+ ?# U6 x2 ~+ _# U3 O! Z
- std::vector<Features::GeometricConstraintData *>
- |4 a# i" n5 w* P - geometricConstraintData(thePoints.size());
& ]+ r2 q0 P# v6 Q, b - , L R! u8 d. c+ \- V( S
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
- ?0 h4 H6 h' U$ c7 J" n- z& x - {) k5 N+ i- H( y4 P6 Z) f" L0 f
- geometricConstraintData[ii] = studioSplineBuilder1->
' \! Z- a, T |: R: g% S1 }# _ - ConstraintManager()->CreateGeometricConstraintData();
1 X7 c/ z& V1 E5 P, c3 M - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
/ u6 z7 I: |1 q$ e4 z8 y) G - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
: a* i: b8 H3 t9 Q% @) z - Features::GeometricConstraintData::ParameterDirectionIso);
0 e9 h' ?& h0 Q" S' \, O0 D/ c - geometricConstraintData[ii]->SetAutomaticConstraintType(
" E4 V' g. m, b' ]* X& K" r# B - Features::GeometricConstraintData::AutoConstraintTypeNone);
" i5 V/ Y% W& c, R/ s) H, H - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
' S. \( d5 `5 s$ E/ K$ J- u( w( h3 U - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);# R' G- N+ u9 S8 k3 @# b
- geometricConstraintData[ii]->SetCurvature(nullOffset);$ q& ~% n* `3 K9 U9 R; k
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
; y$ V( ~6 ]" r: k p, M - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);. o9 o' U" Z, S- n
- }
7 I* S4 I8 d! }5 z* L/ H; T
. }. _6 I7 W" w ]2 J- m- studioSplineBuilder1->ConstraintManager()->SetContents(
4 T) M- B" U! w* |, w% Y - geometricConstraintData);: H5 ?* \ e/ b: [) ?3 L
- $ D) ^+ N1 |- [0 a
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();$ w1 f5 x$ ]7 C! i
- Spline *theSpline = studioSplineBuilder1->Curve();" L e' p; R5 G+ L/ I( {/ L; j
- - e5 G8 L2 K5 A6 a) \# N% q
- studioSplineBuilder1->Destroy();5 \6 x8 w5 ?+ g9 }2 U
- # d3 X* g. q6 ?8 \9 |! q" M& b
- return theSpline;9 S& E/ M5 o3 U9 [. c6 }
- }
3 J+ @* R/ R- s w - 7 ^2 N* T4 w3 W+ r8 h& N- v6 b
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
# m) g" T" w J& o! i - {6 U. p- y" x9 ] \; Z
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
" w) C( S* H# a G2 F - if (!thePoints.size()) return;& B7 i5 j) |" c$ {. h% z
- 9 f, o: E" A4 y, K' I3 |* T) i- Z& k
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
1 J, G/ U/ x, p, r, r
9 X# x4 v3 f+ z: x4 {0 N' e- if (theSpline)
; Z0 o: d4 l2 {. @0 b! V - {2 q5 S3 n3 i; |" ]6 E4 K* R
- theSpline->Highlight();
E" W& C3 h& x0 j7 @* ] - uc1601("Studio Spline Created Thru Points", TRUE);3 s$ N2 e# b9 e* w' u: @0 ]5 ~
- theSpline->Unhighlight();
5 H& {, R- ~( X" x0 o7 w - }1 I* ^' s/ ~. i
- }
" a4 h. M1 H" I7 x- U0 ~
复制代码
; ?1 V* K/ H6 } x% B! u
6 U# s$ ^7 Y5 n0 ] p9 F; s* `" Q% \; G; O6 {. I @+ c
|
|