|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线' }6 `7 @: n) B) `
- #include <uf_defs.h>
# ~2 [0 u8 W+ ~ - #include <uf.h>& R+ I( N; J# `6 q
- #include <uf_modl.h>
% `+ {: w4 v) y) ^3 K - #include <uf_object_types.h>3 o A$ T4 J( k+ B$ [
- #include <uf_ui.h>
; j Y' I! |; _8 @2 h! ` - #include <uf_modl.h>
* k- K4 }7 \" C% C J% t - #include <NXOpen/NXException.hxx>
7 _+ d, Y! i4 V# \ - #include <NXOpen/Session.hxx>% S) g7 ^3 |1 ~5 x! D- l' m+ P
- #include <NXOpen/Selection.hxx>3 y' N* H7 h5 |& I* Z3 W( f/ f
- #include <NXOpen/Builder.hxx>2 s4 t- T" M% B9 N
- #include <NXOpen/Features_Feature.hxx>
9 [+ J( b% v' E+ u9 b - #include <NXOpen/Features_FeatureBuilder.hxx>
! j6 U0 | f! n - #include <NXOpen/Features_FeatureCollection.hxx>% r6 q+ U; K$ l7 F- M$ Y
- #include <NXOpen/Features_GeometricConstraintData.hxx>5 }' ?$ X! N5 }
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
1 y1 k4 S4 W8 v' \7 m - #include <NXOpen/Features_StudioSplineBuilder.hxx>
3 X) k6 B5 T7 t, j. r - #include <NXOpen/Part.hxx>( P1 k& Y1 f! j: Y: @5 u
- #include <NXOpen/ParTCollection.hxx>. [, E! R9 @4 o$ _7 A
- #include <NXOpen/Point.hxx>$ i0 x8 \# ?7 G; f
- #include <NXOpen/PointCollection.hxx>
7 I& S x* B% t) c' E0 `- O4 c - #include <NXOpen/NXString.hxx>
1 q c# H& y# t( o+ H; j - #include <NXOpen/UI.hxx>$ Q3 K* K5 ]2 }
- #include <NXOpen/Spline.hxx>; k* ~# p( A- G) J4 Y: R$ i6 A
- #include <NXOpen/NXObjectManager.hxx>
: h8 _1 m1 U% U2 U1 X
. h+ i4 d! w0 N5 L/ l- using namespace NXOpen;
( K3 J/ X+ ?, K5 {* x; S9 { - using namespace std;6 ?) m! M6 F' K: y
9 s3 B4 c1 ]( u9 {- extern "C" DllExport int ufusr_ask_unload()8 d8 B* @( f3 i8 W
- {4 M2 N' a. l3 `7 b
- return (int)Session::LibraryUnloadOptionImmediately;3 w1 a1 |2 ` \4 s; f
- }! M3 M0 Z$ t+ t- E9 ^
- + m( }5 _$ U: B- @' z Y
- static vector<Point *> selectPoints(NXString prompt)
: @3 t. ]" b1 A/ |) p9 ?0 s - {
6 u y% ~- Q5 N1 j; W - UI *ui = UI::GetUI();
7 }7 b4 U, m+ b% H - Selection *sm = ui->SelectionManager();
' ]; v3 e& L2 h$ r/ P0 t - std::vector<Selection::MaskTriple> mask(1);
* d; W2 x5 M2 m - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
* v* h( y% [% O- |6 M - std::vector<NXObject *> objects;
/ [* b. q* U# Y1 V/ {9 E6 ] - - Z" x; r/ e; T) X9 t; p! L
- sm->SelectObjects("Select Points", prompt, e7 `) V5 t( x9 Z9 q
- Selection::SelectionScopeAnyInAssembly,' ?" x) `- o7 Q/ _8 d0 E. s4 s
- Selection::SelectionActionClearAndEnableSpecific,: w# r- b3 j$ d/ A+ N N
- false, false, mask, objects);: t- P/ ?9 K) |% j$ u9 z$ V' d- w
% K; g8 T8 Z! `) R- vector<Point *>selPoints(objects.size());
! q1 }3 s4 M; Q! t+ }; D - for (unsigned int ii = 0; ii < objects.size(); ii++); G# S2 J0 t5 _: H
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);6 D* ^1 _/ P$ ^
* S2 t3 u+ _- ]9 k8 V8 M( C! W6 X- return selPoints;
E. E$ q/ m F5 d9 M) F - }$ l0 M5 [, t" t( w- w
8 Q- f0 A3 H( a: J& u5 o+ G- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints) z. t( R! W! Y) J5 c1 q; f( H! ?
- {) b6 {) `! }+ {+ R7 f. H
- Session *theSession = Session::GetSession();
1 \6 K$ T6 Y9 a# _( Q( ?5 Z - Part *workPart(theSession->Parts()->Work());
# Q( T2 @/ @$ y, i - + \. N5 r( p" O. K
- Session::UndoMarkId markId1;& h) Z/ T( q8 i0 ~' K/ i
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
( f% n5 S; r5 W& m" O: t/ H - "Studio Spline Thru Points");
9 T/ K6 z6 Q; w( U f8 U: R0 ]/ E
- s/ N D- j; I- x$ @- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
# `0 i [# @7 w7 f9 K8 W6 N$ t
% Q2 R$ L. ^: L' a1 K6 f4 @+ I% n- Features::StudioSplineBuilder *studioSplineBuilder1;
# d; r/ {2 ~$ D; \% a2 w" c - studioSplineBuilder1 = workPart->Features()->
; X& ]0 B! f* m: A [ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
5 N9 d, b& Z! S5 i: O4 ]5 ` l - studioSplineBuilder1->SetAssociative(true);
* y5 L, o' W I; e - studioSplineBuilder1->
6 q/ N6 f' U5 ~$ C - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
c% j* F3 _ t$ s: g - studioSplineBuilder1->% {2 h. U+ N. v* `+ k( |
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);& h* K2 N! z% |3 G+ `- N8 ^& a. f( _
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 i2 h% H/ y! m8 s( c! n2 L
- studioSplineBuilder1->SetPeriodic(false);# Q8 d, r) k. \0 a: C
- studioSplineBuilder1->2 c1 @; D7 J& ^( ~ h, T I% }
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
! G3 r; P0 G; r0 p* B% a. F7 [* |! { - std::vector<double> knots1(0);( D9 [. {0 v$ h! g! _5 @
- studioSplineBuilder1->SetKnots(knots1);/ x2 ^/ a; H. \$ X+ z$ n' `* j/ B
- std::vector<double> parameters1(0);+ }5 u/ \1 d; y& G% a
- studioSplineBuilder1->SetParameters(parameters1);
$ k$ l1 _9 T- O; {% j( I! M - Direction *nullDirection(NULL);
% I: }* Q3 B& Z7 ^) Q; x - Scalar *nullScalar(NULL);0 u9 }1 @1 _% g& }" O& D6 e5 o
- Offset *nullOffset(NULL);# l' `% b7 I9 h' F# \ U9 \8 A
- $ p& z; G" ^, {4 D1 d1 }* ]
- std::vector<Features::GeometricConstraintData *>/ S7 z! S0 t# B2 h0 E* h! E
- geometricConstraintData(thePoints.size());' l4 v. u, m) f! R1 E
- 1 H b! ]9 u* K: Z! l
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
: f2 S6 @2 {' d0 _4 A0 \ - {
0 n' {4 x" ?+ y' S+ \' p5 f+ X2 B6 w - geometricConstraintData[ii] = studioSplineBuilder1->
7 x- P2 i8 B" } - ConstraintManager()->CreateGeometricConstraintData();" U+ z) h; U, n, q3 [1 `
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
$ M* w1 t% r1 t- _$ c - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
: K5 M4 r& P% o - Features::GeometricConstraintData::ParameterDirectionIso);
( l$ M0 p* j! e# \% E4 o - geometricConstraintData[ii]->SetAutomaticConstraintType(
o* y: [. H/ \) m - Features::GeometricConstraintData::AutoConstraintTypeNone);
) Z8 G! _/ M/ ]' q4 |4 O { - geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ Z( B( }. Q" l0 n, P. }( L3 o
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* v9 @5 S/ D/ z8 P3 V3 w( R2 k6 H
- geometricConstraintData[ii]->SetCurvature(nullOffset);
( \2 s9 [( ~6 @6 U, p) e - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
: a' O: u* I. n F' Q% I8 u - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
2 }, P( z* `& D* }, h1 I! ?9 P' K% D3 j - }' L0 {4 g+ ?9 e8 `+ ?; V, c
- , Z3 m' G1 P4 f3 L1 l4 P8 w
- studioSplineBuilder1->ConstraintManager()->SetContents(
" I' |8 j5 y1 P# q% a - geometricConstraintData);" _" ^+ b. [ o+ K: ?
/ G3 ~% ^0 Z: R6 _2 y6 ^- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();9 Q+ g5 A- q) V7 |
- Spline *theSpline = studioSplineBuilder1->Curve();
9 y, c) v, }+ c- K$ ^& V3 w+ _1 Y/ X0 b `) S
" t& J1 F1 Y9 E1 x- studioSplineBuilder1->Destroy();/ `+ I$ I6 ]6 o$ V! L
$ [/ A) e3 i3 w7 O- l- return theSpline;: D2 F3 B1 T# n7 O
- }" U) J$ B! n: ^$ u# S7 m l/ {
- , G% M* T5 @5 t: M) d& \- h
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
# e! a8 ?" x& M - {) |4 K$ m1 W% {1 P
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");' h# @+ j, v# _/ N
- if (!thePoints.size()) return;
) j' m( m# }( p7 e7 f% f - % l, l! I+ A" l& @3 r, Q8 I8 g
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
) p3 H( f0 o5 N) s ` - 5 d' z/ K! m8 X" Z" r! y# x+ D9 x
- if (theSpline)
/ }5 k- L% A5 C5 L) W3 D5 I - {
0 \8 D) }) N6 s7 b F2 Z( f - theSpline->Highlight();! K* @: X0 ]& Q& I8 D
- uc1601("Studio Spline Created Thru Points", TRUE);
7 G8 l3 t0 C: ^ - theSpline->Unhighlight();
m N: B4 P7 d$ S+ [ - }
2 ~4 G% t) h( s% E0 { - }. F9 e3 G/ C$ j2 c
复制代码 " ~0 F' {2 _/ e, }% Q
# w% G2 k j d% A
- G* `7 \8 t( l8 [1 j; d1 v0 C |
|