|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
2 b0 I& X( |: Z5 [3 ~- #include <uf_defs.h>* q. ~( H0 G/ P; `/ ~$ ]
- #include <uf.h>
# Q: ]5 a4 o9 ^9 S# G$ u4 j& S - #include <uf_modl.h># q+ E. K/ \) [# Z- P4 d1 G% X' ?
- #include <uf_object_types.h>
4 M* d9 T( p( J/ c) s" o - #include <uf_ui.h>
6 x/ z, ~7 B# I. T! E$ U - #include <uf_modl.h> G$ C% N l" i
- #include <NXOpen/NXException.hxx>
; _! X! _7 C3 K; W - #include <NXOpen/Session.hxx>
. h* R/ n9 T5 I6 j$ R - #include <NXOpen/Selection.hxx>
- K; X: p' ]& g1 h - #include <NXOpen/Builder.hxx>
2 l% n; v' m/ P( [( h% V& M Y/ s - #include <NXOpen/Features_Feature.hxx> X# M b' k" L0 m9 Q
- #include <NXOpen/Features_FeatureBuilder.hxx>
6 U8 \3 t6 m, i5 C- h - #include <NXOpen/Features_FeatureCollection.hxx>2 I8 O5 { M2 E5 d" e& F2 [" ~
- #include <NXOpen/Features_GeometricConstraintData.hxx>
) I, L; _4 m( R, ]$ ^# V. ? - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>4 o, F' [1 x, H) K. L- f" H; N+ v9 v
- #include <NXOpen/Features_StudioSplineBuilder.hxx>' N* L, _; {/ w$ ~' s
- #include <NXOpen/Part.hxx>
$ ~/ m4 ]3 t" t' F/ { - #include <NXOpen/ParTCollection.hxx>* I! z, h y2 X. z2 I$ E
- #include <NXOpen/Point.hxx>, Z P, K: H8 M: S! I }: z; N
- #include <NXOpen/PointCollection.hxx>+ q- @! T5 F; R7 R( ~. Y
- #include <NXOpen/NXString.hxx>
/ _3 L" i4 E" Q8 `# u7 s( ^2 i8 u - #include <NXOpen/UI.hxx>. z/ D8 ~% X* k, p' F" U& M. i& x- }
- #include <NXOpen/Spline.hxx>2 Y- }3 q! e/ J) [
- #include <NXOpen/NXObjectManager.hxx>
. v" C9 V m# _8 \+ P% g1 l
' G0 ^. }8 u6 |5 Q! A+ T- _- using namespace NXOpen;
6 I; Z+ [. o1 o8 k4 m8 T( a4 [ - using namespace std;8 I0 C( S2 G# \
- U9 H7 x4 {4 j/ \! Y6 M
- extern "C" DllExport int ufusr_ask_unload()
1 L' s$ H; |3 D - {
9 X# [/ s) ?* y0 B4 Q" U0 J1 u - return (int)Session::LibraryUnloadOptionImmediately;
/ ?4 p/ M0 m7 ~% S' b6 n - }! c. \8 }7 E. z9 d/ ~) h( }" o: g/ i: _2 l
- ! N1 @7 B5 d }: g
- static vector<Point *> selectPoints(NXString prompt)
& L" n. ?0 c2 S$ w2 M! D9 a* ^) ^: F - {
$ ?7 P! ?/ I" E8 x3 J: \" K - UI *ui = UI::GetUI();
8 `" E" y& n3 _ J: a6 } - Selection *sm = ui->SelectionManager();
) p" g9 i ? F$ Q - std::vector<Selection::MaskTriple> mask(1);# U% H/ _: X+ c. g. A, I' _3 I
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
" `0 v* g9 u# e m" v! B$ u; j - std::vector<NXObject *> objects;
' V4 T5 V) `) K( g; L - . P( j- P2 V% F5 M& z: ?5 S
- sm->SelectObjects("Select Points", prompt,
) T- \- U0 x$ u! w2 W - Selection::SelectionScopeAnyInAssembly,2 E" N3 C6 E( T9 m
- Selection::SelectionActionClearAndEnableSpecific,
6 F! D# [# `& ?1 a3 ?7 i+ H; T - false, false, mask, objects);8 ]* z0 e# V/ m6 G. Y
- 2 h+ c3 ~5 K7 }; d
- vector<Point *>selPoints(objects.size());1 g4 f: D* w4 W# w8 s
- for (unsigned int ii = 0; ii < objects.size(); ii++)% o ], @: D# M8 E
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);8 c- N( `4 X, ~* j
0 c" P1 I' R% N* F: A- return selPoints;# s9 x! L0 L& Y- W }" Y( U7 R
- }
0 g9 \5 e/ E% L: E5 T- R+ q* G - - u! G" I; h; T6 U$ T2 X2 P
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)* J- G1 H: Y: j/ `6 L/ W8 L
- {
* {9 |' U6 T$ k" | - Session *theSession = Session::GetSession();" r2 l: p( @& n
- Part *workPart(theSession->Parts()->Work());8 `( x3 i/ _# S2 e1 B. R
- 0 i4 A+ Z' \% n9 ~
- Session::UndoMarkId markId1;, a' A7 E& U, r& O
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,. X; d* K6 o* r8 U
- "Studio Spline Thru Points");! n8 o- F6 D6 L3 r0 L
- r v, e, q) W3 l- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
; ^( o2 x) k: k4 y* C - 4 Y5 q. A0 ?, Z. \' j" V0 k. L
- Features::StudioSplineBuilder *studioSplineBuilder1;
8 R- h9 C9 D& m% c - studioSplineBuilder1 = workPart->Features()->
& o/ [7 x; n6 l9 X" S- P - CreateStudioSplineBuilder(nullFeatures_StudioSpline);" m% U" @ Y; |; G( Q1 L
- studioSplineBuilder1->SetAssociative(true); c1 m8 f- ^; Z) `% Z4 I4 k
- studioSplineBuilder1->
4 l3 S, a: \' `* H1 H, T - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
7 g& e8 }/ z& F9 p - studioSplineBuilder1->
6 q; j7 C7 G7 A7 \7 K9 I5 x. B& n - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
$ l$ `& j- @( N" f8 o' o M - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
0 G7 @/ ^/ w$ }" n9 w - studioSplineBuilder1->SetPeriodic(false);3 `0 k: y& t, ^- F- t* g0 T
- studioSplineBuilder1->1 X+ X% o) ^$ @ T
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
( Z4 S' a1 x: w8 b; X, F - std::vector<double> knots1(0);& V# t3 B5 J( h3 N
- studioSplineBuilder1->SetKnots(knots1);
! h; Q" F7 e/ Q6 H' { - std::vector<double> parameters1(0);
6 z% ^" U; X' r0 S - studioSplineBuilder1->SetParameters(parameters1);! [- \5 [2 X% h/ L( ^
- Direction *nullDirection(NULL);
# d: |$ _# L% {, _) U! z - Scalar *nullScalar(NULL);9 o! r1 [' A# E1 O
- Offset *nullOffset(NULL);4 t9 M9 q3 G2 j) m
! N, F9 Q; H5 {$ s/ Y5 \- std::vector<Features::GeometricConstraintData *>
0 r# ^1 u% [; f$ l& w9 d( D - geometricConstraintData(thePoints.size());' M8 P' a, Q1 i
- . z+ c+ w `2 [) ?/ B4 D. x% \
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)* C8 r' g! W- X# @6 s
- {( B; N N$ l& j& i, s I& q8 v) C
- geometricConstraintData[ii] = studioSplineBuilder1->
. [; x- Z- Y% v1 f( v1 c# L - ConstraintManager()->CreateGeometricConstraintData();& L) Q/ F5 O: p
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 G( C1 r& V) E% V( @# D
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(2 Q7 z- I, l3 [8 l9 g0 \( x, L
- Features::GeometricConstraintData::ParameterDirectionIso);
, \- p1 g' X! Z$ E7 l0 j7 k - geometricConstraintData[ii]->SetAutomaticConstraintType(
- u" d9 n/ n5 U6 _ e6 d6 I' ~ - Features::GeometricConstraintData::AutoConstraintTypeNone);
' {" }& `9 p) @$ a; D4 v8 r - geometricConstraintData[ii]->SetTangentDirection(nullDirection);" U* M& \5 N; D- J4 B A4 A
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);: C j1 n3 y& ~# A; {7 B. g
- geometricConstraintData[ii]->SetCurvature(nullOffset);
5 j3 o# v" Y" y3 c7 j7 Y9 l7 B - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);8 N9 I+ O) {2 D5 H
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
- i/ B/ I$ E7 B: J" H( L - }; g6 F7 g* _, f& J
) n7 C5 ^- x& d- studioSplineBuilder1->ConstraintManager()->SetContents(4 T7 X$ Y( B; i2 e6 x6 G
- geometricConstraintData);
7 Y5 G7 s/ e5 t. @- Y9 i& |5 |' K) {$ L
* O( M, N9 u+ K7 m- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
( h1 E( G, b1 B2 i8 A3 V ] - Spline *theSpline = studioSplineBuilder1->Curve();% z/ W8 L- R) L5 W/ J
, S2 F2 D% t+ h, H( K% Z- studioSplineBuilder1->Destroy();
. A% a/ M7 u9 o' N - - ^8 o5 B& o* @
- return theSpline;6 ^, I( @. p; P: \# S: i( I
- }
6 U- M2 K' @/ w' a5 O
8 V& C* g+ B; h- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
( M/ E( u( @4 C) d6 u. H - {
. K+ Y$ {; l; t - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");5 [3 }+ f3 f6 V1 J/ c7 v
- if (!thePoints.size()) return;
3 M, k" h/ G# U0 J5 E6 U/ g3 |7 V
- W8 P/ G, I g4 J, E2 o+ q- Spline *theSpline = createStudioSplineThruPoints(thePoints);! F- j) C" a! a
- 0 @8 s4 D; _6 g: a
- if (theSpline), d- H) ^0 M+ B+ J$ C# l0 L
- {% i( G' a0 u4 u) ?* I
- theSpline->Highlight();
1 X9 M( J, N5 l, R; X- E - uc1601("Studio Spline Created Thru Points", TRUE);
, s5 O7 Q/ I# |9 X! G$ C5 c - theSpline->Unhighlight();7 g4 t# J: O3 n! a3 D5 x
- }+ Y7 G6 X+ o, E
- }
7 A1 w& _* H& k/ l4 u [: {; \
复制代码
, Z, p/ x% w& M" _' f, g
. e* @4 \; n1 G. O* O" G
# Y3 N' J7 N4 m# j4 K. q8 m* \ |
|