|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线) I" U7 j0 ]! O: d4 p/ |
- #include <uf_defs.h>
( G. F8 ^7 g0 `- }+ b8 I, E - #include <uf.h>
: {# F& y- P! D+ y# s - #include <uf_modl.h>
3 r% `9 J, e9 Y* A6 L+ ~9 N9 d4 ^5 f - #include <uf_object_types.h>. _4 z& f& u7 w
- #include <uf_ui.h>; h. ~. |4 h/ a- k+ v
- #include <uf_modl.h>
$ ?2 R) Y' E6 f# K- p* r - #include <NXOpen/NXException.hxx>- G2 K+ x+ @. o/ {; Q3 Z* x
- #include <NXOpen/Session.hxx>
. w. O3 z; P7 f - #include <NXOpen/Selection.hxx>) C+ m- L% [, Q a
- #include <NXOpen/Builder.hxx>2 F5 j9 x1 g5 Y
- #include <NXOpen/Features_Feature.hxx>
h. R! T$ `2 L' A) `/ C# ]/ q - #include <NXOpen/Features_FeatureBuilder.hxx>% ]* r: h& ^* ]- L- C" L+ `/ n- e0 V
- #include <NXOpen/Features_FeatureCollection.hxx>) P! b1 U1 b, t; m: N3 V
- #include <NXOpen/Features_GeometricConstraintData.hxx>1 l# c H1 b( O- e/ L2 c
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
$ }$ {" a6 }4 o; y3 `! h - #include <NXOpen/Features_StudioSplineBuilder.hxx>/ ^; k9 v4 g: H1 t& b0 ^
- #include <NXOpen/Part.hxx>8 l% ~' `. @1 l% }( s) b3 H
- #include <NXOpen/ParTCollection.hxx>5 |. g& q( v9 O, t
- #include <NXOpen/Point.hxx>
7 A1 `" @3 V( z - #include <NXOpen/PointCollection.hxx> Y2 b! k# O' F# Q; O
- #include <NXOpen/NXString.hxx>( T1 m+ d* N$ C3 I. q
- #include <NXOpen/UI.hxx>) p# T' p0 m' q, T* m- E: V) b
- #include <NXOpen/Spline.hxx>' F5 y, c+ g' `6 V- Q1 |3 X
- #include <NXOpen/NXObjectManager.hxx>8 p" A* ^# w9 @4 P8 R& l3 V
- ; I* j8 n3 {* N; S3 [
- using namespace NXOpen;
+ U% u& T# H4 p - using namespace std;
# W6 m$ @ C) t6 ~, J7 x p# n8 ^
. T" O6 d; s' ?, n, `7 W! c, N- extern "C" DllExport int ufusr_ask_unload()
3 L: Q* n, K6 E; W6 b; ?: B( @% B7 T - {
8 E3 ~$ X; c( B6 S6 i - return (int)Session::LibraryUnloadOptionImmediately;. M# h( a4 B; J2 R; X
- }$ X/ W- y) G2 u4 u, i
6 Y- }* V, c) _2 h3 q3 z" b. N- static vector<Point *> selectPoints(NXString prompt)
/ X# k& @/ K1 j3 W5 U7 b& ? - {6 y- z( c+ H, f% }% ~/ ?8 M: ?
- UI *ui = UI::GetUI();
: H; N% m! m- P" |$ ^ - Selection *sm = ui->SelectionManager();
( k2 g" R8 a; }# z. @# U; y3 b - std::vector<Selection::MaskTriple> mask(1);$ ?" F% U$ W8 \$ E: Q" d, W
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);, u- Q( i) `# H+ z0 C. x% L
- std::vector<NXObject *> objects;
' d5 Q: C' R! V# R* I% } - t1 ]+ O- n! |) |' @$ e9 c- D5 V
- sm->SelectObjects("Select Points", prompt,8 U& D M5 x+ ]
- Selection::SelectionScopeAnyInAssembly,3 ^1 h s5 G- l7 v) ?
- Selection::SelectionActionClearAndEnableSpecific,$ B/ L- I, k- K; P) N* q, a2 c
- false, false, mask, objects);
4 P' K) h3 a" G( T. R9 \
1 z* ^2 h6 K% [* T% D- P' J! Z- vector<Point *>selPoints(objects.size());
2 \6 [0 b) Z) V1 y% B. m - for (unsigned int ii = 0; ii < objects.size(); ii++)* e* _, N6 G- p/ N
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 X0 V5 C/ i8 U
- - c, ?3 f8 h" z* ^8 R8 s" o" s
- return selPoints;
s- m2 P, R# Z - }
, h& g2 f# q! D1 @0 z - 4 M- F1 N$ j) `0 j$ i1 Q
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
- F+ b8 m8 i) e* K - {1 G; o* r6 I# O4 m! U. [
- Session *theSession = Session::GetSession();
* m* ]8 U- X$ c5 W - Part *workPart(theSession->Parts()->Work());- ]1 H' l2 \5 _5 l8 R
- * m, v( A. C, K/ v) A! i
- Session::UndoMarkId markId1;
( Q( [1 @5 C5 J# o2 q* A, o0 N - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
% N3 B: M; X9 s3 Y) Z) n - "Studio Spline Thru Points");* b3 |! @) Q) ], P9 N3 Y* T1 ^9 }
1 Y) T+ a" F) J, F- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
I- T. ~# p3 M* f; q
/ z& j6 [7 j. }+ z- Features::StudioSplineBuilder *studioSplineBuilder1;
. i, a& g- r3 N% ~/ i" t - studioSplineBuilder1 = workPart->Features()->( F8 x8 S- r5 Q$ l9 l
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
p& D9 D3 B' P. A \ - studioSplineBuilder1->SetAssociative(true);
X+ `2 X! H% s& \1 h - studioSplineBuilder1->
6 G8 S6 j6 C, ^: E - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
8 @) ?$ L( ^& h$ t8 R8 w/ s - studioSplineBuilder1->$ l; M) O. U5 W1 m( v
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 D8 m" {4 N1 {8 A4 _
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ d! o0 q, X6 X+ j4 @! z$ b8 z
- studioSplineBuilder1->SetPeriodic(false);; w" G: `5 h) G" k" x
- studioSplineBuilder1->
$ A2 i) ~) J9 s0 }2 a6 _ - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
6 z0 e$ z) r5 H1 T0 I. |8 Q1 K - std::vector<double> knots1(0);5 t0 \( S* Z1 M Z
- studioSplineBuilder1->SetKnots(knots1);. }& ^( r! K& g8 ?/ t# A
- std::vector<double> parameters1(0);1 x6 e( x+ a0 T$ U% N
- studioSplineBuilder1->SetParameters(parameters1);
, y; F' t/ h# _7 D - Direction *nullDirection(NULL);
! l% f5 T- p# u0 b8 W - Scalar *nullScalar(NULL);
1 H( h8 U! ?3 Z$ e1 r% b% e - Offset *nullOffset(NULL);
3 M R9 [- h+ @; c1 T. \
! B' A: g2 e5 H* Z( H/ Q- std::vector<Features::GeometricConstraintData *>
* H" W6 ]2 g8 B9 t* h; n, u - geometricConstraintData(thePoints.size());( l7 c, m; v i
- & w/ Y9 R$ X! s
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
3 y$ T/ j! c. @5 z% w* `+ d% p M - {! ?" `9 E* o: s: s$ S
- geometricConstraintData[ii] = studioSplineBuilder1->9 [3 o" @* W0 Z) L) J% _0 x9 n
- ConstraintManager()->CreateGeometricConstraintData();
1 w' S5 A( T$ E: G( _5 l - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
' @7 `' G6 g' e3 X0 a8 y% B, } - geometricConstraintData[ii]->SetAutomaticConstraintDirection(0 g5 Q9 m U/ W2 ^% h. b2 \! ]
- Features::GeometricConstraintData::ParameterDirectionIso); b% n, Y2 a0 w" n7 e
- geometricConstraintData[ii]->SetAutomaticConstraintType(- z7 O. `; J+ o) D
- Features::GeometricConstraintData::AutoConstraintTypeNone);: Q4 F+ |9 M& J9 u3 ?' A& n
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);8 Q: x% Z: p3 i; X- [& s/ B
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
+ }8 K5 r; R. a7 [& S+ f2 U8 @ - geometricConstraintData[ii]->SetCurvature(nullOffset);( _2 W( r% F, C& L6 a
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( ?* B7 ~# b9 W
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);! W2 x* \% M' g+ e2 U. N" m! \2 d( i% ?/ m
- }# Z: W) s m! M4 H
( r0 l* R% O( c4 h; ^. R) K- studioSplineBuilder1->ConstraintManager()->SetContents(! X* Y/ c' ?6 w5 E, ?7 @7 K f
- geometricConstraintData);8 e" `" [! v/ d" g4 h8 Q% a' H
$ v, A3 f& }' E" E, ^- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, [' L$ n/ j5 ^* l
- Spline *theSpline = studioSplineBuilder1->Curve();" d+ ?- p) ~5 j$ z& ]- z3 @& I4 g
3 I- e9 L' r8 W2 m0 ]; u- studioSplineBuilder1->Destroy();5 r; |! O2 p# @6 Q/ s E- P/ Z' s
% B" X* J" w6 T+ B6 V- return theSpline;
4 x% E, r- j7 L: `3 ^' V - }/ N. `; l- Y3 [$ U
- # F5 m, J# z* K# r6 K# t
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
$ [5 V' D" E. Q4 [, d5 ^* @) d - {, z0 A. q @. `% o7 h
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
_& H, |% r3 C1 O+ [ - if (!thePoints.size()) return;
& H$ h X* D0 C! U. A2 D& u: n& ]3 q
: s* ~( U; z' s2 S$ V5 m- B& Z- Spline *theSpline = createStudioSplineThruPoints(thePoints);9 r! M4 a2 ]& u! z& ~& B4 h8 W0 x
- {, ]# v% [4 w2 r! M" U1 [$ x
- if (theSpline)
; y* v4 ~1 [ z - {5 N7 S0 \0 I9 L$ c
- theSpline->Highlight();
) C& j1 I- a6 \1 i; H- W - uc1601("Studio Spline Created Thru Points", TRUE);; p, n, n, a8 [
- theSpline->Unhighlight();$ K9 N2 a3 z- X7 q
- }1 L# c3 E; p4 J: U" l9 U
- }
+ n2 K+ i% |! k( ]( |
复制代码
- M, Y& X) |/ c4 _$ F! {, ~% x, H# o5 b$ Q. V' ^$ e
5 _& a+ v6 X, @2 P J/ M |
|