|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
( k: j, V3 c3 [" ]2 F1 Q- #include <uf_defs.h>8 x" ]4 s7 o. P* e6 b) S& n `( x
- #include <uf.h>
% J7 o( Y/ q1 P/ {# C5 Z3 B, ? - #include <uf_modl.h>
) Y$ N8 x% X9 l$ L - #include <uf_object_types.h> ]7 e) E, l! v' t
- #include <uf_ui.h>
9 t& Z4 g5 K9 K1 ~- ~$ h) ~ - #include <uf_modl.h>0 D/ m8 \ \8 E: t! [6 O( {' a
- #include <NXOpen/NXException.hxx>
u O' r5 O. w z; E - #include <NXOpen/Session.hxx>+ Z9 ~; R# ~* o- e" r
- #include <NXOpen/Selection.hxx>
# s* c$ M- c! H - #include <NXOpen/Builder.hxx>
7 [; `' Q. z! t/ `! B f( Q - #include <NXOpen/Features_Feature.hxx>
) |9 [2 o) y8 D. |8 U8 ` - #include <NXOpen/Features_FeatureBuilder.hxx>
6 u! Q2 _# Z0 Z+ x - #include <NXOpen/Features_FeatureCollection.hxx>" l+ F; `- |! |
- #include <NXOpen/Features_GeometricConstraintData.hxx>& q1 O+ M7 C( y6 v% x5 J7 |) `
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>, P. R0 l) B Q0 f& V
- #include <NXOpen/Features_StudioSplineBuilder.hxx>9 [! f/ i/ c1 K; j5 q+ a
- #include <NXOpen/Part.hxx>' e3 v# b! G# b2 O5 k& L' B/ O
- #include <NXOpen/ParTCollection.hxx>
" j9 I; v6 \5 a/ u1 z8 i: M - #include <NXOpen/Point.hxx>* I: W7 s' n+ R, a
- #include <NXOpen/PointCollection.hxx>! z4 ]7 O9 }3 e) D# ~+ K9 V! ?5 K
- #include <NXOpen/NXString.hxx>) P; {* k$ d/ x- ?
- #include <NXOpen/UI.hxx>! _: n2 l- Z/ U8 p7 P
- #include <NXOpen/Spline.hxx>" [# T/ q# f7 W& J8 x' B d8 A
- #include <NXOpen/NXObjectManager.hxx>$ D, E; m1 H' T E7 X1 Q7 C. F
+ _; e1 W: E/ V, s0 K* U- using namespace NXOpen;
1 }5 W. c6 c. ?9 _ - using namespace std;- j7 P, n& m0 c# V
F) F- b) n* p- extern "C" DllExport int ufusr_ask_unload()
+ O; }& y: ?$ b% F+ O - {
% O6 P. o; s" X% @! v+ h - return (int)Session::LibraryUnloadOptionImmediately;
& J1 L, Q' L3 M9 {# J - }
, C/ F4 O& c) j* Y' Z5 q/ n, ~; m - / l- n q7 ? v. t7 G. {0 w/ v
- static vector<Point *> selectPoints(NXString prompt)
6 T) I* ~5 H' Y$ q6 ]+ w- r - {
. p* V- m" F+ s, ^: t - UI *ui = UI::GetUI();
% v% z% }4 O. J6 e' Q - Selection *sm = ui->SelectionManager();
/ D% J" p3 n1 o# J2 N - std::vector<Selection::MaskTriple> mask(1);
/ l' \; R. U8 P/ O, N+ f - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ f1 m+ @' M; h$ ?5 h: t9 B, D4 R' Y
- std::vector<NXObject *> objects;. N1 ]# ^- L( ?5 U3 F) K0 U
' f7 z* s& J1 z( H/ P$ W- s! q" p- sm->SelectObjects("Select Points", prompt,/ N1 V# j7 F0 n" }1 D Q% j: p
- Selection::SelectionScopeAnyInAssembly,
J1 p' u' G/ l; ^; s0 l' d5 p2 P( U - Selection::SelectionActionClearAndEnableSpecific,
7 S: x* d: E4 l, }& K6 I& Z# S - false, false, mask, objects);
7 H: x3 x- I7 |: C
2 `4 a3 P' C5 q+ p$ u G% r- vector<Point *>selPoints(objects.size());) G% Q6 Z$ x% s0 p8 s8 K
- for (unsigned int ii = 0; ii < objects.size(); ii++)# {8 @5 G9 o. C2 R3 r: Z
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
, i6 ?1 }! W: d9 H) g$ ~ - . f" F0 Y, B% g+ N# G) K
- return selPoints;. H1 \* A% l3 ?7 |, ~6 v4 C
- }
% z: d2 Q' ]. W5 G6 { - 7 y5 N) O& i% F9 G3 \ i
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
1 ]6 Q( Q* y. _; p: m; R - {
* T: d+ ^: b: C9 |$ w" f. m - Session *theSession = Session::GetSession();
9 ~, J ?, k, `% i - Part *workPart(theSession->Parts()->Work());
1 ~5 v/ E8 e9 O6 _3 A# _
1 U) t N& k2 G% p( I9 y- Session::UndoMarkId markId1;
$ C2 m2 r% ~; z2 \& U - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& a$ T- Z8 X; A) c d3 j
- "Studio Spline Thru Points");* H. V9 |- j7 M( A
6 R( X/ e& g- Z' [% a. V- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
& I0 O$ C4 m' w# M4 J) [! V
; t( b h7 Q% U% w+ N' I' H- Features::StudioSplineBuilder *studioSplineBuilder1;, p1 `5 R4 u1 C* F# k
- studioSplineBuilder1 = workPart->Features()->
! N: [# O) \+ `8 C) e - CreateStudioSplineBuilder(nullFeatures_StudioSpline);8 C# N; t. ]* K u1 D, t) [
- studioSplineBuilder1->SetAssociative(true);
6 z8 A2 ?- u( V% G0 Q: k - studioSplineBuilder1->
3 B' M1 n+ r& N - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
! M6 G0 h3 K3 n - studioSplineBuilder1->, n# R- S4 q/ P4 u/ u- E
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);$ O7 c. \# t" ^# z7 Y) A X
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
3 y$ D% ]! b6 ]- `' d - studioSplineBuilder1->SetPeriodic(false);( C: i; A9 u6 O1 D# i
- studioSplineBuilder1->
& J; t) X, M2 w0 L- a/ I* a - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
$ L X/ u7 Y& i) B - std::vector<double> knots1(0);
5 b0 P8 L; k1 ^$ p - studioSplineBuilder1->SetKnots(knots1);
& I5 }1 {" T3 N! i& ?* z4 r- G - std::vector<double> parameters1(0);
4 _5 Q7 r* n7 `1 K7 l9 E. e9 Z - studioSplineBuilder1->SetParameters(parameters1);! o) \8 B2 d2 @* k1 F2 a
- Direction *nullDirection(NULL);
9 Y( m9 f* M" v- O6 j - Scalar *nullScalar(NULL);
j4 H$ d: {% F; m) r - Offset *nullOffset(NULL);
1 Q. _0 y5 |! r% d) G/ x4 l7 U
8 X; ?, R5 K( Z5 G5 e% M& g- std::vector<Features::GeometricConstraintData *>: T U8 t5 y1 E% A4 J
- geometricConstraintData(thePoints.size());: x( G" A' s* c& ?6 v
- 7 h& t! y* `0 ~) X
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)2 U4 D1 ?( j& g% ?! q
- {
: w6 u, C" ?* X) } U - geometricConstraintData[ii] = studioSplineBuilder1->
L0 z, @$ M- ^) ^& o6 e; { - ConstraintManager()->CreateGeometricConstraintData();/ f6 I& N$ Q! P y- x* j
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);2 ^+ a& U% I2 ?5 ^0 T3 C
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
6 k1 ~2 A; T+ i9 {& q; R - Features::GeometricConstraintData::ParameterDirectionIso);$ `! E. k. \: T3 C% X# b/ j
- geometricConstraintData[ii]->SetAutomaticConstraintType(
" P3 S6 ^/ D$ V% |5 O$ R( m* M - Features::GeometricConstraintData::AutoConstraintTypeNone);/ p% C( N4 h7 t
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
' N, ]- a4 k) c, U o1 C - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
* m7 o( h& U4 o6 g8 p. F g - geometricConstraintData[ii]->SetCurvature(nullOffset);
$ [. w8 u5 `. S+ k6 z+ W& P- R - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
; W/ O; s+ K/ G, M5 q( k; I - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 Z( m1 n; j. S0 H0 ~" t X& _
- }, p0 o: ?; g1 b& i1 H4 [& X* `
- 5 n0 e6 _" r+ e; m
- studioSplineBuilder1->ConstraintManager()->SetContents(. p5 U L1 @* z+ K# V$ K6 t
- geometricConstraintData);
; {& J0 ^, K' ]9 o0 @0 J% j& | - % r; A2 n1 G2 F/ U
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
& p% M" b# j0 X6 W! U5 V - Spline *theSpline = studioSplineBuilder1->Curve();
% [% g% z8 [7 t( t) [ - # b/ G% @7 g6 i4 w5 [/ E
- studioSplineBuilder1->Destroy(); X7 w5 \' h# }9 ]1 x7 z8 Q" I
- ; o ]# p& n) b/ {& k
- return theSpline;, Y' F# O1 y3 L( A- Z" {
- }* ~% Z* {3 N7 [5 Y4 ~, I, A
- ' @; ]+ D1 L2 }/ _# Q$ y
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
! T, d* ^" J8 ` - {4 g+ G5 w1 G. y/ A# O+ E2 M
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");; Q2 u/ |6 V) H* s: q( f) N1 E
- if (!thePoints.size()) return;3 [' F/ l1 u. {/ `% ^& n
- ) B9 @7 z& d/ E9 d+ F
- Spline *theSpline = createStudioSplineThruPoints(thePoints);' t N* P( r/ b% }2 ]
' d. l: j) P6 z$ g$ q- if (theSpline)
. a' [7 `; ?) O4 u& M - {6 y/ X% d+ ?( z- h/ L0 P! a
- theSpline->Highlight();
+ }3 a) p6 C& _1 E7 P - uc1601("Studio Spline Created Thru Points", TRUE);7 s5 l2 J# \! c8 f
- theSpline->Unhighlight();
1 l5 _$ t% m6 e" W; J - }7 Y3 G' J8 v; r" J# T0 o
- }% `& ~6 O& V8 _2 k) [( q, a+ ?4 j* U1 `
复制代码 & n6 r p3 k% n; H
' y, u$ ^+ u/ J6 Q
6 Z+ D; z4 D/ c4 h# m
|
|