|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
7 ?2 r: \! f' i' c# Z& `- #include <uf_defs.h>
v4 C: d4 W1 }3 L$ K2 [+ ^ - #include <uf.h>
/ f9 ]+ G% k! w! ` - #include <uf_modl.h>1 m1 c8 M2 i3 ^3 ^! _3 y3 {& I
- #include <uf_object_types.h>6 ~; N0 d8 H: M B1 Y! I/ w$ _
- #include <uf_ui.h>
) F, Z; ]. b! M, J$ \6 h( \ - #include <uf_modl.h>7 x q I8 I0 w
- #include <NXOpen/NXException.hxx>. h* G- c$ i( _7 Z- E
- #include <NXOpen/Session.hxx>
' m# U; R3 ?8 t - #include <NXOpen/Selection.hxx>
, C2 c6 ^8 w2 `4 |3 J8 C - #include <NXOpen/Builder.hxx>
: h/ d# z1 U s+ r# a5 |/ }, T* q' t - #include <NXOpen/Features_Feature.hxx>7 D7 w5 G3 v1 [. _, o8 V! a
- #include <NXOpen/Features_FeatureBuilder.hxx>% E+ m. [; T( T) l
- #include <NXOpen/Features_FeatureCollection.hxx>7 `5 R3 }4 ~! L+ O& L. X" M% P2 O m
- #include <NXOpen/Features_GeometricConstraintData.hxx>
0 z, {3 e# X9 _! v. j; \ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) _5 A+ B: V1 H) l; \
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
7 q6 O1 M( l# p6 i% ]5 y - #include <NXOpen/Part.hxx>
% V% { P: E0 q! N - #include <NXOpen/ParTCollection.hxx>) T) K8 M# _' Q* D, N
- #include <NXOpen/Point.hxx>' _2 u: b `7 k
- #include <NXOpen/PointCollection.hxx>
4 N# z+ a) l( m5 q5 d - #include <NXOpen/NXString.hxx>
0 |+ F0 e9 x! D5 r5 E8 N) m - #include <NXOpen/UI.hxx>8 r* c. U% t) @# J, ?) a
- #include <NXOpen/Spline.hxx>6 P6 P+ G3 H0 p
- #include <NXOpen/NXObjectManager.hxx>4 U( d8 `6 B1 g2 M+ y% [
2 W* h: |5 c; D; I$ U; e( H- using namespace NXOpen;
* A' y$ ^7 K; s+ T& O - using namespace std;! L7 o) F5 L# B- f7 B; t0 l+ R3 g |
- 1 d- _( \0 M3 a, Z N z( B
- extern "C" DllExport int ufusr_ask_unload()
! i2 F( a% J2 L/ m/ T - {8 n( I2 }3 A+ ?" w1 u& }! R: `/ ]
- return (int)Session::LibraryUnloadOptionImmediately;
5 A" u( E0 o& q! v; X( @8 J - }1 a4 M8 ~& P y( k* m7 j, c% y
& t% K8 y) x% E' ~- static vector<Point *> selectPoints(NXString prompt)5 A" j1 I- J+ u
- {
7 {' }) E$ A% b+ c- y" e - UI *ui = UI::GetUI();$ ?0 W9 i( c6 H: h
- Selection *sm = ui->SelectionManager();/ j' a. e4 u6 F" V' x& B. e
- std::vector<Selection::MaskTriple> mask(1);; k5 Z" T( S' r. i- J6 H2 h4 `
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
( t% }! \1 J! c# X; w* C" I2 Z0 ?% a - std::vector<NXObject *> objects;
( N# N0 q/ K1 E+ J& T - ( f" y5 T4 Z5 w' m# y
- sm->SelectObjects("Select Points", prompt,# S( X7 ]5 T1 u, k
- Selection::SelectionScopeAnyInAssembly,( h7 K7 m1 V( E3 M+ S
- Selection::SelectionActionClearAndEnableSpecific,
9 ^7 Q0 B: t; |; o2 x6 S+ b - false, false, mask, objects);% P. {2 k" W6 B2 |# q/ e: S8 z
- 3 ? m4 e5 t( P- a7 i Y& n
- vector<Point *>selPoints(objects.size());9 J& w: J, Q/ I9 O' B* A
- for (unsigned int ii = 0; ii < objects.size(); ii++)
+ U6 y7 @% n1 N; D+ q - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
! S5 R. o+ |. N! [: Z8 A# i' s% A
1 b- j* v: V$ u+ ]& t. u- return selPoints;
_) Q; p$ O" @ - }
$ r/ g6 A6 X6 u - . x0 A; j G" J6 W& F' `& s
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
0 o7 m& B) N- h$ }& f - {+ G/ [; m7 G2 M0 g# |' c
- Session *theSession = Session::GetSession();$ }/ l% a% b% G" E. j9 s6 E
- Part *workPart(theSession->Parts()->Work()); Y; [) n6 j$ d3 y- |* L) [: _
- 0 t- o; _8 i3 e' [* q6 n8 O6 }- M
- Session::UndoMarkId markId1;. f' j# Q! j& x; H
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,8 X- K# ^6 m7 E. }* C
- "Studio Spline Thru Points");
& y1 O0 z1 }3 Z4 `
, w. ?( R8 h8 l1 Q: s- Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 L8 Z4 S) [- w
- & f" t* e6 }9 X, w% t- B* c( X
- Features::StudioSplineBuilder *studioSplineBuilder1;3 c1 M, z6 k& ]- ?- D$ \ i! P
- studioSplineBuilder1 = workPart->Features()->
1 |$ i& e' _7 v& H - CreateStudioSplineBuilder(nullFeatures_StudioSpline);0 P0 h1 U" _& J$ G) R
- studioSplineBuilder1->SetAssociative(true);# Y1 u9 l* B, R0 H' U, J/ y
- studioSplineBuilder1->9 w, h9 H$ h9 H" D% i& g, m! _ R
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 L# ~6 G& f" f) o* O5 e
- studioSplineBuilder1->- Z2 r1 }3 j% E( J" Z8 T9 A
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints); j. V; {$ f4 E& P
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
* M, d+ q; Y1 ]' D5 v! Q! l - studioSplineBuilder1->SetPeriodic(false);
+ x2 S" c* ^$ k - studioSplineBuilder1->1 S2 e( i2 s3 X4 E. o4 ]5 S) ~
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
. U/ t1 H% F2 m8 }+ I2 G4 l - std::vector<double> knots1(0);
. q" P1 ]5 O! } - studioSplineBuilder1->SetKnots(knots1);
! I& H+ y A; _& C" u+ O9 B. y! [ - std::vector<double> parameters1(0);
' e4 w* d7 m$ t+ l - studioSplineBuilder1->SetParameters(parameters1);
, N. u% p! O" { - Direction *nullDirection(NULL);
" x5 ?) H% b; j - Scalar *nullScalar(NULL);: _$ E8 g3 x, v2 U! O% U
- Offset *nullOffset(NULL);
- a/ L+ q/ O, N+ ]1 H+ o9 P7 K - 5 U4 K' F$ N/ @# x
- std::vector<Features::GeometricConstraintData *>
/ i% l( g" P4 J4 f7 n u4 k! f - geometricConstraintData(thePoints.size());
2 ?; ?3 ^# @+ Y2 y5 p" }# V
; | p5 H. f0 ~# J B/ t! ~# f- for (unsigned int ii = 0; ii < thePoints.size(); ii++) [$ b7 D- U" `4 W) I& U
- {9 I; d/ Y/ \; L' k. V: d' ^
- geometricConstraintData[ii] = studioSplineBuilder1->! I% A+ Z4 U" s' u1 W1 P, c
- ConstraintManager()->CreateGeometricConstraintData();
$ r5 k5 J3 F$ ^# S6 Z4 ` - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
Q- ?; X$ q0 n0 i$ H7 l - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
2 ^. ^1 c( O+ F& n5 K' r - Features::GeometricConstraintData::ParameterDirectionIso);
% u/ ^% @! J) O' o$ k% h% u4 n! b - geometricConstraintData[ii]->SetAutomaticConstraintType(
. ~0 r+ [6 N# d( Q* g1 q! q - Features::GeometricConstraintData::AutoConstraintTypeNone);% g" ]# P) e' I8 B
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
, |4 f* F, G1 d! d; k - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
, A+ p! Y. A( q! Q* j - geometricConstraintData[ii]->SetCurvature(nullOffset);
6 x3 V {0 h0 g" x9 i# P! g1 ~+ r - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- e1 q0 O7 ~3 _
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);/ h' }& K7 ?3 a9 \
- }) U/ \6 d% `. ^
- % v# m4 W+ O5 F) l- A0 J2 c
- studioSplineBuilder1->ConstraintManager()->SetContents(( z2 E4 {7 s; r+ q
- geometricConstraintData);
n: O* k. G- V+ I. H& b - : \9 j; V$ T: q
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();% s4 ]# h& x4 @3 h0 Q# Q& }
- Spline *theSpline = studioSplineBuilder1->Curve();
5 b. a- G+ q& ^* ~% S - , R. `* s7 `/ |( ?+ g$ P
- studioSplineBuilder1->Destroy(); t5 z* L4 I( ~" \% ~5 l
- ) j% J( K, q' s/ @4 k( n* f9 v4 [# @
- return theSpline;
3 e# G- b: s# ` - }
5 x) v y1 X2 L - ' n4 p" Y; K; g9 L5 R% v; m
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
0 O7 e3 {9 R8 v* e+ |9 a - {8 Q. G- v' D% V/ }
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
( v2 O4 c9 d. _ - if (!thePoints.size()) return; Y0 C+ s9 O% v2 p" e: ~
- - L# L+ d7 w0 X* T/ I3 B* P
- Spline *theSpline = createStudioSplineThruPoints(thePoints);4 Z1 s/ T7 H1 i! m0 k3 `. I
# B/ j0 K2 q# z& H8 B/ C- if (theSpline)
+ T0 f3 P" {' t9 r8 K - {
% z3 N2 c4 R: T( |9 u1 `1 K c - theSpline->Highlight();
2 A& _+ P# y2 H8 M4 C; X* k - uc1601("Studio Spline Created Thru Points", TRUE);
A6 N, ?# F( B3 P& A2 a - theSpline->Unhighlight();
0 q: j b( o" Z. m/ y. S a+ N - }
0 F1 o2 v8 h: u - }
3 K, Y6 H% M$ n
复制代码 h! x5 y' _# {1 _' a: L6 u3 g& A7 B
4 F' A! u* Z' i; Y
5 Y& N. b0 d) w
|
|