|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# S+ I% q3 F/ w$ K# p$ f) I
NX二次开发源码:通过选择点创建样条曲线
0 K/ q" U& |, k" T, G& r! ]9 [4 J2 F/ h+ E$ J3 D9 N
0 i7 e# K1 o8 p) L, k4 o- 9 x" }) e$ W! r6 k- z6 y: w+ t
- #include <uf_defs.h>
" E& U4 x6 z. P, ~1 v - #include <uf.h>
* _& ?/ r7 L9 m9 N+ e - #include <uf_modl.h>+ b* S0 p+ u c: u
- #include <uf_object_types.h>
4 m( n7 A5 f- s. r: g2 D1 A+ z - #include <uf_ui.h>7 ~5 B( O# x! S
- #include <uf_modl.h>; v: v* D! l8 p* F7 o8 i
- #include <<em>NXOpen</em>/NXException.hxx>* l( a4 O# Y& M
- #include <<em>NXOpen</em>/Session.hxx>
( m2 Z& ]- g; T' G6 c) G9 O - #include <<em>NXOpen</em>/Selection.hxx>
$ N$ w! [4 M8 ]& j& N! k. A$ g - #include <<em>NXOpen</em>/Builder.hxx>
1 M( Q( w! _% ~' n. I% X - #include <<em>NXOpen</em>/Features_Feature.hxx>2 M9 H' C( Y. J. B6 y0 h0 W
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
_' Y9 _/ |4 D7 p0 T - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>7 v& i- r( E* D5 f( g$ ^- S
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>3 O- ~3 t% @% C- p1 `
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>) @, z3 x+ e% S! l
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>0 v& X! a' l# X/ N
- #include <<em>NXOpen</em>/Part.hxx>
, a* f0 r7 C0 e1 d - #include <<em>NXOpen</em>/ParTCollection.hxx>
" f( E/ a+ j$ t/ X, m, O - #include <<em>NXOpen</em>/Point.hxx>
, p" ?* v3 e% S4 \4 G( W - #include <<em>NXOpen</em>/PointCollection.hxx>
; h$ W: m9 a) u6 G - #include <<em>NXOpen</em>/NXString.hxx>' H! W- E8 e! c2 E4 V J8 I ^6 W
- #include <<em>NXOpen</em>/UI.hxx>% G8 u6 C6 ?0 z- h3 D0 D
- #include <<em>NXOpen</em>/Spline.hxx>9 W8 K& N! W" N+ h& f
- #include <<em>NXOpen</em>/NXObjectManager.hxx>
% z7 ~" ^. n+ I; y - 5 A' P1 ?9 ]& Z8 c
- using namespace <em>NXOpen</em>;6 ~, E" |6 \: N# E
- using namespace std;
9 b+ E# @3 K$ R2 b& r i0 h
1 ?& l0 ~. }7 j& a' A0 b" {; m. d4 _- @- extern "<em>C</em>" DllExport int ufusr_ask_unload()
F" @. j; |1 z; |# C7 q1 l - {0 k# o# f$ H- r) {- ]
- return (int)Session::LibraryUnloadOptionImmediately;: Y! l3 ^- j) j. k3 M, Q
- }8 e" Y% A* {8 n! h7 Z# `
- 0 N9 i! d5 z8 X6 p9 h2 F) O
- static vector<Point *> selectPoints(NXString prompt)
6 K: `8 X# w. C N6 H8 D0 C - {& `. \, H( z9 z. ?" ^2 r3 L8 B/ ~
- UI *ui = UI::GetUI();
e: w6 n+ g$ F2 p6 ?7 l9 [ - Selection *sm = ui->SelectionManager();4 Y: N3 x0 j5 ~7 a7 S# ]
- std::vector<Selection::MaskTriple> mask(1);
1 A# m" h4 j/ a _. ~* k( ^2 I. U - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
0 V, v1 q$ P' B5 m7 j, y' D1 Q7 } - std::vector<NXObject *> objects;. j; \! X9 w: _5 k% u. ?
6 y) g) x" m* K2 K" S- sm->SelectObjects("Select Points", prompt,
, T$ r( a: j I5 T4 M: W6 Q# d; o4 ^ - Selection::SelectionScopeAnyInAssembly,1 j) u3 d9 D& D# q4 Z
- Selection::SelectionActionClearAndEnableSpecific,6 \8 J4 M& E+ p/ B k: c
- false, false, mask, objects);
& H( ^3 y: X& r8 v
7 ], I2 L' y" n% J6 O3 E# S- vector<Point *>selPoints(objects.size());
/ _1 f# W' J- }1 F1 z - for (unsigned int ii = 0; ii < objects.size(); ii++)
( h. J2 K# z8 X$ ?: t4 I; j - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ L7 r& l: r- \
; Z, c6 B- A0 i- return selPoints;9 t2 H4 ]+ A" T7 u; y
- }
3 {0 i+ k2 [% Q
4 G1 L" Q" t9 j; v- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
9 w# L; I! V1 k! m9 T2 V - {; N' j# G4 m+ b C
- Session *theSession = Session::GetSession();
% n. g* T9 W O8 q4 ? - Part *workPart(theSession->Parts()->Work());/ `9 X7 l& G! n$ T0 E" m, O
6 o' E, z* k, n# ]/ a8 z- Session::UndoMarkId markId1;4 h e, ~. U9 \) c P
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,! @/ R2 J; W; J7 ?5 s
- "Studio Spline Thru Points"); X/ y! ]) z6 ?! j; n. p
- / x* T/ ?; _& l+ T" u" z+ N7 x: W
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
* H" Q5 W G: J! ~" N - ( h$ T% T& c4 z) o
- Features::StudioSplineBuilder *studioSplineBuilder1;7 m; n/ v+ P" p3 Z" V5 P
- studioSplineBuilder1 = workPart->Features()->
; ~/ {; J1 m# X - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
1 K) B: I; Y, Q; }2 |* E - studioSplineBuilder1->SetAssociative(true);, J/ T1 n j# u
- studioSplineBuilder1->
! |; c: }7 `- d - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
/ B; x5 }& [7 q1 n) D( A - studioSplineBuilder1->9 p: H8 ?+ v& Y& D
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
8 D' {, T, i& j7 } - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
, _! E. T" u6 Y - studioSplineBuilder1->SetPeriodic(false);
: E& F' ~7 h/ o2 U - studioSplineBuilder1->0 H. S9 u/ u2 ~. I& t
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# E; q0 T2 y7 R2 f. p/ N
- std::vector<double> knots1(0);% E: Q' i; F& P
- studioSplineBuilder1->SetKnots(knots1);
1 x% `$ `( t- ?! e, z/ c( q0 p - std::vector<double> parameters1(0);/ a( k5 K! G, f! c$ ]
- studioSplineBuilder1->SetParameters(parameters1);
" B! D Q. U; z3 {4 D! n - Direction *nullDirection(NULL);
3 I5 B; s! h5 i0 k - Scalar *nullScalar(NULL);
, e( ]8 c8 b- t, r7 _2 A1 `% { @ - Offset *nullOffset(NULL);
8 ~0 t* F1 ~& Q- I9 S - ( U3 V) P5 l+ ^+ |( H6 d
- std::vector<Features::GeometricConstraintData *>
, q6 O4 }' R4 J - geometricConstraintData(thePoints.size());# H# P' s' D0 b
- " U$ v- M! l$ q8 K4 D3 k/ N$ @
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)7 w- x# c5 [) k' M# |* @0 N
- {9 e; T0 ^0 C, ~* w1 g) c
- geometricConstraintData[ii] = studioSplineBuilder1->
' y2 y3 M8 R8 k, l - ConstraintManager()->CreateGeometricConstraintData();9 k' U) V E- y
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
7 Q+ ]* M/ w* O - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
$ {+ P0 e/ x' c" c& N - Features::GeometricConstraintData::ParameterDirectionIso);- w: @; K( f! z/ N/ |. }
- geometricConstraintData[ii]->SetAutomaticConstraintType(4 j& F. b- ]6 q
- Features::GeometricConstraintData::AutoConstraintTypeNone);( U. T0 z0 O5 \) o% f* l. n3 S% p- d
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
0 e- Y, x4 c$ A/ Z" ~$ ~ - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar); J- W. u- N4 `- O
- geometricConstraintData[ii]->SetCurvature(nullOffset);' M3 t J! }* h0 c
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);7 K, c. V5 U8 R. |
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 F1 S& B9 P) V4 \% h$ d
- }* y) c4 B0 y( m' M, \5 q6 W7 Z
- ; p2 n3 C4 |" ]/ b' L3 C
- studioSplineBuilder1->ConstraintManager()->SetContents(
& _, Q& w7 ?* N8 j - geometricConstraintData);! V" F0 I1 I/ \9 i* M+ ] ~) q5 w
- 3 r* M) y5 Q, A5 v! E l$ T# j
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
) N2 B8 Z+ q7 E$ v# X, f - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
+ h5 x$ I) x* R( m: [
+ W: g) n5 j+ T9 {& {- studioSplineBuilder1->Destroy();. I b1 }( o4 I
# J. w. a: U# H- return theSpline;' Q: K' V9 C9 ?& c: z% }) g
- }& X. `3 R( k# l, W
- 2 l3 y5 B! U9 l a
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)! r+ Q1 l1 G- V& h
- {8 F" y. J) D* |4 b8 U9 f
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");% d# G/ _# _0 L
- if (!thePoints.size()) return;" E4 ^5 Y* {* i& L
- . [3 p) |2 K4 q! h" c. m
- Spline *theSpline = createStudioSplineThruPoints(thePoints);1 X# l* P# L F- u
; {1 M' K; S# g/ ?. n# ?; ]% H- if (theSpline), d/ b% Z7 @8 E( b; c$ d: a
- {& ^2 c+ w- S; s* x+ b
- theSpline->Highlight();
. ]+ P) ?+ C; N4 x/ c$ I5 n - uc1601("Studio Spline Created Thru Points", TRUE);
5 n6 g+ f A6 b - theSpline->Unhighlight();
- s& [2 @7 B3 y2 t7 p8 M$ ^$ }) V - }9 z# ^1 `0 Q2 C) {9 R6 i
- }
* Y7 t; L& H2 l/ F' D9 [. } - <p> </p>
复制代码
( I* e/ s1 C" H1 }3 { |
|