|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线0 r8 ]6 F' o4 O* O
- #include <uf_defs.h>
' m& s6 s- H, l% S( v0 K - #include <uf.h>
! E# O# o: G& H+ o - #include <uf_modl.h>4 o5 Z: D1 p. f( J" J
- #include <uf_object_types.h>+ S* F* C1 g; f, G7 @ U
- #include <uf_ui.h>
, f0 A- o' I9 M! r. {" F - #include <uf_modl.h>& g' g ~' \7 l4 E7 ~( g/ T& I
- #include <NXOpen/NXException.hxx>
' d( K8 k1 e: g' s% S - #include <NXOpen/Session.hxx>
O4 r1 T& ~) X" @! k6 Z% O+ B - #include <NXOpen/Selection.hxx>* I( L) v, u. V% M: M) e% T2 g
- #include <NXOpen/Builder.hxx>
6 S0 Z( Y# P% _ - #include <NXOpen/Features_Feature.hxx>( _( t, T$ o+ P ^( f0 y
- #include <NXOpen/Features_FeatureBuilder.hxx>
" y; R2 X& J5 v; ~) l - #include <NXOpen/Features_FeatureCollection.hxx>
4 U4 S2 j) L. E) C" ? - #include <NXOpen/Features_GeometricConstraintData.hxx>' |7 \5 Z% @2 E( ]+ S! f0 G
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
( U# b3 g! c) O4 Z3 R - #include <NXOpen/Features_StudioSplineBuilder.hxx>& g1 Y0 }+ h( `8 A6 _0 o N/ ]
- #include <NXOpen/Part.hxx>2 |5 n. I9 t+ k k M, _% k
- #include <NXOpen/ParTCollection.hxx>
2 t$ Y4 } B! \ - #include <NXOpen/Point.hxx>
! ^: \3 u4 [9 b - #include <NXOpen/PointCollection.hxx>
1 s u- q$ u8 D! ]5 y9 r - #include <NXOpen/NXString.hxx>
+ s; t. W0 F% F3 o1 p) D9 B: A - #include <NXOpen/UI.hxx>( K X- {, M: s) K4 k& W
- #include <NXOpen/Spline.hxx>6 x, ]4 z5 S0 {3 G' h( b+ o* l
- #include <NXOpen/NXObjectManager.hxx>7 t. _; a9 g& D. X' T5 }3 a
/ n" I( G- d5 l6 d+ A2 M0 b- I- using namespace NXOpen;
/ ~* ~# ]5 A+ w7 X: x& P1 u - using namespace std;
7 e. n$ e5 S3 E
# |4 w2 p' E h- U V" u- extern "C" DllExport int ufusr_ask_unload()( q, R$ A; }& }
- {
: v% a( t* p" G0 S- h/ A; q - return (int)Session::LibraryUnloadOptionImmediately;" a8 h Q% e& |2 o8 b; X8 @
- }! s( c* B1 w4 N8 f2 R* p
- . }3 N- b3 P( j5 }8 O; ]2 p
- static vector<Point *> selectPoints(NXString prompt)
; u% L. ~$ U1 n. Y( O+ U5 O - {# R2 v6 Z: j+ }4 E3 {
- UI *ui = UI::GetUI();
2 }5 q/ V7 Z& j - Selection *sm = ui->SelectionManager();
) m$ ~' V; I0 Z7 Z1 Q# j - std::vector<Selection::MaskTriple> mask(1);+ b7 y5 H; x- }8 u
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% C; x- ~& r; C
- std::vector<NXObject *> objects;! |' H& _6 | y L9 r
/ h8 Y. \2 x1 F3 |" J0 O; w5 r- sm->SelectObjects("Select Points", prompt,; M( x. Z& J! w" k9 d1 [
- Selection::SelectionScopeAnyInAssembly,
1 X/ L+ n( X$ f' B1 [) A - Selection::SelectionActionClearAndEnableSpecific,
. y$ J+ f1 ]& V6 }9 u - false, false, mask, objects);
9 C' h8 r, p" K9 F3 o - ) n; U) D) t1 @( G! b
- vector<Point *>selPoints(objects.size());
9 v. O* }3 ~6 I& D3 v - for (unsigned int ii = 0; ii < objects.size(); ii++): \4 S# u- z* f. C) N
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);' j% e+ q9 C, i: [: T q* x4 R+ F
) x i4 C$ t m, c' D- return selPoints;
- [, S }$ z; L `5 H! T u3 i - }
) j5 B1 i1 f( q$ e' V6 o3 T4 S
) `# F- a+ i* ~3 n- e- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
8 q! x: O" B( R- v- y. ~ - {$ A5 ~1 z) N/ c4 C! \
- Session *theSession = Session::GetSession();; d1 y, k7 P) D5 S0 _# d
- Part *workPart(theSession->Parts()->Work());
" T$ _) h9 a% C6 z: f9 M% C! O6 a - ' T8 T; W F) i2 H! y; V h9 X
- Session::UndoMarkId markId1;8 I' _1 {0 d1 d1 |+ j. r7 G7 n
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,8 R- v: N8 h+ |4 g
- "Studio Spline Thru Points");9 j: | n6 Y0 H+ v0 M* v' e7 I
- 6 v& u. R) R3 R
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);& [) p- F- ?$ g
- / w: o6 V* }3 i% Q
- Features::StudioSplineBuilder *studioSplineBuilder1;/ ?/ f( M+ \& O5 n- z
- studioSplineBuilder1 = workPart->Features()->
6 U0 b8 u# t* W( ]# ^ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);2 p1 B _( C# [5 }% i
- studioSplineBuilder1->SetAssociative(true);
% J0 c# K" G" [( d1 e5 j - studioSplineBuilder1->
- I* B5 W3 ^+ A- k5 m - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);, g( B2 F- B+ N2 ]
- studioSplineBuilder1->
+ q! o+ T& U' a! }7 x' M+ e0 F) `2 Q: m - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! F% e* Y8 v4 O, l) g
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
2 G: S6 t7 W o& A - studioSplineBuilder1->SetPeriodic(false);
! g7 f! `- M" a& f1 x9 P5 v3 x - studioSplineBuilder1->, u4 a3 z0 S6 ^0 g1 l
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
; i6 ?6 ^" a( A2 k5 I D' K - std::vector<double> knots1(0);
1 B: _' Q+ K5 I8 |* v" E( @ - studioSplineBuilder1->SetKnots(knots1);
, g7 ? E' Y. E; N& {6 r/ ^; A - std::vector<double> parameters1(0);! m' ^# w- S% h, K4 [/ D
- studioSplineBuilder1->SetParameters(parameters1);7 A9 ^- @& M- d9 H* b+ H/ K4 T
- Direction *nullDirection(NULL);9 n8 M2 @4 d F" Q1 ^
- Scalar *nullScalar(NULL);
) N6 R' O3 b! e' ~ - Offset *nullOffset(NULL);( O8 K9 m: z- C6 f
: p/ ]: J7 ~; | v. l" A- std::vector<Features::GeometricConstraintData *>
8 u# o3 n2 e3 f/ E: R - geometricConstraintData(thePoints.size());
: l. i, K; M. Y! j, d7 Q! g2 a - 9 J* W; B6 Z/ v9 p1 G
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
" F) e3 N& h9 z' E6 K2 @) Z& r; s# j" f - {
9 T7 @ ~0 l) Z/ m% Z! ~ - geometricConstraintData[ii] = studioSplineBuilder1->8 W q" K% Y9 P6 m1 w
- ConstraintManager()->CreateGeometricConstraintData();2 o+ x( T$ D; h
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
: R+ s1 w5 c) D, {" u3 h - geometricConstraintData[ii]->SetAutomaticConstraintDirection(- ^" }, m* M% z3 i; k: F& T
- Features::GeometricConstraintData::ParameterDirectionIso);; c' o# q3 K! W# c
- geometricConstraintData[ii]->SetAutomaticConstraintType(
0 K8 r( M) k1 j" B - Features::GeometricConstraintData::AutoConstraintTypeNone);
8 r7 W# @ v" |2 a& N {* h - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
, |8 h0 H8 m2 e9 u& x; l& A( Z# e - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
, s" [! @( W3 g3 \ - geometricConstraintData[ii]->SetCurvature(nullOffset);2 p! L5 l; m1 ?; H9 x
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( l6 O6 o( }8 W Z6 \/ [
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 g, a# M& r; F
- }
( D9 G% d3 s \: M" w - * e/ o: a" }( C& ]; Q- E
- studioSplineBuilder1->ConstraintManager()->SetContents(
|. L+ Z h: i& s" m - geometricConstraintData);; J5 Z9 a" `7 k
4 Q$ L$ Z0 A1 O0 \- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
+ A; z4 m$ }4 q. `7 u6 D- x8 K - Spline *theSpline = studioSplineBuilder1->Curve();0 o! N+ W. v& |1 O
- . T4 ?" I+ |$ L! H; g
- studioSplineBuilder1->Destroy();% _/ O0 M; `: m- J: Q. }
- + x6 T# r, x2 o1 c; b5 n" @
- return theSpline;3 O. F$ C4 ^8 g
- }$ o# s6 V* Y$ F+ J
' u+ N) O" e; O- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
# f; x) N/ d X9 o" G/ u# i- E* h1 x - {
1 H9 t0 \1 W/ v0 I! s) f - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");: q1 c( j5 j6 O J$ C
- if (!thePoints.size()) return;
1 e/ n! y) _8 Y) U# `
- {' z: S. h/ w$ n" x7 t4 J- Spline *theSpline = createStudioSplineThruPoints(thePoints);. d5 O; ^) }) l
- : a- D- H( f$ Y& e3 w5 h' Z. i& d' p
- if (theSpline)
$ _& T7 p! ~, A5 i; e - {
8 z! ~( e! q' p5 v+ c: U - theSpline->Highlight();
, Z0 {; i( O0 q: o - uc1601("Studio Spline Created Thru Points", TRUE);
/ r( }1 G. P$ T4 L! _3 T& l - theSpline->Unhighlight();; f6 {9 V. _6 r0 d
- }
5 G; U: c3 d/ k, } p - }
1 M" L- w) w: O# |+ `
复制代码 % x" k6 F' n. ^7 r' N4 g( P; I
" X1 _, h1 ]/ C/ P+ V+ _9 v
9 a: O' ^/ k" J# s. X( X4 p |
|