|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线4 O) J( J4 h0 B' `2 m% a
- #include <uf_defs.h>4 {' u" o, C7 r& u$ t% q, T+ O
- #include <uf.h> h' N1 c8 h7 X5 H( }4 N7 }
- #include <uf_modl.h>1 `0 b9 `* a2 V8 w. b. J' t
- #include <uf_object_types.h>
; ?. P+ O/ b5 [- y" _ - #include <uf_ui.h>
' S) g- m3 w( z - #include <uf_modl.h>1 ] ^: w& u: T/ T) d. {$ T4 D
- #include <NXOpen/NXException.hxx>
; f4 q2 u) m* R - #include <NXOpen/Session.hxx>" o* k* [9 }3 o5 w
- #include <NXOpen/Selection.hxx> f: w B6 Z, w' v7 f
- #include <NXOpen/Builder.hxx>6 f# |) u4 `, I5 |" U% U8 S* p1 T
- #include <NXOpen/Features_Feature.hxx>
# |' n. @6 J/ K$ ^9 y - #include <NXOpen/Features_FeatureBuilder.hxx>: L) t' g% |1 @5 |+ _
- #include <NXOpen/Features_FeatureCollection.hxx> t% I6 }+ S* r+ v! z6 B: {! B$ H
- #include <NXOpen/Features_GeometricConstraintData.hxx>4 Z; V. Z5 O J6 Q4 X7 V1 C
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
( P1 f* e4 ~5 r- s4 j0 N; o - #include <NXOpen/Features_StudioSplineBuilder.hxx>* a5 m' m. i' V' v- W
- #include <NXOpen/Part.hxx>4 {2 a* b' X5 V, F* O
- #include <NXOpen/ParTCollection.hxx>
, a! j. Q; h1 {3 f3 G* G$ [; p, ~ - #include <NXOpen/Point.hxx>
; F7 x3 C: a: p1 r4 B - #include <NXOpen/PointCollection.hxx>
1 ?" l, }8 n) V9 a - #include <NXOpen/NXString.hxx>
2 D% p4 [9 F" u3 e# p - #include <NXOpen/UI.hxx>
& T% ^$ B7 ^5 X - #include <NXOpen/Spline.hxx>
8 q. U2 ?1 L9 o5 T7 o5 S/ y8 m - #include <NXOpen/NXObjectManager.hxx>4 p W, c% C7 D6 b6 C0 q
- 3 X, |! T; \9 O" H- n* b
- using namespace NXOpen;
$ n% J+ u. W# N% h* |% ] - using namespace std;+ N+ t% h/ C. \6 W" L2 C$ P7 M! U
- ) K/ a/ ^1 U* {( b8 p r
- extern "C" DllExport int ufusr_ask_unload()# r2 [% J. C$ F8 [
- {% f# e/ Z/ \% a
- return (int)Session::LibraryUnloadOptionImmediately;' k R, ]- u$ p! Z
- }8 B% K& n0 E: S+ x
; h- [' b& R* v9 Q( z- static vector<Point *> selectPoints(NXString prompt)) j/ b# D: s" y8 S8 n/ L
- {4 {. |& x$ \3 v7 {
- UI *ui = UI::GetUI();) O" Q% j; H5 r5 n( a5 c! r
- Selection *sm = ui->SelectionManager();8 R! p6 H+ ~# r _& O6 s
- std::vector<Selection::MaskTriple> mask(1);, c T3 Y6 C9 k4 v: v# G1 h
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
2 ^; K$ _( g, ?9 @% P - std::vector<NXObject *> objects;
8 H. |7 Q2 \, F" y Y$ s/ \
1 X) V A2 X8 z( [' X- sm->SelectObjects("Select Points", prompt,
: z, j# [7 c/ f7 I' H* o5 R6 | - Selection::SelectionScopeAnyInAssembly,
& a3 _9 Y6 J% m K/ Q0 B! }5 H) R+ X - Selection::SelectionActionClearAndEnableSpecific,
4 E) N. j0 K" v" v w+ J2 s$ P - false, false, mask, objects);
+ N* W! Q: s1 q; h1 ? - 2 Q. a6 w) h6 ^; p
- vector<Point *>selPoints(objects.size());; v6 T. c# ?5 [6 F
- for (unsigned int ii = 0; ii < objects.size(); ii++)4 G$ k' q' }4 _6 N
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
& H3 a" t5 E% T6 N' {" P" ~
. \& l, g9 m, L9 M3 z7 S( a- return selPoints;9 W0 _8 J2 U+ } Z( ~* |; Z
- }
( j9 t- C- `) t7 S- u+ b0 Q - & Q1 t3 h8 {* t$ h3 q
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)8 m& I* X q5 z9 B
- {
7 o/ h; x. s$ W/ X/ N' d# n5 O - Session *theSession = Session::GetSession();
( D9 k! }, `$ z" N - Part *workPart(theSession->Parts()->Work());8 s1 @8 m' J* }+ C; F/ }" ^3 M! c5 S
; h! ]+ R1 H. e7 B' N- Session::UndoMarkId markId1;/ `: f: ~( Y- S; z: O1 U
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ |! e* A. E( _1 h$ J' R7 {
- "Studio Spline Thru Points");" u% c1 O5 x' t% y5 \* M( @
+ I* v1 I8 ?, p% m! g9 @0 h% g7 P- Features::StudioSpline *nullFeatures_StudioSpline(NULL); p/ w6 k! w/ K+ b
* A1 r- w. w: b6 e* U- Features::StudioSplineBuilder *studioSplineBuilder1;
( H0 x3 e# e4 B3 \: ^+ | - studioSplineBuilder1 = workPart->Features()->* o+ {5 p. |0 H- C2 z. D1 s
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
( C9 f: d0 q" k# m$ P7 v - studioSplineBuilder1->SetAssociative(true);4 U6 g: F# E+ n- p, F E
- studioSplineBuilder1->, f/ m& B# v3 m6 b9 J
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
! |6 [' B* q. X. w - studioSplineBuilder1->9 C! {" G, N' o6 G
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);: U) m, `8 }- T, ?" W/ i5 A8 m
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
% c9 K9 e3 a; j8 n4 T( r - studioSplineBuilder1->SetPeriodic(false);; b3 [2 u# r& m# b w
- studioSplineBuilder1->8 n/ r. \( o2 r$ K7 {' r
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ ]$ s- [: B l
- std::vector<double> knots1(0);1 \6 c N8 ~" M2 }7 H2 k
- studioSplineBuilder1->SetKnots(knots1);
- Z6 p K! |, B6 z' l; E - std::vector<double> parameters1(0);
+ Q5 g& s9 x8 S. Z' g% \9 c" x - studioSplineBuilder1->SetParameters(parameters1);: R0 n Q2 d3 R1 X
- Direction *nullDirection(NULL);" I; Z6 J6 e. w# X
- Scalar *nullScalar(NULL);9 A; q0 }7 X, w0 m$ B' Z0 D# m9 v
- Offset *nullOffset(NULL);
8 T( V% P9 O5 k3 B6 c
& M% r ?! t( r2 F2 {- std::vector<Features::GeometricConstraintData *>
/ |* _4 ?! D o" v - geometricConstraintData(thePoints.size());
9 ]* \/ e" @% S% `$ }+ b
3 u8 L$ i! q: _1 T. U8 Y: L, Z6 h- for (unsigned int ii = 0; ii < thePoints.size(); ii++)5 c# A/ }2 [" t/ \/ i4 k* t
- {1 I4 d; V9 p; A* p; Z* E( n
- geometricConstraintData[ii] = studioSplineBuilder1->
4 j$ |6 F9 T# \1 ^ - ConstraintManager()->CreateGeometricConstraintData();
( Z$ ?' L5 @) [: i2 c9 ~, `* G1 e - geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 G2 v' n8 c" I% o- n8 A% D; U
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
" X1 m3 I/ A! U: N p - Features::GeometricConstraintData::ParameterDirectionIso);0 I9 c; o' m' Q" d& s% {6 k/ B: K! R
- geometricConstraintData[ii]->SetAutomaticConstraintType(- }5 R+ h3 F' |" Y% m' d7 O
- Features::GeometricConstraintData::AutoConstraintTypeNone);
% d% Y/ c2 _$ u9 z/ v7 y0 F6 p - geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ F+ w) [* Z2 f: R. V
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
0 I3 z) I0 A0 B7 U8 z3 c4 B - geometricConstraintData[ii]->SetCurvature(nullOffset);
4 `4 F% I. A* Y. ? O& O% l+ r - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
- m5 v8 b: ~5 A; |) b - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
* x" V. \" B% N7 i - }& q0 |, z- Q# w' j S5 u
- " G& e2 l+ F! T$ n# E2 ]& V
- studioSplineBuilder1->ConstraintManager()->SetContents(
5 j) h4 {, y/ f* a - geometricConstraintData);
3 ?4 b- O2 Y" ]& N; Q) x
" w7 C/ a2 a' E3 h) w- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. o$ D4 a# [8 j% i+ {2 R: d9 o
- Spline *theSpline = studioSplineBuilder1->Curve();- C4 p6 z9 d5 b: l
( N* g9 ^8 _1 u" M4 X: m- studioSplineBuilder1->Destroy();
% C7 K. h# X0 V# V1 y
- i; s$ U1 Q- Y% S7 g% @7 _- return theSpline;
4 Y6 {" X+ T# Z! ?; a" ~+ J - }1 J( z: @- l2 Q! r# [, A, S$ E
8 g. n1 i9 r7 N+ o& D$ \8 e! B- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
' E' \& N$ N! ]8 | - {% v( i* `% F! \, V
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");' j! p9 T3 L" L& z# m F! T
- if (!thePoints.size()) return;
0 ~# a' q# R; w o1 s
, c# h8 H* x, }# l5 B- Spline *theSpline = createStudioSplineThruPoints(thePoints);
) G+ K8 e" Q; k - , L- s( U: k2 K7 o
- if (theSpline). O6 F5 z$ `5 ~/ N
- {$ k% P7 z4 A7 s" u* e
- theSpline->Highlight();8 ]: t- b+ A- A; C% D
- uc1601("Studio Spline Created Thru Points", TRUE);
6 W a, _3 g- y4 h) p% X( j - theSpline->Unhighlight();& z, X) A4 W. z* @% {
- }$ ]4 H% W. k* l4 S0 S' D( u
- }
2 M. z" ] I5 {$ N7 y1 ^9 ~; g
复制代码 4 a( _. e2 K O+ a4 x5 C8 w
+ p3 D) n& O7 k% N+ E& J
5 [8 o1 c' @& o. \. a( h% w+ N7 Z |
|