|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, V0 q2 Z/ `' @6 c- S/ E
NX二次开发源码:通过选择点创建样条曲线
* r0 `1 A' E4 B Z* p; n! f7 m; @6 |1 X0 a$ l) z& a- b' D f' w
4 @( `' i/ g5 s X% B1 B
- # [8 ]" s9 H0 _1 J
- #include <uf_defs.h>
$ h7 A8 z; q5 b# d) b% \ - #include <uf.h>
3 @$ d- b! ^: I2 g+ e6 f$ ?' g - #include <uf_modl.h>
, o+ l# v% G! }; \& ~, O$ \ - #include <uf_object_types.h>
6 u1 c# E% T+ q( x% r5 P( B - #include <uf_ui.h>2 Q, {/ I5 x; E/ `$ T
- #include <uf_modl.h>) Z: M8 J7 r+ d; ]. G; U& Q! Z( R) N& [
- #include <<em>NXOpen</em>/NXException.hxx>/ r3 X% I# t; w' @% p7 |# T- j
- #include <<em>NXOpen</em>/Session.hxx>
) G! G+ p- p U! u7 m - #include <<em>NXOpen</em>/Selection.hxx>3 E! R/ O0 l; K) y, b
- #include <<em>NXOpen</em>/Builder.hxx>0 c5 K. e, o2 N4 d$ R: u \* S
- #include <<em>NXOpen</em>/Features_Feature.hxx>. S+ \! R. _1 f0 m( `9 l9 o/ l9 q
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
; M7 }, @' |. T& Y - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
- W9 C3 X* H7 } E5 S0 ]' k - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>( g: J) J8 D; }8 e& I# b: s/ b
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
, F- e. [& v/ ^9 I( i - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
, U! o- n% _* g# n# W) v - #include <<em>NXOpen</em>/Part.hxx>" \- I$ l: u& U2 h
- #include <<em>NXOpen</em>/ParTCollection.hxx>1 c1 t) k) D' `7 a
- #include <<em>NXOpen</em>/Point.hxx>( [8 `4 R# a3 O; Z# H# u
- #include <<em>NXOpen</em>/PointCollection.hxx>, { N8 w+ O4 L3 y
- #include <<em>NXOpen</em>/NXString.hxx>
. c% w; ^) U) [- i - #include <<em>NXOpen</em>/UI.hxx>
; G" ]9 w* J/ X) P+ [2 U2 ]5 A6 T - #include <<em>NXOpen</em>/Spline.hxx>
: }1 q& L& k. K9 R - #include <<em>NXOpen</em>/NXObjectManager.hxx>
: Y& M3 O8 `& } - 7 d4 C0 Z8 O0 g9 b' ]
- using namespace <em>NXOpen</em>;( Q Q1 ^- Y6 Y! Z9 T+ m
- using namespace std; Z) S1 _0 l( a2 u: ?
- ) H# n. }$ [0 q d
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
8 _( N: x1 R' F* I' n% j @+ @' b. ^ - {0 d, H) X4 L8 P0 ~0 \; `' Z& T+ O
- return (int)Session::LibraryUnloadOptionImmediately;; S E' ~0 I! i# y. k8 c6 k
- }
+ A; K* A6 T' j: ]+ E$ f
: P# S% n' D0 l2 e; i2 L- L; M6 O- static vector<Point *> selectPoints(NXString prompt)3 x/ c; p/ r; r9 x% K& R8 v5 ~# M
- {
. L8 `- W4 J( j# j% F2 S4 i - UI *ui = UI::GetUI();( u" w" p& t8 {% u9 n' H
- Selection *sm = ui->SelectionManager();
6 v B) \/ ?: k/ F- v0 p - std::vector<Selection::MaskTriple> mask(1);/ `. A; {3 a7 s! C2 _
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);6 H! q' p! k/ O T- X
- std::vector<NXObject *> objects;
) W5 E/ ?! S. x
7 |9 d/ s" O& l6 }! ]' y$ N* U- sm->SelectObjects("Select Points", prompt,
4 i1 ]! A. v* Q% `, J. f' z - Selection::SelectionScopeAnyInAssembly," R; C( w) }# s2 \: H7 q
- Selection::SelectionActionClearAndEnableSpecific,
- g7 W- U3 ?- V- O' E+ N - false, false, mask, objects);
2 g/ }5 U3 H. s9 M - 8 y! T8 H& R' X! J, v& T
- vector<Point *>selPoints(objects.size());
' y8 m5 S2 D- ~2 f$ a9 k - for (unsigned int ii = 0; ii < objects.size(); ii++). t/ T# s# ?1 f- J3 c- N5 s
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
+ C! N) K8 e }
( N. h- ]2 i$ g' Y' |4 b- return selPoints;
6 S2 ~, T1 H1 E) _* \ - }3 d( H7 e% S. c
; J/ o/ ~2 A( C: s& m, `- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)% a& Z8 U6 Z3 J' r. j, a1 v4 `
- {
$ t; a1 d+ f1 x5 w - Session *theSession = Session::GetSession();
J$ _2 [) B2 S8 W - Part *workPart(theSession->Parts()->Work());. b# {: X) d; }3 U5 |7 T p i
- 5 L! Q4 p1 Q6 r! w/ F
- Session::UndoMarkId markId1;
1 T% D5 t# w% @/ r7 A: q/ ? - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
: i6 j) Y, C* o) K4 m/ |" j6 T - "Studio Spline Thru Points");) y2 O' L5 g* ^. ?' W0 {
- $ L" C+ a+ b; a
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
: L! I5 b$ j" e) a7 V8 | - ' b- h) T, V. k8 k
- Features::StudioSplineBuilder *studioSplineBuilder1;. t; p% c+ g9 [6 Y! _8 Z7 q
- studioSplineBuilder1 = workPart->Features()->. V+ ?* Q2 v7 `* ~6 c6 d
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);# `, K6 W2 T7 V f. r0 E2 `! N2 O8 B
- studioSplineBuilder1->SetAssociative(true);
3 U8 A) p2 }) S1 e: ^! f2 t - studioSplineBuilder1->
* W' M: d1 j0 P - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
9 f0 r2 d+ A: ~+ B0 B - studioSplineBuilder1->- |) w) I- ]* X- `7 S& B" _8 F% c; J
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
. ]0 M. C' R' H' ]* m7 @ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! K2 m/ l- i( S& `: Z
- studioSplineBuilder1->SetPeriodic(false);8 x" c0 z1 t' U) K" Y
- studioSplineBuilder1->% Z( r7 O2 K; w% T
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
b3 p7 h8 o9 U. v. ]' ]$ Y0 T - std::vector<double> knots1(0);# L; @) P* P( @4 g$ n# U' t! Q
- studioSplineBuilder1->SetKnots(knots1);
4 @3 K6 Q6 F9 B3 C' I - std::vector<double> parameters1(0);9 L% j3 o3 ?1 L) q6 q
- studioSplineBuilder1->SetParameters(parameters1);
! O; q5 g8 G" R D - Direction *nullDirection(NULL);
6 f- _: b }( l - Scalar *nullScalar(NULL);
3 I& L9 z: _3 V2 @9 _( S4 u - Offset *nullOffset(NULL);- }* d( K: }. _9 T, a/ M h1 V
! B3 N) A7 Q: [$ _5 i' s7 d- std::vector<Features::GeometricConstraintData *>
i* w5 f) P# l! \2 n - geometricConstraintData(thePoints.size());9 Z. P" T5 i3 I
- 2 w e3 T$ a8 Q8 C
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 d4 U: a# M8 X
- {) ]& C0 h! L& Y
- geometricConstraintData[ii] = studioSplineBuilder1->
0 \( w/ v4 Z. w& `# S! R - ConstraintManager()->CreateGeometricConstraintData();% v; I+ [5 }6 O6 E9 H, f8 _
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 U" m) ?" A% w/ W) _
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
: b, F. C6 i9 [& s - Features::GeometricConstraintData::ParameterDirectionIso);- x, \+ q) g( I7 C! h; z
- geometricConstraintData[ii]->SetAutomaticConstraintType(8 X* y9 G2 f# ^9 V/ W: Q$ U
- Features::GeometricConstraintData::AutoConstraintTypeNone);
" t1 m; l# `# C( x - geometricConstraintData[ii]->SetTangentDirection(nullDirection);" ~. D$ M# d6 v7 V0 S! F, J! ^
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
6 r4 U* ]1 y- A, E: Z5 X - geometricConstraintData[ii]->SetCurvature(nullOffset);% C0 u j: Q* [: y( j( h4 t. D0 J
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);2 f4 ^/ q- t, P) n6 W" A
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
5 h% H0 E+ v1 l; P/ H) \% A - }9 s6 n! E0 Z" f! H
- . F% s/ T F2 x3 G. @
- studioSplineBuilder1->ConstraintManager()->SetContents(
6 `# x2 R$ v& g6 }" d+ ~6 o6 H3 e - geometricConstraintData);
+ T$ \4 k) D" B - " T3 r" j( {! a! E0 R
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
! ^$ Y4 J+ z* m& L" L6 @ - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
L5 s+ F/ L+ G+ s& g - : N, f! R; w; p1 d; Y( ]
- studioSplineBuilder1->Destroy();
3 O7 i/ @, @4 j( B: p - $ \# ?6 F2 ~' v" a
- return theSpline;
. N0 l7 x8 N; ]1 j# }2 J- _ - }
) R6 Q2 X. {; w! s# l
6 Q4 i. G' N3 r3 `$ e- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
! j5 u0 J2 U1 r, F9 J$ R7 B - {- \+ j6 r' k' \ H8 T0 U' R' O
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
/ y2 z& d% F: R6 c0 X! d% e7 p5 N - if (!thePoints.size()) return;) n, k. b- t0 u0 a( [- T2 f! @2 c3 Y
- & \+ z/ O, ?$ d6 G; |
- Spline *theSpline = createStudioSplineThruPoints(thePoints);. w' {& l3 R$ @6 z$ i% N! y
- ) ~+ O2 c. {( M+ ?+ j) b
- if (theSpline)$ O1 k. G7 L( @7 K6 e" _2 a
- {
, t$ T1 x$ V ~' ]4 X3 J8 C - theSpline->Highlight();
' e% c6 E; V9 L - uc1601("Studio Spline Created Thru Points", TRUE);
$ H. q6 v9 p2 u5 b& w - theSpline->Unhighlight();! z# u% @0 Q& u2 x& M8 @9 D
- }& z1 ^: j* H4 }
- }% S" s3 k0 ~) R4 I- _/ W6 H
- <p> </p>
复制代码 : T- j6 e: ^2 @% Y$ o% h# i @& H
|
|