|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* {; D* S7 D' g4 aNX二次开发源码:通过选择点创建样条曲线
* b+ b r2 `6 e% I+ W' Q# V# D( l& U' z& t. k. \5 q
r0 N) F6 y4 z, j3 f
+ Z! {* o. f2 }* ]& q7 k- #include <uf_defs.h>5 D. a A- I" }6 `, w' ?
- #include <uf.h>
$ k+ }6 z# @! Z; \0 U# M% `3 n - #include <uf_modl.h>
# A7 Z5 L( C$ f2 T6 [ - #include <uf_object_types.h>
* f+ D! _. x9 j4 k4 K6 O" q7 g* ]4 J - #include <uf_ui.h>
$ f' b3 O$ H1 h5 w3 x1 i - #include <uf_modl.h>
) u4 X( v) |8 k8 O - #include <<em>NXOpen</em>/NXException.hxx>& F4 T G; m4 ^/ A
- #include <<em>NXOpen</em>/Session.hxx>+ N& T7 J, c, M! Z6 G
- #include <<em>NXOpen</em>/Selection.hxx>
5 K( r. b+ z; e4 w, O G- q) [ - #include <<em>NXOpen</em>/Builder.hxx>
2 {# f6 H( I7 H; | - #include <<em>NXOpen</em>/Features_Feature.hxx>* {$ S4 ^. B2 a' r2 l( ]5 t E, y. @
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
9 m" F, q$ \" D& ]! i - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
/ u1 f, T6 {1 E f% v - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
1 w) P- o# L. E" M - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>- w" M, n3 d1 \; T* _7 F: U
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>3 K; B( ] n/ T1 u" V3 t0 I8 U& g+ M
- #include <<em>NXOpen</em>/Part.hxx>
8 ] G/ X! o1 G& |5 F3 ~/ Z7 W - #include <<em>NXOpen</em>/ParTCollection.hxx>( ~; O) v4 {! l* A2 [ z
- #include <<em>NXOpen</em>/Point.hxx>3 `' ], C- y, @8 x( J
- #include <<em>NXOpen</em>/PointCollection.hxx>% b9 l8 Z6 s/ f1 G
- #include <<em>NXOpen</em>/NXString.hxx>4 O9 @& K& J, R# @
- #include <<em>NXOpen</em>/UI.hxx>% N* |+ w' b7 ]7 C
- #include <<em>NXOpen</em>/Spline.hxx>4 Z( X' L9 r8 G' }- i
- #include <<em>NXOpen</em>/NXObjectManager.hxx>
2 L" j# }, j6 M$ M2 b+ N% j
" r3 |% D6 Q9 }4 r) n- using namespace <em>NXOpen</em>;
6 r3 F) T) N N7 B - using namespace std;) X* d; o4 |1 G) }( f2 E
- $ P3 r& N. y, N. \0 d
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
8 L6 @8 r% }3 L4 |. K - {+ S9 d' S1 A: `" u5 c9 i7 [# K+ ~5 p
- return (int)Session::LibraryUnloadOptionImmediately;
- V; R Q: A3 a! G/ p% j. N - }% [6 T1 L# G% F m) O
U$ L# i( L* g, ?- static vector<Point *> selectPoints(NXString prompt)# Y1 N$ a% P6 o& A3 |" B* c
- {! b8 l, c3 c4 V/ D
- UI *ui = UI::GetUI();
s" ^* d' g- X! L9 Z y/ | - Selection *sm = ui->SelectionManager();; S5 f+ m/ E) z) S5 }# {
- std::vector<Selection::MaskTriple> mask(1);5 C) d4 H N+ ~! v% D! Q$ K) W
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" K, _8 j, S' T7 T
- std::vector<NXObject *> objects;
% g8 b) Q1 z7 y, L
. D0 z; g- A. v n' M' O: [! R- C- sm->SelectObjects("Select Points", prompt,
# k+ M1 q$ \& E: J' ` - Selection::SelectionScopeAnyInAssembly,4 M" t4 j( f# i* b+ `
- Selection::SelectionActionClearAndEnableSpecific,
2 F9 t G; l5 I; e. n5 e - false, false, mask, objects);& w4 r3 O9 f% E3 W
- 3 O: W7 e! T& V2 l8 }5 A' F# B
- vector<Point *>selPoints(objects.size());
0 C( i" N# B# P P- v - for (unsigned int ii = 0; ii < objects.size(); ii++)
0 [5 q- A+ [" M - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);8 w% v! U! x4 r% \3 ]
- , |' [. p' | Z# U6 \
- return selPoints;
[- ^: B) A8 B, `2 x3 p/ t - }/ n. N8 A- \0 C$ k, a: v; E
0 d8 y! h* f( S3 R7 z5 Q$ ^9 T- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
$ n; Q& i2 q) q! y - {
4 O* Y' h" b! R# u0 G - Session *theSession = Session::GetSession();% l7 Y( `3 u, X: q A
- Part *workPart(theSession->Parts()->Work());; a" @! |5 w9 t) r
, D" |! @- S( q2 Y- Session::UndoMarkId markId1;
1 ^# w4 F' M0 V8 }$ j( }6 } - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
- q" l9 Q! D$ o$ C - "Studio Spline Thru Points");( X2 i( |3 c3 }2 D; ]( B$ N8 A1 D5 X
( s- B* p6 I! Z; Y2 F- Features::StudioSpline *nullFeatures_StudioSpline(NULL);' r/ N& Q3 w3 z9 F
- $ P8 s! {. a2 [- h/ b! {: m6 K
- Features::StudioSplineBuilder *studioSplineBuilder1;
6 J& F c* z0 s; F6 Z - studioSplineBuilder1 = workPart->Features()->
& b" `, n2 f c* R9 D - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
9 `8 P* w) s1 r) Z; @4 v$ r. n - studioSplineBuilder1->SetAssociative(true);+ j6 \0 J' Q8 w/ s. I
- studioSplineBuilder1->
0 Z: C' O3 `7 {/ w. a - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
8 m* ~: ], Z9 u - studioSplineBuilder1->
% m, p( ~" l7 J6 Y# H3 A - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
5 {2 c) p) j, \; k8 `8 ^$ N - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
; e; q4 |* @% Z { - studioSplineBuilder1->SetPeriodic(false);" P9 I0 b2 y" c7 M$ k
- studioSplineBuilder1->% I# v: K# u4 l. `( ?# e* \
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);9 Y9 C# ~. V; n0 S7 A# Y1 R3 A' ]
- std::vector<double> knots1(0);* o' w. p' C9 k3 c+ m1 l
- studioSplineBuilder1->SetKnots(knots1);
- p$ @6 R; q5 V( Q e. J; r: d - std::vector<double> parameters1(0);
0 r6 j. ?, }8 h# H1 F! X5 t - studioSplineBuilder1->SetParameters(parameters1);
# P# u1 h" R9 G1 \7 Q2 `; w - Direction *nullDirection(NULL);
1 g5 l! A6 z* t6 h - Scalar *nullScalar(NULL);
1 l/ j! J: c0 w, W! \ - Offset *nullOffset(NULL);2 r% o% w0 Y1 f+ Q
- ( _1 J) N4 E, ]& ^ W
- std::vector<Features::GeometricConstraintData *>
* N3 d& T8 g+ g" E" ~3 P - geometricConstraintData(thePoints.size());
6 X( n' |+ D4 d8 l! P* `& t
; q9 z- ^! ?& W. i7 i- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
/ J$ p& E3 b8 r; F - {8 B. r) V+ f7 j7 W" s* ?
- geometricConstraintData[ii] = studioSplineBuilder1->
0 C* B0 C1 b/ F! s3 W# y - ConstraintManager()->CreateGeometricConstraintData();! d, w$ U* F$ }1 G u" x8 N4 T
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);' q* O6 h8 L! j# S z- A
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(9 a9 S) ~. T0 }" P2 L
- Features::GeometricConstraintData::ParameterDirectionIso);/ L* H2 d( f2 _* v' H: f4 M
- geometricConstraintData[ii]->SetAutomaticConstraintType(
: I0 T& T. ?3 _6 Z! P1 [. f - Features::GeometricConstraintData::AutoConstraintTypeNone);5 f" `( I3 q* M. ~6 }7 n3 R: ~" O
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);) d: e0 s& |9 F, @$ B8 Z
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 v/ {* ~: O5 i# p
- geometricConstraintData[ii]->SetCurvature(nullOffset);
$ P! Y) y8 Y, M - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- b# e6 s' n; j6 Y* ?6 R+ y% o
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
7 R2 F$ r* N ^: B4 A6 c - }
6 Z1 h! i1 p. u& D3 j - 5 `6 p) ? h1 X" I+ C% E
- studioSplineBuilder1->ConstraintManager()->SetContents( A/ n! [3 [ _# [; U7 r9 V' H
- geometricConstraintData);
$ Z. ^2 g2 S' A* _$ L2 W0 ~ f
. F9 p' n# M+ C" E3 F- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
1 w+ w4 ]4 X, q# @9 } - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
* S) F/ k- z" N9 Q4 `
3 u. ?' r; n z! u- studioSplineBuilder1->Destroy();+ \8 z+ ^% i, U* v$ c p2 }5 h/ a
# l* p0 B( y2 W: n6 R- return theSpline;
% I/ A: j7 Z2 H8 I. ^% K) s! Y - }
V+ W3 \$ E& A4 \& e9 S
0 W& o; \) X2 R/ c3 h% u- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)7 F* W4 ]; A3 X; {# ~1 k
- {% w9 n$ g8 X1 t: b
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");3 \, o+ a; l: _' G' e7 u
- if (!thePoints.size()) return;/ N$ n6 S9 s9 u# m+ W2 s# ~% l* A
- I( I6 v! |+ M1 H: q7 n& q
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
5 d) f- I2 A6 a# |. \ - 7 m; n( X* R7 m) G' m# Z
- if (theSpline)
/ j/ H$ p$ P; E - {/ }: J* h( H1 e* H1 d
- theSpline->Highlight();
5 C# @0 P+ o; {$ \- }% F. ^5 O - uc1601("Studio Spline Created Thru Points", TRUE);8 d7 k& y6 Q9 B: t
- theSpline->Unhighlight();: w' O* V2 K3 X2 s3 }2 P) _
- }
- b4 i# K$ [' t6 B9 m x4 Z; F! ] - }
4 w9 j: g3 f. S' |1 ?/ o; U - <p> </p>
复制代码 ! K) L: o/ B b9 `8 i
|
|