|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
7 ~6 t( P4 J+ R& t3 f- #include <uf_defs.h>
, p3 i% P' h+ E7 P - #include <uf.h>
2 M) Z% j* ?$ {* g' n - #include <uf_modl.h>
. t; r4 f- \% i3 r% h6 m - #include <uf_object_types.h>, D8 d0 w; X9 j0 K' c# W* F
- #include <uf_ui.h>3 X) Y1 e8 E2 n2 l2 H) w& f
- #include <uf_modl.h>
! ]/ Q' H- G$ Y! F& |3 ~0 f$ g" G - #include <NXOpen/NXException.hxx>6 C9 P4 Z3 X1 `" s
- #include <NXOpen/Session.hxx>
% ~. H' [1 p( s( L/ R - #include <NXOpen/Selection.hxx>
# w8 ?! ~) i& v0 E1 P - #include <NXOpen/Builder.hxx>
4 t: t: D* ?: q1 x1 S+ x' s* D - #include <NXOpen/Features_Feature.hxx>
/ K4 O% @/ [# c( d0 b6 b' ? E( u - #include <NXOpen/Features_FeatureBuilder.hxx>
2 ~* E4 l2 K5 w. \- N1 J( c - #include <NXOpen/Features_FeatureCollection.hxx>+ n1 K: f' E8 B# k; ]
- #include <NXOpen/Features_GeometricConstraintData.hxx>7 t3 B9 j7 v0 \4 V" ~: |7 h" |" p8 m
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>$ m: }; B: ?- z' C4 q5 A* w
- #include <NXOpen/Features_StudioSplineBuilder.hxx>+ F/ Q9 K7 }: q' p9 b# `
- #include <NXOpen/Part.hxx>0 u- u0 H: [/ k
- #include <NXOpen/ParTCollection.hxx>
2 H9 F8 g- P/ M$ p6 H - #include <NXOpen/Point.hxx>" F, h8 j2 ^$ S) [
- #include <NXOpen/PointCollection.hxx>0 H7 j) N9 R& D" L1 A1 ]
- #include <NXOpen/NXString.hxx>
' V( W* b! e6 ^% K7 r! Z. Z - #include <NXOpen/UI.hxx>
, a$ A: I. J& W7 _/ B - #include <NXOpen/Spline.hxx>, D2 E: z, D! | L
- #include <NXOpen/NXObjectManager.hxx>
) C! l5 u' x6 ^" b5 p, M - 2 J2 A6 Y! ~. E9 c9 D% T' l0 c
- using namespace NXOpen;
& r I0 U: ~) Y1 O7 W - using namespace std;
6 `$ u O1 Z6 ^, H/ \& @ - + D8 x7 O% M; j
- extern "C" DllExport int ufusr_ask_unload()9 i8 ?0 n; p: Q* a# K
- {
3 J/ f S% v. l- n- h4 V - return (int)Session::LibraryUnloadOptionImmediately; j7 F6 j5 e5 ?/ q" o1 @
- }
Y% U& t3 q9 r7 m - 6 v9 p" @/ l# j
- static vector<Point *> selectPoints(NXString prompt)8 r; x) X: w6 d( [$ k4 w1 |
- {2 U6 E% @! H+ A/ t
- UI *ui = UI::GetUI();) e) K* z7 ^8 M% n# y& u
- Selection *sm = ui->SelectionManager();
2 g5 a; O0 M% U# _/ C - std::vector<Selection::MaskTriple> mask(1);3 p3 w2 a$ U. n
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
5 {8 F# \, o- z4 E3 ?/ K - std::vector<NXObject *> objects;. V) t5 _1 S5 q- }% O0 Y5 T
- : n, o( i8 k9 U% ` Q, M
- sm->SelectObjects("Select Points", prompt,4 ~0 m$ b+ Y2 z- S9 }5 q/ q, m
- Selection::SelectionScopeAnyInAssembly,
& V- p) o$ I n - Selection::SelectionActionClearAndEnableSpecific,* `: ]0 Q# K) x; u/ c$ l
- false, false, mask, objects);, w6 J' e1 O; c _9 o+ [/ t0 j$ s& y
- 6 n4 M1 I' T: \( _4 K$ c/ t
- vector<Point *>selPoints(objects.size());
6 R m: e1 I$ t1 M5 u) A" F - for (unsigned int ii = 0; ii < objects.size(); ii++)* J6 f. P3 I5 z6 G% j
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
- Q8 j: ?. ]/ ]3 q3 t8 }
) _+ x1 Z4 A/ B3 F7 I, d- return selPoints;
: `% U% Z2 @1 ~! R E3 ]0 d - }! i9 _) M( Z8 C' z( s
4 U8 h T: R z. ^4 C* @# i; `- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
; [, g# ?( A+ ~9 ^: n: I - {
' E0 I1 ~- J. V1 s7 v - Session *theSession = Session::GetSession();
$ b6 ?+ T9 W+ |' G2 X - Part *workPart(theSession->Parts()->Work());
) d1 {0 [9 s( [- |/ C
' _, b( u j/ c4 X1 B; C9 K- Session::UndoMarkId markId1;8 n5 | W8 [7 q1 ~. l/ R% r
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
8 ?3 V3 a0 O! G+ |/ _ - "Studio Spline Thru Points");
0 k7 l2 e+ M; r - 0 Z% z% a# N# r) u6 Q6 i
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
) f& R9 k5 R5 ~
$ g" L; v% v9 U2 o& }4 n B2 @% U- Features::StudioSplineBuilder *studioSplineBuilder1;/ Z; {' \" f' f9 y% ?7 b& I: C: E
- studioSplineBuilder1 = workPart->Features()->% x q# f7 C$ a d! s7 _( }1 R
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
8 a+ Z8 Q l; w - studioSplineBuilder1->SetAssociative(true);) u; @6 N$ q. h5 X j7 K* R
- studioSplineBuilder1->+ r1 P+ n3 Y. C% F0 E
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);! s9 I1 x$ @& P- a1 P5 l1 z
- studioSplineBuilder1->) R; R" r, Z3 \6 T$ [; f, Z8 Z; @
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
3 T; V9 E! a4 O8 F8 G# u - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1); [' i9 O# ?5 f+ q) N$ c& O
- studioSplineBuilder1->SetPeriodic(false);
1 q W a2 Z! _, H - studioSplineBuilder1->7 p1 ^8 v9 Z- M R3 y) ]4 f5 T
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);; m$ E1 f- B* W5 b: z+ l
- std::vector<double> knots1(0);& p5 G) K" B; m- G: ~& b5 Y
- studioSplineBuilder1->SetKnots(knots1);* u! L/ h% F) }- }' x1 g
- std::vector<double> parameters1(0);5 P# q0 P7 n' x4 ^/ y* w$ N
- studioSplineBuilder1->SetParameters(parameters1);1 b* o7 T/ P8 P1 c5 D3 Z0 x
- Direction *nullDirection(NULL);5 X% s: O `5 W0 j r' A* |" f; Z
- Scalar *nullScalar(NULL);8 J5 Z3 d, d3 C1 Q
- Offset *nullOffset(NULL);- T) Z) M7 B/ [/ s
- ( {$ C/ q0 w. c. k
- std::vector<Features::GeometricConstraintData *>: n: \# Q& @1 G2 L
- geometricConstraintData(thePoints.size());
% r- M: U. \# v - : f& D0 ]& q4 f# M
- for (unsigned int ii = 0; ii < thePoints.size(); ii++): p3 G8 X# ~ I' G- H
- {2 J: X. n+ q- {& V; V5 ^6 V
- geometricConstraintData[ii] = studioSplineBuilder1->, b; k5 P' _0 J. V9 Y( r
- ConstraintManager()->CreateGeometricConstraintData();
' c' y: O! S+ `% P. C- {; ?; C# x - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
7 O, Y' S! q( s" ^7 s+ R9 S3 { - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
4 f7 z$ o: ~5 z8 ^% }* R - Features::GeometricConstraintData::ParameterDirectionIso);
2 \3 t4 X$ i" [: o7 ? - geometricConstraintData[ii]->SetAutomaticConstraintType(
d8 U! N& L( o* {) s - Features::GeometricConstraintData::AutoConstraintTypeNone);
( {# E& T- @4 k - geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ `/ Q' ^) Q* F4 `/ |# d. j
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* ^* z2 {( H6 R p o9 M0 ^& H7 ]. D
- geometricConstraintData[ii]->SetCurvature(nullOffset);4 L0 h5 w5 E% d! H# C' r1 K* F1 d
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);9 u. T- J$ j* w2 N; G. c- W
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 `) X9 X" _3 P& {6 G9 f
- }! ~8 V6 A: d1 e& s5 U$ d/ Z$ V+ {( w$ w
- 5 ^$ f( ^$ |& j9 F6 L
- studioSplineBuilder1->ConstraintManager()->SetContents(
2 m& K8 B- g5 f4 k/ M# }6 S4 ^9 } - geometricConstraintData);
- ?0 i6 X8 ]: y1 ^5 A
' Y% q8 Z0 m7 J- O* K; |8 i1 Y- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();! j9 @+ m# \5 u: |
- Spline *theSpline = studioSplineBuilder1->Curve();8 G7 v2 V e5 n7 N* Q
- / T2 o2 b2 z1 `6 Z; {
- studioSplineBuilder1->Destroy();
& b6 E. u0 T4 T8 W
9 ]' I8 v/ J( a8 n' ^7 N, U _& i- return theSpline;8 U: e1 c, s' n
- }
" h4 J% t1 o* ?. x) A& u, g6 i
6 m+ g) X+ P& m2 q- B j2 W, H- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)- V$ E. i* C. A* Z$ E; r/ e6 ^0 W
- {
+ U9 _7 n5 B$ ^5 p) C4 Q5 J - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
* m( H, W0 x/ s( r - if (!thePoints.size()) return;+ M0 _& h4 m S4 `
- & q0 s% v4 ?" V
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
8 U9 v3 n7 Y {5 j+ i
" Y) L# C3 W: O, J1 ` ]. \3 q/ Q- if (theSpline)
6 y, K4 ?/ O5 u$ n5 M - {% K3 [$ x; J9 X7 N. L
- theSpline->Highlight();
: q6 a: c1 \% ?; h8 b3 A - uc1601("Studio Spline Created Thru Points", TRUE);: C& ~4 j8 d' D2 E# N
- theSpline->Unhighlight();! i" j# P' T( N, E3 s. I+ C
- }
6 _: Z: E+ e$ _9 f$ C1 l* Q; I; I1 K - }
Y. M8 w [; s4 x1 b1 C
复制代码
9 f# p' v& j% c+ _! s9 X, Y7 q/ j4 W2 C2 d
) Z/ J5 r* E/ q) c* N) G. Z3 b
|
|