|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
0 d( s- K' g. _; h0 ]- #include <uf_defs.h>
2 m: B0 D/ j6 Q; v9 G- @ - #include <uf.h>3 [9 O( G* I% O8 }$ ]9 z8 q
- #include <uf_modl.h>
6 A9 E0 P& \) l! D) q' D+ ~ - #include <uf_object_types.h>
8 i# Y6 j1 H1 @( A - #include <uf_ui.h>
0 y& Q" ?) u, i( `: a) r) p - #include <uf_modl.h>
: Q# a' N( j) a7 t, W% \) V - #include <NXOpen/NXException.hxx>& Z) Y$ d+ ~, ?, O' S1 M- H
- #include <NXOpen/Session.hxx>* ]: Q* g- K. v3 R' \
- #include <NXOpen/Selection.hxx>, Q4 U( E/ U- x# D F' {0 n
- #include <NXOpen/Builder.hxx>
' c2 B$ n8 S; h7 X" v6 y/ ?9 W - #include <NXOpen/Features_Feature.hxx>- Z: g' g7 `# ?8 {8 [( z
- #include <NXOpen/Features_FeatureBuilder.hxx>& r! c6 S. H: g* T
- #include <NXOpen/Features_FeatureCollection.hxx>
/ d, _0 J7 w) |2 R6 X3 G - #include <NXOpen/Features_GeometricConstraintData.hxx>
& T# ?( }7 [8 W) R2 N) \( t6 y - #include <NXOpen/Features_GeometricConstraintDataManager.hxx> U5 ~( W7 \: {- H [$ R
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
3 \! _+ n2 f5 P0 e3 ]" [+ ^ - #include <NXOpen/Part.hxx>
; [% b+ i4 t( D+ e7 w" L - #include <NXOpen/ParTCollection.hxx>. V" e. M4 r7 H5 m8 q
- #include <NXOpen/Point.hxx>8 e( ]$ W" ^# p/ l
- #include <NXOpen/PointCollection.hxx>3 F8 O$ t0 Y1 \5 G4 ]/ H" A' p
- #include <NXOpen/NXString.hxx>
/ y L8 w- o, c( @ - #include <NXOpen/UI.hxx>
; Q0 }) B* u8 R) v* ]" F - #include <NXOpen/Spline.hxx>
) [7 h' Y \) V% r+ @, P: p - #include <NXOpen/NXObjectManager.hxx>5 Y: P& f5 s/ N# L0 @ [
- 9 ] c3 x* D" m0 T; n
- using namespace NXOpen;; `9 a J% d; X3 t& R5 c* B
- using namespace std;
. }1 ]0 ^9 T7 M
' h3 U+ Z, h- ]1 S }- extern "C" DllExport int ufusr_ask_unload()0 l+ ?5 W/ E2 K/ L D8 M3 c9 k
- {9 s O& Z8 H' }1 M
- return (int)Session::LibraryUnloadOptionImmediately;% f4 B1 _2 o5 s3 i" P: a2 Q
- }# C9 a' V6 M S: W* C2 n% I$ o# i; S
! i3 F0 S& @9 I/ }4 K5 i3 p, ?( t- static vector<Point *> selectPoints(NXString prompt); P" x( `% m( ~ P' t+ j
- {. k) G( X- r% x4 I0 T8 x3 `
- UI *ui = UI::GetUI();( C# s4 i1 h) ^
- Selection *sm = ui->SelectionManager();' {: G! M) U; p# g8 J
- std::vector<Selection::MaskTriple> mask(1);% i3 v3 ~; H) d4 I% a
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);: u( M d( r: G
- std::vector<NXObject *> objects;, V# E6 }4 U6 G; i
- 1 g2 L3 Y3 N/ ]: y
- sm->SelectObjects("Select Points", prompt," ^$ N$ {+ U; G, s1 N# G
- Selection::SelectionScopeAnyInAssembly,
* c& X9 l6 N2 j1 ^# @6 i - Selection::SelectionActionClearAndEnableSpecific,
4 } R' C4 `0 A - false, false, mask, objects);: a+ w7 K+ k6 b L# {* g
- + x. u( q4 R1 X6 t6 _0 _% b* X' \1 K6 I
- vector<Point *>selPoints(objects.size()); D, `/ {9 @7 d# e0 K' c& ~6 P
- for (unsigned int ii = 0; ii < objects.size(); ii++)% _' R3 D6 I/ p4 }1 [ V
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
0 u# h( b9 |: r' l. [0 I
1 U. w+ s, Y" R( s& M4 i- return selPoints;' P7 d2 K- d, w6 p, Z7 v
- }
: f, ^) c! E! `- R- Z, i% y
\% }+ E1 }. M: v9 @6 X6 ^( i- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). O: Y+ o& ?5 _0 u6 r U
- {
. d, U' a! U; x7 Q! J5 W: { - Session *theSession = Session::GetSession();
7 J) u3 Y k6 I8 z2 ]; ]% |* L - Part *workPart(theSession->Parts()->Work());: V5 V C4 G6 o
- ; I2 ~, Z( q& N0 b; [& q
- Session::UndoMarkId markId1;
3 z, N: r+ z+ q- c, _) E8 w4 e - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
) Z. }% ~) b/ b) ?2 V: E P6 U- _# y - "Studio Spline Thru Points");1 ~$ o. V, Q4 E. w3 X
- 4 _. Q: ]7 x9 i+ L/ y7 U6 r: |
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
. e, {# ?# r) r; R. ?$ [& d& O
9 v9 g; @- s( j- Features::StudioSplineBuilder *studioSplineBuilder1;
8 E) W0 g+ P) s1 I& I$ N; M - studioSplineBuilder1 = workPart->Features()->1 D, V" {: P& W2 q9 V) x
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);( }4 [6 y! L; N3 @" m
- studioSplineBuilder1->SetAssociative(true);- R' ^: T9 g7 \
- studioSplineBuilder1->$ i. L& H/ j. p0 G/ `' Q; e
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);: K6 e l, v, ~# r) t" {
- studioSplineBuilder1->
7 ~4 A& ]" T2 \& t) w* M- C9 [ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);. Q( n6 G# g% N: @% O$ s, S
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
; A; ]( J7 w6 k% ? - studioSplineBuilder1->SetPeriodic(false);
, |3 B" ^: f* ^4 y, ^" R - studioSplineBuilder1->
% }; T: O0 S; B. g% K- g - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# x* k' a9 A" p3 p; C
- std::vector<double> knots1(0);% n2 z0 c% x+ D4 S0 u0 m3 ~. C% D
- studioSplineBuilder1->SetKnots(knots1);' R$ [( O, \/ \/ J* m/ _3 u
- std::vector<double> parameters1(0);
5 s# F. D! `1 d* p - studioSplineBuilder1->SetParameters(parameters1);7 T. J0 ]& E5 ?
- Direction *nullDirection(NULL);
& ?9 G# E0 W- |# @2 \4 N$ E. R - Scalar *nullScalar(NULL);
8 q" f/ z4 G, Z3 c$ j - Offset *nullOffset(NULL);. d( z) h7 ^+ h3 D; O6 E
) i" R" n2 s0 O' a% X- std::vector<Features::GeometricConstraintData *>' I. q7 Z. N0 t/ M: b' W5 j, \
- geometricConstraintData(thePoints.size());
4 j" [' E3 V) d% }
1 }+ ]% j& Y3 g5 V9 w# p5 H" \- ~- for (unsigned int ii = 0; ii < thePoints.size(); ii++)- R# v( B8 K/ L; ]4 S
- {! a1 F$ R z8 u
- geometricConstraintData[ii] = studioSplineBuilder1->/ P" Z3 l3 j d& p, c
- ConstraintManager()->CreateGeometricConstraintData();
$ Q$ k# ]0 ~8 t$ k. \- H - geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 ^; e/ l+ K' D3 P
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(+ |: t' H s/ o+ U5 U/ r
- Features::GeometricConstraintData::ParameterDirectionIso);: U) y. a" P8 \8 B4 b- G1 E
- geometricConstraintData[ii]->SetAutomaticConstraintType(0 c5 e8 C$ h8 y# }; p) B, m# C
- Features::GeometricConstraintData::AutoConstraintTypeNone); P! J0 W( w9 h, y. q! Z$ L
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);8 R2 L* a) @; E, P
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
5 r r2 h1 u. c0 i - geometricConstraintData[ii]->SetCurvature(nullOffset);) Y! T) ~2 W6 c# B
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
. q3 x: D1 @! i1 U' C - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);$ g- j% t) U( F8 U
- }
2 V2 t' ~/ u1 ?5 ~8 p% V: u& v - : W% \% p. A3 S
- studioSplineBuilder1->ConstraintManager()->SetContents(
* t, A8 T a) ?5 M1 R# i - geometricConstraintData);0 @; A0 ?( M6 t
- & l; e& `0 u! a& F* M
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
3 \" ?) b1 N* N7 R ` - Spline *theSpline = studioSplineBuilder1->Curve();, r! T% F: P( u1 S! L
9 D9 @' c6 K6 D4 L) L- studioSplineBuilder1->Destroy();
. p; t+ j5 @6 L. n2 }& E6 ] - : ~/ U0 t" n, e0 _! u( d
- return theSpline;
6 B+ g7 k7 c: P& V: C! f3 [7 Y+ Q - }* e9 J- L7 c, `! o0 ^8 a
- ' w/ R$ U" J' S, {7 H: ~
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)4 z: ^' b: `/ c7 ?+ `
- {* }/ S: O& q6 d' m6 W0 }* O& w
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
& e; ?1 E% ^% I. _" A4 i - if (!thePoints.size()) return;! [- d, m5 o+ b# z1 f; J+ M8 d0 {% O
9 O/ u' R: [2 n% O0 v% x# I; V$ G8 c9 `- Spline *theSpline = createStudioSplineThruPoints(thePoints);
, W( W" @) `4 l
/ m9 V" x3 b5 p# n- if (theSpline)1 \" b5 M9 c% \# g; Y
- {
3 [# d- k' d1 G& h& Y - theSpline->Highlight(); D2 A( x6 I1 }% n ?" G$ M
- uc1601("Studio Spline Created Thru Points", TRUE);
; z+ y) d& d5 h2 v5 P8 s+ ~4 |& R/ ^ - theSpline->Unhighlight();' e7 `/ c, p+ M7 W# }5 i
- }
( v+ Z3 D1 A* J! V0 l0 A - }
9 {/ w5 Y$ q" b4 i4 w
复制代码 7 l, c1 ^ a( l0 X! p
6 `* a7 R$ I( }: z& f6 z3 u% U* T5 r! m0 W( w7 C0 Z
|
|