|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线- v& F2 F; Z5 V( q, A
- #include <uf_defs.h>
- `5 ^ `2 Z$ M& i6 X- F - #include <uf.h>
6 ^5 [# L" y f- ~$ r( S - #include <uf_modl.h>
" _; @0 v& D( F/ @$ C$ [: V - #include <uf_object_types.h>
% A! P+ P b0 T2 D# P- a - #include <uf_ui.h>
/ M* o7 S' J. q - #include <uf_modl.h>3 m1 B5 z( c7 l6 {) ~/ x
- #include <NXOpen/NXException.hxx>
# N8 f8 h1 I$ X4 l+ @) g, I; \8 c7 v - #include <NXOpen/Session.hxx>
( o Z& d0 {3 A! C - #include <NXOpen/Selection.hxx>
5 |6 E! J9 _2 `5 V- Q" d& B - #include <NXOpen/Builder.hxx>& u4 J; B' f+ {$ ?; I
- #include <NXOpen/Features_Feature.hxx>
3 U( ]4 N+ l& _. p - #include <NXOpen/Features_FeatureBuilder.hxx>
5 ^; e) t: g" K# ^7 N; M - #include <NXOpen/Features_FeatureCollection.hxx>
, G7 g. B+ x3 H3 { - #include <NXOpen/Features_GeometricConstraintData.hxx>
; f% p7 e' H I4 ?' _& C. Q4 ] - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
# ?: j) C" V6 x, [% ^ - #include <NXOpen/Features_StudioSplineBuilder.hxx>) D) B7 C! W& O2 n( z
- #include <NXOpen/Part.hxx>
- n" [3 K2 i% Y* R4 W - #include <NXOpen/ParTCollection.hxx>- K& u; v; v% k' A7 n2 P( m
- #include <NXOpen/Point.hxx>; X1 f; ]5 b6 {# u
- #include <NXOpen/PointCollection.hxx>- x4 F Q4 c9 e3 S' B( h: }
- #include <NXOpen/NXString.hxx>
7 q4 Z6 U& p8 y# T3 ~ M - #include <NXOpen/UI.hxx>5 f; f$ y; f5 S2 Z! b0 L) ?. J
- #include <NXOpen/Spline.hxx>
4 l0 p+ g$ v4 h4 H2 w - #include <NXOpen/NXObjectManager.hxx>
& U' R$ ]8 O. o9 L* S& n. f Z
/ p+ P" f5 F: _- ^. F) D, B) v- using namespace NXOpen;
P9 o% U, L2 w - using namespace std;
( j1 p$ B0 T! I2 W+ [8 }) M
( y* W7 e* b% J3 a# S! h- extern "C" DllExport int ufusr_ask_unload()
1 n% {" E: x3 \8 R - {0 W, L, ?* D3 y
- return (int)Session::LibraryUnloadOptionImmediately;( F/ J |+ P! \. E
- }
- G) e* ~/ E' Q) X5 C3 h( S9 f
. \- E0 T8 @ W/ U' Y4 d- static vector<Point *> selectPoints(NXString prompt); R- r7 t2 t+ o& U. X
- {
' T7 m' x8 _- J( ~. ?5 { - UI *ui = UI::GetUI();
& F7 S; W* J: M, K: A/ x - Selection *sm = ui->SelectionManager();0 L# q w# z$ d& Z+ b! B
- std::vector<Selection::MaskTriple> mask(1);
2 ~& d* T+ S# R, Y9 ? - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
, A: j% s4 Q. V% T# B' ]) ?! } - std::vector<NXObject *> objects;
" k/ T t& |3 i; _# |( K
/ j8 c. n8 b% ], K- sm->SelectObjects("Select Points", prompt,
5 u; h# t% ]$ c! s - Selection::SelectionScopeAnyInAssembly,
) K6 S1 ^" Z" a" T6 T - Selection::SelectionActionClearAndEnableSpecific,' m2 R- m2 P* m( @
- false, false, mask, objects);
$ t" P3 H3 M) d2 n/ C; J
u: O* Q- B. G5 f$ v7 O, X" N7 g- W# X- vector<Point *>selPoints(objects.size());! Q& V0 X1 T: }% L) h, j; G% x
- for (unsigned int ii = 0; ii < objects.size(); ii++)/ ]+ N& m3 w9 t, m
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
# s( @3 u% Q/ s, h6 a* V3 q
1 p' p9 Q2 q9 \7 U0 f3 _- return selPoints;3 B) R4 x0 X( E
- }2 F0 A- J9 h" f* v
- 4 C% W& u ]) ~( a; F2 g9 m
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)7 P: d& v) D, U5 y
- {
0 w- w% }1 p+ E& o' o - Session *theSession = Session::GetSession();
3 A/ {2 _" w" W# _ - Part *workPart(theSession->Parts()->Work());
9 f& h+ P4 q' \& i9 ^; l! b" j( { - % R- E9 F: K# T1 k5 \( j4 |
- Session::UndoMarkId markId1;6 `' v) y3 i. b: z* R
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
" P; I+ z' C2 D k* y$ N. p4 Q - "Studio Spline Thru Points");
$ ?# i( z* d0 o! W - ! P* {8 Y$ X. N/ y
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);" ?5 W" W# w, ^6 V- l
. [: v* C' d, Y7 \- Features::StudioSplineBuilder *studioSplineBuilder1;; q* ] [. }& m+ d; E6 ]: l$ J
- studioSplineBuilder1 = workPart->Features()-># y) {. {& O" k# y+ u
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);/ }% }) n9 j+ e/ B& h6 t
- studioSplineBuilder1->SetAssociative(true);
( v) Y% S0 w6 g4 F) W3 c$ ~! ? - studioSplineBuilder1->7 C% J# W4 P$ V/ e+ J) p" i6 ^6 n
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
8 ]# y: _' t& E - studioSplineBuilder1->
y" z) g* {8 G* |7 O& I - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! `! O( q8 d( f8 B
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
* s: y" }0 z; D/ i5 {; |% Z - studioSplineBuilder1->SetPeriodic(false);
_3 z1 l0 b3 }; _* @. ?4 H% t - studioSplineBuilder1->
3 X# y2 t. o( Y3 F1 [1 X; ^ - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);) d" X; y" ~' ~- ~
- std::vector<double> knots1(0);$ x2 n+ F) N& ]( p
- studioSplineBuilder1->SetKnots(knots1); _6 y& y( `/ ~3 l
- std::vector<double> parameters1(0);5 Y% ]' h8 b, K
- studioSplineBuilder1->SetParameters(parameters1);
4 f1 H; v- P, T$ f0 o5 J) A: B - Direction *nullDirection(NULL);* x" q4 t. S1 {- d* j E
- Scalar *nullScalar(NULL);
3 _: b8 ^4 l& P( I8 m - Offset *nullOffset(NULL);+ J' v* O4 b9 u7 Q2 p3 C( _
3 Y8 V; N0 _8 Z; ]+ x- std::vector<Features::GeometricConstraintData *>
* D3 F4 ^8 o3 W - geometricConstraintData(thePoints.size());
" k5 b3 L; w2 ?8 t - 7 r6 G$ a) l9 T& y6 o# R2 J
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)) Z2 v! z* N8 p" G* m2 B
- {1 ^3 f3 n+ L5 p' k' [
- geometricConstraintData[ii] = studioSplineBuilder1->
' ~3 r3 A2 h+ Y# B/ k7 W2 z - ConstraintManager()->CreateGeometricConstraintData();5 \, m7 c& d% ?6 a. U' V- l
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);& S& K4 n: {$ K# _# N
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(& W; [& U8 q) E
- Features::GeometricConstraintData::ParameterDirectionIso);) Q6 B) N2 Q6 M* S
- geometricConstraintData[ii]->SetAutomaticConstraintType(* }- d3 b- M T, }, i. D
- Features::GeometricConstraintData::AutoConstraintTypeNone);- n" a! e2 v5 X
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
. \0 x" s1 K7 q& X/ j - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
9 K% D; c! q) l6 X4 U - geometricConstraintData[ii]->SetCurvature(nullOffset);9 W. c5 G5 Q6 T
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. c/ f, K$ M* q; `: P
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
9 b+ u- g1 W# M; f- M - }
, I( R# V1 ]3 D
, J" b) M9 H0 M- studioSplineBuilder1->ConstraintManager()->SetContents(* U ?7 Z& \! M; ~4 m+ O
- geometricConstraintData);0 K& F! P9 \8 V- \
- 3 A5 ~/ {) N5 z1 I+ k0 G
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
1 R! W+ }$ S& m; S* ~$ M - Spline *theSpline = studioSplineBuilder1->Curve();
7 @1 s" W( E9 C% n5 Z - + P" B) R6 U! h; V# l, H! F
- studioSplineBuilder1->Destroy();8 k9 n5 q) f6 j) @
- % d& q4 F7 @1 Q
- return theSpline;
! U" {; V. k& E6 D ?/ W - }
! ^6 p4 F* o. R8 B# M$ q3 ^ K3 |
% h8 _2 T5 Y- M, S5 i- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
, `( H% Y* V1 k - {
3 F' l6 e0 ^% h E6 c" ~, r - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" \+ ^1 X. N' \. z" Z
- if (!thePoints.size()) return;: M8 k2 J" H: T
+ h: ^( j, K& U0 n5 O- Spline *theSpline = createStudioSplineThruPoints(thePoints);1 |4 {- E) x/ w# Y# Q' R& q
- ; e+ }8 {+ g) M+ ?9 D
- if (theSpline)' C' J8 M9 S3 U$ ?/ C
- {
/ h( T z% Q7 { - theSpline->Highlight();2 O! l: }7 n' w& }
- uc1601("Studio Spline Created Thru Points", TRUE);# h& l+ K$ L1 l
- theSpline->Unhighlight();
8 m1 h0 w" J- s- _ - }
# R3 t/ A/ z/ Y S: { - }
& l7 \2 A& |4 G3 Z+ |7 l" p; B0 \
复制代码 & ?" z# {9 f# ` V
; B* j3 c4 b+ g- q5 V( E
6 V. G4 q$ }( @ |
|