|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线0 Q; ^( j6 u0 [
- #include <uf_defs.h>0 G. k$ d: T3 K! G$ b! G
- #include <uf.h>
$ P W, u3 l6 c$ c3 i- b - #include <uf_modl.h>( P- x) G' h7 `+ N
- #include <uf_object_types.h>
( p% u" Y7 X$ p& v+ Q( | - #include <uf_ui.h>/ h+ E8 U% b; G$ j! H
- #include <uf_modl.h>% e3 h! N3 S" S) M$ l; m% N" U- [7 I+ X
- #include <NXOpen/NXException.hxx>
$ i8 K/ f0 G+ W - #include <NXOpen/Session.hxx>2 R. B# Z6 D# D( e
- #include <NXOpen/Selection.hxx>8 ?+ O6 p7 l7 `
- #include <NXOpen/Builder.hxx>
1 ?5 W3 p! u3 G% s& h - #include <NXOpen/Features_Feature.hxx>- |# I# C4 p/ c, _. j/ ~
- #include <NXOpen/Features_FeatureBuilder.hxx>
2 b' q% [) V0 B - #include <NXOpen/Features_FeatureCollection.hxx>- @% c# R: h9 l) G' P T, U
- #include <NXOpen/Features_GeometricConstraintData.hxx>
* K: @' J! ^; W' S* }8 G - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
! j, H2 C2 @! s. I - #include <NXOpen/Features_StudioSplineBuilder.hxx>
7 N. }) r% W6 z$ c( P( | - #include <NXOpen/Part.hxx># V& U* b. ]2 L: Z: P/ t
- #include <NXOpen/ParTCollection.hxx>6 m% F5 r! ^( W0 S$ n
- #include <NXOpen/Point.hxx>" v7 ]* u1 F4 y. p6 v" y2 ^
- #include <NXOpen/PointCollection.hxx>
# t; j! [. k5 \' p - #include <NXOpen/NXString.hxx>3 C' m9 b6 L! ]' @. c' C! N5 `0 P; U
- #include <NXOpen/UI.hxx>) w* c2 h8 M4 w& M9 ^
- #include <NXOpen/Spline.hxx>
; E U1 ^, q. Z! m& Z8 {- U# U- O# a - #include <NXOpen/NXObjectManager.hxx>$ g {2 e1 I H- ]2 ^; e
- , l7 v, f0 s; o' }
- using namespace NXOpen;
8 Y+ I* y- j5 R4 [, F - using namespace std;( R+ B! q7 x5 ]* O
- $ {( a# o+ g& h# F9 h" \
- extern "C" DllExport int ufusr_ask_unload()/ L. |; }! j$ Q' ?" \
- {. Q0 N/ u' J( D+ f: ?
- return (int)Session::LibraryUnloadOptionImmediately;/ j3 ]. j. W7 p% F2 _5 {
- }5 t3 m. u! g* G3 S
- 2 P9 `5 [$ V# i+ x. N! V% ^+ q
- static vector<Point *> selectPoints(NXString prompt)
: c1 `8 |) \& _# b# @ - {* E0 Q8 A, z @) m6 g+ t1 f/ V
- UI *ui = UI::GetUI();; K0 d$ i( H; w' B' k: n
- Selection *sm = ui->SelectionManager();5 Y" V' _/ i8 Z0 h% i* w
- std::vector<Selection::MaskTriple> mask(1);5 O+ k6 u/ L1 s0 z
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
0 S4 R) ` w, L1 _+ P5 ] - std::vector<NXObject *> objects;/ U# [+ b7 ]' r2 ~5 b) i
" U( g% q& d1 m: M, p. A- sm->SelectObjects("Select Points", prompt,
" k! H& L$ ?0 U7 w - Selection::SelectionScopeAnyInAssembly,/ Y& l) u1 v7 J Y! r1 [
- Selection::SelectionActionClearAndEnableSpecific,
* k! m, {- Q9 [. p; l - false, false, mask, objects);
+ s0 b( r; [5 Y! p7 Y. j. l* w - # ]) f' I: e' E# Y( w9 _8 N9 _
- vector<Point *>selPoints(objects.size());! _% I3 s2 P- y, j
- for (unsigned int ii = 0; ii < objects.size(); ii++): {" @5 I) C& z
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
* w! U& d9 d. R/ W5 p# y* ~ - # L7 X4 N0 W- P# c% N: @6 j4 X
- return selPoints;
& M) P/ A0 A, P: E1 t6 Y$ c4 `% l - }3 T" E9 w! y) J: W
- & T* F7 ]4 I% b" h" s* ~" |# U
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
4 y$ j( |3 E1 c# Y g% u - {
. X1 y/ e# \: w* }! P, C - Session *theSession = Session::GetSession();8 b& X, Y: `5 ], Z& E, s+ f$ K# n
- Part *workPart(theSession->Parts()->Work());
4 E0 I% L2 Z/ L6 {7 V( Y& J3 i5 u8 g/ o
5 c, G: E2 [! F/ |" y0 H, J- Session::UndoMarkId markId1;6 }& b- Q9 \. X/ J. @0 r
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
$ H" g; }5 D# I! C- ` - "Studio Spline Thru Points");0 k, J- {8 Y+ P r
0 n9 r5 h! S4 z& D' j% N- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
! B2 u# R. x1 J# ]. ?1 @1 u! @% H
q1 Y* H7 ]9 s. o4 Q- Features::StudioSplineBuilder *studioSplineBuilder1;1 P& G, d% \' @3 R7 _) t
- studioSplineBuilder1 = workPart->Features()->
% p6 l" w$ A* x: Y - CreateStudioSplineBuilder(nullFeatures_StudioSpline);% G* x7 E6 T; N3 n8 X4 p
- studioSplineBuilder1->SetAssociative(true);
2 M/ x d- A# d, \ - studioSplineBuilder1->
6 G0 a, ]' q- K9 G) |8 t - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
# u, h$ [, N: j0 L$ r0 M - studioSplineBuilder1->0 x5 a8 B7 e$ U' q
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
8 m W2 J& y3 p6 U I( Y8 T - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
Y& V3 _) M7 [' ]9 M8 J - studioSplineBuilder1->SetPeriodic(false);
3 Z5 d8 b3 u: w+ k - studioSplineBuilder1->
1 j( e4 |0 _. i. F- F: h1 g - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
, H7 m6 @. F& C+ S; { - std::vector<double> knots1(0);! z( X; u+ k! J" b# `9 N; G1 v( |
- studioSplineBuilder1->SetKnots(knots1);
% R8 e' q* O" T) y9 T- n - std::vector<double> parameters1(0);
G% o2 Q( C* p3 M2 R' R - studioSplineBuilder1->SetParameters(parameters1);" G( n. p6 t: C& f, O' q, \
- Direction *nullDirection(NULL);2 U" F# ~" s6 ?
- Scalar *nullScalar(NULL);7 _8 ]" x6 |) F* n9 z9 y$ {
- Offset *nullOffset(NULL);, Q6 P. K4 \+ ^& T5 Q
- * C4 n# n+ g& m8 x* c' z
- std::vector<Features::GeometricConstraintData *>& a+ @ u, R8 Z9 b- e' h, U
- geometricConstraintData(thePoints.size());
+ X* G1 M' V/ M% N: c
" f! z% d6 O, w( k! y; a- for (unsigned int ii = 0; ii < thePoints.size(); ii++)' N, A4 z" W' ^
- {
$ k: o; @8 A8 X* L* |3 X7 E) B$ l; ` - geometricConstraintData[ii] = studioSplineBuilder1->" m5 e N0 U9 B0 e5 x: Q
- ConstraintManager()->CreateGeometricConstraintData();
. D3 e7 G( ^( Z; y - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
) z2 _: q c5 D; i5 V - geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 T7 X" _: D0 ^' Y* [! P2 {' v% f
- Features::GeometricConstraintData::ParameterDirectionIso);
6 t# {" Y; R8 J2 u" M; H - geometricConstraintData[ii]->SetAutomaticConstraintType(5 b" e7 V# n+ R) h
- Features::GeometricConstraintData::AutoConstraintTypeNone);& u+ M/ I9 g- v
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
( C1 {+ X; g) J1 s( j3 R, @+ n - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);. d v5 i' Y6 M9 ~8 |7 X
- geometricConstraintData[ii]->SetCurvature(nullOffset);# T- ~4 \- `2 s- H' w: P: U ]
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
f! o/ r, S3 F! ] - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
: C% X$ P0 N3 B' [ - }3 A1 ?; k. J7 P, u5 k
- h4 m7 n6 K- A- w4 }; R0 A- studioSplineBuilder1->ConstraintManager()->SetContents(
9 W$ ~" w) Z' T- i+ G7 ~ - geometricConstraintData);
9 y, K S* M0 S( W1 L% e; D2 c- o0 t - 2 G+ U9 g$ }+ }4 P! a1 ~1 S
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
6 b a; M6 K+ k' ~0 ^7 _9 w) J& n - Spline *theSpline = studioSplineBuilder1->Curve();; }! j5 g6 v) \# l, o' M
, H3 m0 J( @! u0 Z8 t+ o- studioSplineBuilder1->Destroy();) D( [3 J# C. v. U( g
- % O$ V z& X; M# K
- return theSpline;
+ s5 ~1 b6 k l7 x! P3 `. }/ a - }
& K# W& j) Q' N& `! t" ^' G - 0 I& N5 C$ \: [! A% L8 c
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
7 u9 z9 Q& y1 I6 b+ p7 Q) m - {. g4 h; e+ G# B9 Z6 `
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ f) }' g! j6 [- c' l1 u
- if (!thePoints.size()) return;' S. q$ ?5 K. C' n- T5 A
0 G) e: A; D; v; ~5 d5 B- Spline *theSpline = createStudioSplineThruPoints(thePoints);2 x1 k3 _: Y% D8 l
- $ c2 Z7 {* ^2 {% N
- if (theSpline)
( y$ \; r* P8 e2 o' G" Q - {9 f) @6 c- ^1 o( Y( Q$ w
- theSpline->Highlight();! ]' e: e7 P2 L4 S2 t: g v
- uc1601("Studio Spline Created Thru Points", TRUE);1 o/ D( E. _+ M
- theSpline->Unhighlight();
7 y6 D) ~, H% |; ]4 `* p0 e - }7 I5 K' s- U' ?5 V0 S o3 v
- }& c' H7 V, d2 d
复制代码 , R9 F+ N8 R3 M0 V
" o, [! R0 g/ e2 Q
) d/ U& q- ~, H- } ?: J0 o |
|