|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线+ o; f7 V' r. M+ K8 c4 l* |$ p
- #include <uf_defs.h>/ k" w4 T* }) i; P7 R$ H0 n9 |- G! a
- #include <uf.h>" D/ M8 _, j9 I) ~$ L4 g
- #include <uf_modl.h>" V! K/ J! [6 y! J
- #include <uf_object_types.h>
D' ?, m; ~& O. V3 a# \ - #include <uf_ui.h>
$ C) M* u! l# r6 e - #include <uf_modl.h>. ]3 K7 R) f% {/ y
- #include <NXOpen/NXException.hxx>
Z* h# O# Z& @5 D3 y - #include <NXOpen/Session.hxx>, [: U2 a! j+ n
- #include <NXOpen/Selection.hxx>
0 K/ {9 l* t' O& P# h7 A" \ - #include <NXOpen/Builder.hxx>% d. z/ a- n* |0 S) J! U/ t
- #include <NXOpen/Features_Feature.hxx>* Q1 ~$ Q; _ J; q/ y' z
- #include <NXOpen/Features_FeatureBuilder.hxx>
4 v7 ]$ a% \; R2 e( F$ f3 C) a - #include <NXOpen/Features_FeatureCollection.hxx>+ s4 C+ s& ?- s }
- #include <NXOpen/Features_GeometricConstraintData.hxx>
+ ]+ v, Q- |! b1 g9 e# E$ P - #include <NXOpen/Features_GeometricConstraintDataManager.hxx># m6 q2 A! B9 w+ L
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
1 b2 W o) s, h - #include <NXOpen/Part.hxx>! Q/ G2 u% p: Q; g8 T @+ x* p) x
- #include <NXOpen/ParTCollection.hxx>/ a; ?; h- K, M) _
- #include <NXOpen/Point.hxx>9 Q! S. c4 \9 ~2 \6 x$ D% P$ _
- #include <NXOpen/PointCollection.hxx>
/ C0 t" U3 @8 x& N- c: m" E( f - #include <NXOpen/NXString.hxx>
9 x7 B7 ^; \. Z: ~3 C: w/ Y% Y7 [ - #include <NXOpen/UI.hxx>% n) |! z, s# ]
- #include <NXOpen/Spline.hxx>; l& \# D$ M9 }+ Z& J
- #include <NXOpen/NXObjectManager.hxx>) O, q( L4 ?) I, r8 }
- 7 P1 N' H( J; i' i# ]$ r5 i
- using namespace NXOpen;
( x5 P6 r# V S8 ]8 d% V' E. ]$ Q7 Y - using namespace std;$ _, k: T, D( v3 C
- ' y. f4 |& g$ N; g$ E9 ], T
- extern "C" DllExport int ufusr_ask_unload()
4 A. d' I% }6 s+ |# [+ q2 j! N - {: i3 d9 q) X% X7 [8 `: w% x
- return (int)Session::LibraryUnloadOptionImmediately;
, g9 k) P' C; Z- z! R9 `$ K r - }
' [5 V1 A7 v9 o2 B% N: R( d - & f0 `0 `: T8 j. i0 ^, |: I
- static vector<Point *> selectPoints(NXString prompt)
; j( a L' }) B I) T! E - {; C" ^1 ~7 T3 _ |
- UI *ui = UI::GetUI();8 r+ L" O+ {$ v3 N- b0 U& t
- Selection *sm = ui->SelectionManager();4 `4 I5 g4 J$ R( m7 w) l8 E+ g- N
- std::vector<Selection::MaskTriple> mask(1);
! z h' r8 A& P/ @) I+ |: f& R- k! i - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
; z$ K: i( u& h5 H& b - std::vector<NXObject *> objects;
) t, i; a2 N1 f! W0 V
j3 c6 s$ t5 p2 z! _- E! ^# S- sm->SelectObjects("Select Points", prompt,1 F# Z @9 |2 s5 X& o
- Selection::SelectionScopeAnyInAssembly, D, @; k' D# i/ I3 s* y
- Selection::SelectionActionClearAndEnableSpecific,5 ?' @9 K; }5 ^
- false, false, mask, objects);
7 R( U0 `: X& E- _) A' F
9 l$ A/ [1 f7 [$ K7 D- vector<Point *>selPoints(objects.size());
' m( x: o7 H0 y4 \% q - for (unsigned int ii = 0; ii < objects.size(); ii++)
7 [ ^3 u4 D$ D6 b6 G# P0 z - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ y7 R, K" c% T
- " m/ q$ V, a' I) ^- {
- return selPoints;
# l5 P( k4 l6 T+ q, Y - }' Q- R4 U5 x9 ], e m! L
" \8 a- Q7 u# x, D( B- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 v3 t4 O' L1 o$ D* `: }# N) u1 Q, c
- {4 \ z$ G- {! B
- Session *theSession = Session::GetSession();
1 b4 h1 ]; _2 }9 L% D7 v - Part *workPart(theSession->Parts()->Work());8 c7 J( w3 o( s
- 4 l4 O/ d0 D+ I9 h
- Session::UndoMarkId markId1;4 ^+ A4 w. e4 N; y( l
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,/ w7 _2 g( e8 f1 A1 F% P
- "Studio Spline Thru Points");. n8 i6 G* q! T# R$ v( R% `
* p8 c# p7 O* N; e S; B- Features::StudioSpline *nullFeatures_StudioSpline(NULL);7 D" Y; g+ I3 G8 [# D$ m
- ! F( c5 i" {5 x" b
- Features::StudioSplineBuilder *studioSplineBuilder1;
; p& Q( u% ^6 g4 w4 h, I - studioSplineBuilder1 = workPart->Features()->, A/ n- `6 X g; i( }1 c
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);) G. Q' V( T% R# Z
- studioSplineBuilder1->SetAssociative(true);
3 O+ t5 i1 J) m3 B' p. J6 ^ - studioSplineBuilder1-> x# x J ?! j/ G( }3 j6 e
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 |. j& X) R7 W! V; X2 a- @; M
- studioSplineBuilder1->: t/ A; Y; ^/ t
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
0 R( B+ U$ _2 } - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
. m( e9 M/ I& ?( D4 }" N - studioSplineBuilder1->SetPeriodic(false);
% Z6 Y: @0 F0 b; n - studioSplineBuilder1->+ I, h2 H' k$ r+ {: n- T% _
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ ~, a* }5 T, P& y5 y. B+ t$ a
- std::vector<double> knots1(0);
* b* J4 J: e, k0 \! A - studioSplineBuilder1->SetKnots(knots1);
& q; x% {, P, C( u) H. \ W$ [$ r, R - std::vector<double> parameters1(0);
# [9 E; d& B. o3 G5 ` - studioSplineBuilder1->SetParameters(parameters1);6 ^" h* P5 y2 k
- Direction *nullDirection(NULL);- g9 k5 k" N) F j z5 {6 k+ [. T T
- Scalar *nullScalar(NULL);
0 Y, y* v' h7 \" E - Offset *nullOffset(NULL);
% B& O; A- l7 `) p6 [
7 J4 `( K; [6 I6 m- std::vector<Features::GeometricConstraintData *>
2 N4 n0 j% G5 B, L - geometricConstraintData(thePoints.size());% N6 L5 m) W/ \
- 8 |: U( c9 d1 L8 w
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
* ]0 J' k4 E& Y; G% L6 a - {' n2 |9 h- ^5 o5 z& z
- geometricConstraintData[ii] = studioSplineBuilder1->
- L( J3 w4 D( w# `8 z) m - ConstraintManager()->CreateGeometricConstraintData();; ~! b/ s/ l" R' k7 b) m# ]
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
' M' C. D5 ^: A! U9 s% A7 i - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
" g9 L" U5 i C( q - Features::GeometricConstraintData::ParameterDirectionIso);
. P6 [3 i: y f4 i4 E3 } - geometricConstraintData[ii]->SetAutomaticConstraintType(
: B9 s* M! ?$ v" ]/ T - Features::GeometricConstraintData::AutoConstraintTypeNone);
4 d6 F. R3 p! n; ~7 |5 T+ l( [ - geometricConstraintData[ii]->SetTangentDirection(nullDirection);, v+ s5 }& f% u! ~) |' @
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);. u. L: {. q" E- ^9 X; D
- geometricConstraintData[ii]->SetCurvature(nullOffset);9 D) G' T0 v% u" P8 \
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);1 r- o* H2 j4 i6 p F
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
; I& |- r M4 R# o* ~" G - }+ h' F* [, d) Q _' ^ h% M
- . Y6 ?' d$ ~( U: F: e& y
- studioSplineBuilder1->ConstraintManager()->SetContents(0 Y$ `0 V# Q1 u( p P' |
- geometricConstraintData);# J/ Q J3 E9 U! x* K1 _0 V
- C% B/ r2 d, W" E2 b+ r
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
: p: ]. M/ W: f- D$ N2 T. | - Spline *theSpline = studioSplineBuilder1->Curve();
- t R6 {' [" j* n - 3 F5 u$ t: w1 b% q6 i
- studioSplineBuilder1->Destroy();
, c. P8 J/ [! D+ i) d8 a. M8 [* G3 e - / G: }7 T% w& j$ @# a
- return theSpline;: ~1 @, J# _' b2 @' B4 Z3 x
- }0 N$ d6 t/ w4 E7 w4 a+ ?4 C
- 4 D4 Q. Q k) ^+ v
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)6 h3 [& z" {* U
- {
& `4 F1 A5 |+ v7 Z) ?! V. t5 \! F - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
1 }% j# G3 R8 j2 ?: T, @: { - if (!thePoints.size()) return;. Q) k/ C) [8 N: B$ S( y
- . Q1 T1 A6 K/ [# C' g4 _
- Spline *theSpline = createStudioSplineThruPoints(thePoints);% \0 b2 j6 Z2 m- ?; s% V8 k# w' N
6 T+ Y% z1 ^% C" T9 y- if (theSpline)
0 a0 {' X9 ]6 Z - {
) r3 Z2 y0 {9 d$ T6 Q* Z+ D% ` - theSpline->Highlight();
' o: V+ H* x4 y) G - uc1601("Studio Spline Created Thru Points", TRUE);
2 y! y2 v, \; J* r% ^ - theSpline->Unhighlight();
0 Z, K' E8 e7 K! P( }" a' U - }1 P+ D4 f L* X
- }
$ d9 L, T5 {' B( x& M$ f
复制代码 + b* q' j8 L8 x5 W7 l i) i) W5 o, D
. b( {8 M# n. A9 H2 T0 w
1 }+ N7 Z T# K+ |# | |
|