|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
' s7 N) ]% }9 j, O7 C- #include <uf_defs.h>
7 n# D! c; U4 E- q - #include <uf.h>
$ E- \* Y5 J. f1 v3 T Y( {4 E8 ~ - #include <uf_modl.h>
' t& Y/ e- e% m" H2 n; ~7 S - #include <uf_object_types.h>
3 e# h% A( u4 `3 Z: X" X9 B - #include <uf_ui.h>4 V1 \3 ~4 `3 c. O& r( A: w
- #include <uf_modl.h>! X& ~. r6 {. |, [
- #include <NXOpen/NXException.hxx>2 O. t4 x1 _; G% V* G% D
- #include <NXOpen/Session.hxx>
7 t2 E4 H% a" t, ] - #include <NXOpen/Selection.hxx>
8 S2 H5 K5 t, T$ P3 f; z _5 u1 e - #include <NXOpen/Builder.hxx>- g# `2 T" o$ t& ?3 K1 n% }
- #include <NXOpen/Features_Feature.hxx>( R% c. V% e2 p" ~
- #include <NXOpen/Features_FeatureBuilder.hxx>0 A' O7 {3 p c( Q
- #include <NXOpen/Features_FeatureCollection.hxx>
5 D! `0 O5 Z$ `/ Z9 s6 _8 i - #include <NXOpen/Features_GeometricConstraintData.hxx>" I! g$ F" A( ^1 \. i% s
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>6 G+ A B6 l" {. L5 h
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
% T+ N' G/ t' s N - #include <NXOpen/Part.hxx>
; M/ i- d) U5 `, a - #include <NXOpen/ParTCollection.hxx>
$ q& P. \6 q! s: |$ a; z - #include <NXOpen/Point.hxx>
# N7 D/ k+ [9 K# y; i! f - #include <NXOpen/PointCollection.hxx>, A7 o% e3 h) T
- #include <NXOpen/NXString.hxx>
, a4 F+ f% I4 K - #include <NXOpen/UI.hxx>
" w# P" x M# G) R5 @8 H - #include <NXOpen/Spline.hxx>
: T! }% I1 S3 I. D. \9 q! Q - #include <NXOpen/NXObjectManager.hxx>7 N$ ]8 [4 A+ w) e( B
- $ h4 r/ V& q, x' z# G h9 C
- using namespace NXOpen;
# e, b, e0 D; c3 w# Q. A2 u& ^ - using namespace std;
: M5 y$ g* `* N0 c! M+ f- p9 _& @
! A: A( j+ z: E. j o# G; K" C- extern "C" DllExport int ufusr_ask_unload()4 o% H: G3 z1 ^7 W4 X
- {3 ]7 S5 d" U* D0 C
- return (int)Session::LibraryUnloadOptionImmediately;- z! a; q% v0 V9 z$ t. O3 W5 }8 Q% F
- }( F2 g" [% r* X* z4 B
- . _7 U) T0 C" ?! w4 t/ G1 b1 S
- static vector<Point *> selectPoints(NXString prompt)" R, D# x) k! p4 Q+ {; W9 A: f
- {. w" P) o Z% f
- UI *ui = UI::GetUI();
7 O6 w0 L" S! I - Selection *sm = ui->SelectionManager();
2 ?8 m% K; N6 h5 Q6 b0 C, c1 f5 ~ - std::vector<Selection::MaskTriple> mask(1);9 g, s- Z' k" Y% V+ B4 ]
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);5 Z+ f2 z8 G& E% s7 Z
- std::vector<NXObject *> objects; M. j5 b+ N" a; K
- ( W$ _. J7 V E. |. s B* A K
- sm->SelectObjects("Select Points", prompt,
# n, F% {) p9 S - Selection::SelectionScopeAnyInAssembly,
! `. O* ~: t8 ~5 ` - Selection::SelectionActionClearAndEnableSpecific,
4 [2 M# K9 G" V! _- e# q$ K2 e/ Z - false, false, mask, objects);
8 d6 J( r7 t3 R; B$ s% t* s3 V$ i
/ S( @5 F* l. [8 Y! H t- g+ f: r- vector<Point *>selPoints(objects.size());
8 x1 a \- ]. u3 t- R; h' S - for (unsigned int ii = 0; ii < objects.size(); ii++)
! j; K- k. g0 B( }! ` - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
6 n Z% N4 Z( z& a
# ?7 z9 Y) R) u& ?* g- return selPoints;
- J$ l! T- T8 o- {' c - }
3 {0 l% ]. n0 U+ ]
; y- A5 u3 H4 M) ~ A- G$ d- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
+ g. L. R9 o4 a- u) R3 j) | - {
6 w; F% Z7 ^. c4 {& G7 p1 c - Session *theSession = Session::GetSession();& y: n4 E+ z, r0 A& R
- Part *workPart(theSession->Parts()->Work());
" Z, ?% t* h1 [3 B
! ?6 g1 H1 R& w3 Y. f4 W$ W- Session::UndoMarkId markId1;7 V! w2 _( e9 f# M5 ^2 }
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ h& g7 v7 v3 c! e1 c+ O
- "Studio Spline Thru Points");
* K7 h, e% i. y6 g3 `# ` - 0 q) _4 p$ f( l; p# `
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
- n! u1 ?6 e' |( J8 J: _" P - : ^4 N* M/ M) ]7 W. Z& C" z; @6 g
- Features::StudioSplineBuilder *studioSplineBuilder1;
2 }. Q5 R( k& q7 v2 \3 j - studioSplineBuilder1 = workPart->Features()->
! L5 ~9 q' |; m. O - CreateStudioSplineBuilder(nullFeatures_StudioSpline);2 p' b! m0 X$ ~! W6 G
- studioSplineBuilder1->SetAssociative(true);
) F. ]* p ^& @' Z" c - studioSplineBuilder1->3 r% ?3 N3 e2 w4 t# y# G @
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
; K& ]( u" l" _" L1 Q - studioSplineBuilder1->, z% N& r& s, ~+ S1 t9 p
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
# i0 V+ f4 g) C# T( d0 D6 q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);- B+ n. }, Q& u; J; O
- studioSplineBuilder1->SetPeriodic(false);
0 Y: d. p, V: i9 M1 m# E - studioSplineBuilder1->
8 V( V; i4 ^9 R! D - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);- [5 j' T0 D+ { C
- std::vector<double> knots1(0);
, _1 h) B2 X/ W! o6 ? - studioSplineBuilder1->SetKnots(knots1);2 `9 I3 U& P I
- std::vector<double> parameters1(0);& D' q4 Y, m" V( Q7 ^ Q
- studioSplineBuilder1->SetParameters(parameters1);
& X9 p W# F' B! i8 ^ - Direction *nullDirection(NULL);% P, l' c+ c. h3 v' }
- Scalar *nullScalar(NULL);
! {' L- V W) i, @ - Offset *nullOffset(NULL);% b3 k" z0 k' }, `% v0 R
8 [8 A( y- R" V6 T( O c4 h8 M- std::vector<Features::GeometricConstraintData *>7 l g0 v1 M% k% r5 O! q* j
- geometricConstraintData(thePoints.size());8 f, C8 q2 M |% j
" _. v' M1 e6 ]2 J/ e- for (unsigned int ii = 0; ii < thePoints.size(); ii++)4 S6 T; V b2 |" p2 P) a# |3 K3 n
- {
4 @7 c( n5 ~: W3 n - geometricConstraintData[ii] = studioSplineBuilder1->
6 b6 S- n9 e" ^- j4 a; b - ConstraintManager()->CreateGeometricConstraintData();; x4 V) V. ^, z9 V _
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
% b" A3 s/ X! y+ G4 b$ | ] - geometricConstraintData[ii]->SetAutomaticConstraintDirection(3 g j0 W9 y( P3 L- o. j
- Features::GeometricConstraintData::ParameterDirectionIso);
. ]4 Z9 Q5 x8 ? - geometricConstraintData[ii]->SetAutomaticConstraintType(
2 A! j/ _7 H, g7 g5 e - Features::GeometricConstraintData::AutoConstraintTypeNone);5 I; G( R+ _3 F5 i
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
5 P1 t ]1 g& X9 t, T- a+ x) e - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar); W9 ~$ o+ g4 s, n
- geometricConstraintData[ii]->SetCurvature(nullOffset);
* U n: \, Q/ i% U# I& H - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);) H$ o J/ y" ^- |$ ]' t6 N* s
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 V4 s9 j s; D* a/ @! m, q
- }3 @3 G( e g8 m, U4 {
, W& g4 H, G# S- studioSplineBuilder1->ConstraintManager()->SetContents(8 O- ~, B, k M( u' H4 `
- geometricConstraintData);
9 m+ p0 @+ Z* U2 T5 z& ^2 k - 6 G8 I8 K0 B1 Q
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();! _: _: u& J7 v& P: Q
- Spline *theSpline = studioSplineBuilder1->Curve();/ t0 G! d7 s* p0 u4 W
- 6 N& p7 d. |) |" K7 Q* D1 |
- studioSplineBuilder1->Destroy();) ]5 P) s( G, Q( ~+ i7 x6 l/ f
- ' V. e, D7 k; U A4 I2 t
- return theSpline;
8 i( t7 x: c0 B) u! D; t7 f - }
0 I! F0 ~$ z3 d. Y - : w, t, @2 i1 X. }& F ?4 |* `
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
' X- l% o* R. W! S2 e - {: l: s: I* Z2 a+ c2 P
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 {0 l l+ P! H# t" |
- if (!thePoints.size()) return;7 g0 r- b2 W: l3 W- J* S3 D
: V9 w$ N. Z/ A3 S4 Z- Spline *theSpline = createStudioSplineThruPoints(thePoints);! |. l6 f6 j J
- . I6 v: j6 K( g# s" i5 u
- if (theSpline)
: Z# E$ l# P. Q1 K: Q6 k! ?. h* t - {* z4 W; y6 X& l1 P
- theSpline->Highlight();% l4 [0 ]5 R' v$ I
- uc1601("Studio Spline Created Thru Points", TRUE);
0 C& a6 _# A* b) g8 M0 W - theSpline->Unhighlight();* @1 A3 c& j, f8 y {) S
- }" W9 v5 d* p* M7 l: V5 q
- }
; x" g. Y6 h# S' Q
复制代码
. G) E3 [% p% k( z- T4 b7 V1 {" o; p
8 o5 G9 W M2 `. }5 K& I8 o5 I! D2 n1 ^) A2 T8 h s% g; ~7 G) i
|
|