|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线3 C% K, @. w$ R7 H2 r8 V" e/ u! |
- #include <uf_defs.h>
. j: P$ f2 Y( i- J5 W, J4 z/ s - #include <uf.h>
2 Y! E7 U) R* ~3 v - #include <uf_modl.h>8 c9 d( ]% r, t: N
- #include <uf_object_types.h>) H! U+ U5 k0 w% ]
- #include <uf_ui.h>+ ^- {$ ^ M$ S I3 u! z0 `! `3 X
- #include <uf_modl.h>
8 ?0 U$ f5 L# ?4 v, F d- C2 g - #include <NXOpen/NXException.hxx>
3 l' W, u" j; _8 Z8 ] i - #include <NXOpen/Session.hxx>' U5 X. ?0 ?! U2 d) ?5 p' E
- #include <NXOpen/Selection.hxx>
7 z7 v' I8 o A( j4 e% H - #include <NXOpen/Builder.hxx>
( q- m2 _* W& Q/ K - #include <NXOpen/Features_Feature.hxx>
, O8 p( O9 k/ H0 r' R' R - #include <NXOpen/Features_FeatureBuilder.hxx>) A: ]8 B3 g& q
- #include <NXOpen/Features_FeatureCollection.hxx>
- g- ]' d9 Q; K, z: L - #include <NXOpen/Features_GeometricConstraintData.hxx>( }4 w) r, U" j4 y
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>( A/ b' ]8 }1 y% Z
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
1 q5 `; x! I' Z! g1 B/ E - #include <NXOpen/Part.hxx>
" N; T& ?1 D' k - #include <NXOpen/ParTCollection.hxx>
; Q3 I. |; U4 _- I - #include <NXOpen/Point.hxx>
5 l5 p* x( ]& c+ e( |$ D - #include <NXOpen/PointCollection.hxx>8 r0 \ `7 u- N# Z( d+ u+ D$ m( k1 x$ O
- #include <NXOpen/NXString.hxx>
: r- T$ j7 A% C5 W/ P) E. p - #include <NXOpen/UI.hxx>
5 |6 M/ H# L2 U9 { - #include <NXOpen/Spline.hxx>* x/ r/ K5 z# z" ^# e7 M: ?
- #include <NXOpen/NXObjectManager.hxx>* ]) }$ W! J2 |7 I' g
- ( P0 `3 k8 L- i/ e
- using namespace NXOpen;
g# C( a) g9 B+ h( Z E+ y' L( B - using namespace std;
# b5 \6 v+ w9 Y& g
% M9 h- N' k& I- Y- extern "C" DllExport int ufusr_ask_unload()
! G {. Z4 y9 h: e! F - {
+ [; `& q6 x6 z: k8 U4 {- h - return (int)Session::LibraryUnloadOptionImmediately;3 S4 ?9 h/ a# C
- }3 Y, W6 F$ i' D8 O
5 t" T4 ?5 J$ `2 h- e$ ^+ N- static vector<Point *> selectPoints(NXString prompt)/ N, B+ Q8 @/ A3 h! g
- {( L8 O8 g# |: c0 p9 t
- UI *ui = UI::GetUI();9 C8 {& i* G8 s% z7 A5 d1 J ~/ x
- Selection *sm = ui->SelectionManager();4 S% s, A" i6 [. B" O7 L6 U+ F% d( R& z% z
- std::vector<Selection::MaskTriple> mask(1);& s* Z1 \& `& g8 e) W5 ~+ i
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
. J2 i/ N) n. Z7 f7 h5 ?0 d - std::vector<NXObject *> objects;
- e$ x% z" E# g, x' N9 P+ ^ - 4 b# \! N* O$ S( H- ]" {
- sm->SelectObjects("Select Points", prompt,
" B) i4 M1 u+ v4 W4 p) A - Selection::SelectionScopeAnyInAssembly,4 O( N# d' v5 C+ u, j' ~
- Selection::SelectionActionClearAndEnableSpecific,
3 j) X; m4 T: J& C) q" i - false, false, mask, objects);% I4 U) R" V+ { P+ V
- - C" c9 r, `& D* P0 l G+ h
- vector<Point *>selPoints(objects.size());* ]8 k- H- E1 Y- C7 V7 G
- for (unsigned int ii = 0; ii < objects.size(); ii++)5 s: J) i2 {/ L) {, ]7 D. s
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
6 i5 J8 f5 `" p
! ]( x0 {! e4 B* T7 W& g, e% e- return selPoints;
) y4 R/ q* M& ~7 M* @9 B - }
% @* z& E9 \& b I8 X$ B1 K
* B* x+ q4 O/ b5 R9 f! ?- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 U- q; D$ ~$ a
- {
3 J. D- g& c& k0 c( b4 I - Session *theSession = Session::GetSession();% w* f/ }6 a0 G3 W
- Part *workPart(theSession->Parts()->Work());& u; H5 W5 |% c. G% n
- 8 @7 L6 i. E, ?7 q* N
- Session::UndoMarkId markId1;
# `( z1 v1 w: t, ^. X/ t# V - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
7 J% C: ~( } C2 Q N9 k - "Studio Spline Thru Points");% F E( I4 P7 g* U% i: q
- ! z( g$ I+ W* _% j3 y* h# j: _
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);& T: A6 Q3 E9 {: {
- % u9 O3 a' ^4 e; L
- Features::StudioSplineBuilder *studioSplineBuilder1;! q# `& k, _: \( }9 [
- studioSplineBuilder1 = workPart->Features()->" \. `/ w2 R ^7 c. r
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
; B2 Y4 }7 c' n6 Y) u$ M - studioSplineBuilder1->SetAssociative(true);
# M! H8 F5 Z8 A8 m. C; `3 i6 @) L+ u - studioSplineBuilder1->5 Q6 _' R: M3 q4 a* {3 } h
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
! O+ ? d: t) j8 g8 f% U$ l - studioSplineBuilder1->
# q) N' Q5 h# y! y - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
" E! _/ t2 D( q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
! R& J3 G1 T$ o3 C( I8 U - studioSplineBuilder1->SetPeriodic(false);
( b' r3 J8 Y8 q6 `) _5 T3 @ - studioSplineBuilder1->
: k* k+ @/ s, H% S - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone); V, b3 i) ~2 I7 ^& A" ]
- std::vector<double> knots1(0);
4 B4 k, O8 @8 o2 o - studioSplineBuilder1->SetKnots(knots1);
6 A( ^( @; i: x) E7 F8 k; W - std::vector<double> parameters1(0);
# S; Z, X7 r# Z/ ~/ a - studioSplineBuilder1->SetParameters(parameters1);. w1 m: z7 D6 p8 g4 S3 D5 a+ A
- Direction *nullDirection(NULL);1 ^$ H2 [/ N6 V( }5 r# V5 v
- Scalar *nullScalar(NULL);
$ i) i4 @% \+ U( h2 a2 [2 S - Offset *nullOffset(NULL);: `' u7 x0 x2 i; [1 _
5 N, @9 r4 y Z6 Y) u) Z. y- std::vector<Features::GeometricConstraintData *>
: H$ E0 z, a0 c$ p. R - geometricConstraintData(thePoints.size());
4 ?6 B9 z" J Q/ W* U9 v# i& ~& x. q
& r2 K' d) z# d! \5 J( d8 u- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
# D. z3 ?* e1 d; O - {
: Y. C/ V! D6 d1 [8 ^; R" m% B - geometricConstraintData[ii] = studioSplineBuilder1->
) `7 g; W5 {, \ - ConstraintManager()->CreateGeometricConstraintData();- l% Y) Y8 p$ q7 }7 v
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);$ G; F5 t/ h( ~2 [- u
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
$ y h+ S$ w- z4 P: U6 \ - Features::GeometricConstraintData::ParameterDirectionIso);
# [& b/ W3 n- ~7 g- D4 u - geometricConstraintData[ii]->SetAutomaticConstraintType(0 c* Z+ c, O+ P1 L$ l
- Features::GeometricConstraintData::AutoConstraintTypeNone);
! q2 @6 z& _: b& p - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
, u: j$ {% E. W5 f7 R% c& ]7 X2 { - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
d( K5 v w) d' ~1 q7 O - geometricConstraintData[ii]->SetCurvature(nullOffset);/ Y% a, `+ E# K4 o
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
4 h9 _1 ]* y& P% {$ X7 o - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);# y2 M: r- i1 R, V( {1 |& m/ q
- }% Y5 A& \; j. g+ E- W! ]) }
8 {5 |+ W$ ]; X( P. q p- studioSplineBuilder1->ConstraintManager()->SetContents(
; R3 o3 G" @& Z2 M2 C3 J; d - geometricConstraintData);
W0 F& w8 l/ t) F7 r$ o; Q
5 o6 M$ n( P# N* s( P4 y+ k- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();2 j+ [% ^4 s4 B# W6 H* l, v- }
- Spline *theSpline = studioSplineBuilder1->Curve();
2 e/ h3 T2 {. e* { - 1 ?7 Y3 m' W, s4 X: R5 v0 |. s' C
- studioSplineBuilder1->Destroy();
, T8 z0 h/ B( |$ f7 T( i/ i3 n/ w
" m) Z7 W% |3 S, ?; v0 m- return theSpline;4 P3 G. Y$ T+ d/ ?; b* X
- }# U9 g, C( M2 o8 n: F9 ?
( K( d C, F7 @( q3 n, A- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len) D. W( F: l. d
- {/ ~, K: i; n: r5 {, {* |% L
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");8 {' n2 n: @' ^- A2 I7 ^
- if (!thePoints.size()) return;
6 {4 q$ I _0 z' x# U9 Z$ G$ R8 C - , s" D4 n; |8 u" ~2 E4 X7 x: H6 s
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
* r% r h0 |! L - 3 j( N" f; t& k+ a+ C
- if (theSpline)
& v: I9 k; R \* [. R+ d - {
4 \0 u( f$ r" }4 i. P; X - theSpline->Highlight();& s2 B: L' _- V2 X' W) z! u9 K
- uc1601("Studio Spline Created Thru Points", TRUE);% v% ]2 c) m0 j) s
- theSpline->Unhighlight();9 X5 Z' Y; J' j. }
- }' n- ~# g+ O6 b! w4 o! V
- }
- K5 J0 v5 n+ i8 X, E
复制代码 ) K @4 _" O" D
" B% P; R8 k% c/ A3 N( g
, v4 Y h* |, C; T7 h) n |
|