|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' ~# A3 B2 Z2 c0 O& }NX二次开发源码:通过选择点创建样条曲线
) \$ e, P* C. X! H3 V! m0 n$ j6 o( F0 k) M( @
+ b8 x/ Y4 v; U- g$ p2 _6 Q4 o- % m5 v) i+ P* B g+ p& [
- #include <uf_defs.h>
2 O& s ^+ b8 d( u$ H - #include <uf.h>% V: B- y4 T/ k4 l$ K2 ^) H, b! \
- #include <uf_modl.h>4 y9 {: H) Q) c: \+ ~- s2 ?
- #include <uf_object_types.h>
# R. S) f* L3 | - #include <uf_ui.h>( K$ w; x4 Y3 A
- #include <uf_modl.h>" {) U) M" s+ d7 K- B8 B
- #include <<em>NXOpen</em>/NXException.hxx>
5 Q2 H, |% I N - #include <<em>NXOpen</em>/Session.hxx>1 k1 W: z: w e1 E! ~
- #include <<em>NXOpen</em>/Selection.hxx>
" i4 A9 q; G# N% G+ P9 U( | - #include <<em>NXOpen</em>/Builder.hxx>
7 b8 H% k# i/ b4 S6 B9 A - #include <<em>NXOpen</em>/Features_Feature.hxx>' @/ ]9 N9 P4 j5 O9 v1 q1 e6 ]
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>7 h ~" q1 \; o% u4 a! ~
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>& o" G( R& |- Y, p! i) @
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>& h. z0 \$ e4 y4 o2 X0 v
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>. G% [$ k: z; r4 p. l
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
! _( U+ @ b4 v! ^ - #include <<em>NXOpen</em>/Part.hxx>/ y% E& I6 ] Z9 y% Q+ N
- #include <<em>NXOpen</em>/ParTCollection.hxx>
1 B. u7 s. ~: }+ e, W - #include <<em>NXOpen</em>/Point.hxx>5 [8 ]5 z( L+ j, n ~. T
- #include <<em>NXOpen</em>/PointCollection.hxx>
: H& g+ `! X: F+ g: i) N3 o6 ]8 k - #include <<em>NXOpen</em>/NXString.hxx>
5 m; `) f" p# r/ x4 m4 X7 [# n - #include <<em>NXOpen</em>/UI.hxx>5 }4 z+ q0 ], m( u! q: D) ]
- #include <<em>NXOpen</em>/Spline.hxx>4 L! ?4 k$ O% d8 O4 O+ y1 z
- #include <<em>NXOpen</em>/NXObjectManager.hxx> h1 J; a6 R. s6 {6 m }/ s
: r4 {* O! o7 ^- l$ _' N- using namespace <em>NXOpen</em>;) d: U/ G! C8 l
- using namespace std;4 b/ Q5 x* _$ O# _; I
- ) D n4 q& M1 Z$ @
- extern "<em>C</em>" DllExport int ufusr_ask_unload()" d- m. i& U# U% e( B4 \5 l
- {
0 k3 x" V, |4 @ - return (int)Session::LibraryUnloadOptionImmediately;$ ~# c: a) C% e/ W# a* Z
- }
+ P' N# r4 H6 C% \' p
5 U* U5 q$ A# x Y$ z2 K7 ]- static vector<Point *> selectPoints(NXString prompt)
* f9 X) x) V3 S+ K+ s: @4 J - {; k: y' T3 Z0 L" @" M* O H
- UI *ui = UI::GetUI();
9 t" ^+ X+ O+ U) Z - Selection *sm = ui->SelectionManager();) V2 I, H" C* m$ M
- std::vector<Selection::MaskTriple> mask(1);; ?3 Y5 i6 C3 _! U5 S8 X9 d
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
* y, s0 y" Y. A. r& \ - std::vector<NXObject *> objects;
, V) `% @0 s% l - . M- w9 o8 b9 W7 S) t L
- sm->SelectObjects("Select Points", prompt,
0 N7 h" X1 N) E' ?0 P4 y# E# g5 } - Selection::SelectionScopeAnyInAssembly,: U! c& B' U: R
- Selection::SelectionActionClearAndEnableSpecific,
4 b; z% u7 a0 z3 J - false, false, mask, objects);3 J# \' t- L+ ~; s7 Z+ J- j
: N/ Q' @9 i, \+ p" e- vector<Point *>selPoints(objects.size());& D3 D7 L \, F. V0 u( O
- for (unsigned int ii = 0; ii < objects.size(); ii++)% g' c1 P! ~: m9 Z3 G* z2 n- J
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]); j( f7 H) L+ J. Q
9 L. e& A* P' [5 x0 D$ C% H- g- return selPoints;
; s" X+ d+ j% y8 [, g- ^9 l - }
( b9 G( F# M0 p7 x! k' q: j
9 r8 z, w$ V( {: r- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
8 }. W7 W1 S+ R5 n7 K$ j - {
) L; Q% ]: d0 V. ` - Session *theSession = Session::GetSession();
, ]6 F2 q4 F7 u0 { - Part *workPart(theSession->Parts()->Work());- L( t& P0 D6 [: K$ l, \
, _: S' O, n" B/ | _. {/ w- Session::UndoMarkId markId1;7 K2 Z) O: q$ |# q) A1 W; q1 b
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,9 _5 n) ^! W1 O$ Z: e. W
- "Studio Spline Thru Points");2 L9 T; B" e5 R6 W7 f
( V$ D- [: K8 Q c) J5 G- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
1 h7 F( d x ~, U5 T
0 h e/ D* g6 k Z+ h- Features::StudioSplineBuilder *studioSplineBuilder1;" a: h' Q4 [: W3 N! a1 b$ b
- studioSplineBuilder1 = workPart->Features()->5 q6 O+ j3 k7 j- J* U; f8 x% } k
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
6 ^5 g0 J5 {5 _+ H0 Z$ F6 o: j4 R - studioSplineBuilder1->SetAssociative(true);! p2 Y n3 L4 o, q2 i
- studioSplineBuilder1->
# v, g1 `; {- x, [! o - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
0 C0 z9 B5 {% \8 s% H$ P! p6 M' c - studioSplineBuilder1->
6 t2 F1 {3 j2 q$ ]/ [ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! [8 d8 l; x: V8 S" ?2 E7 L
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
! n* f7 F! Q/ f! J1 V - studioSplineBuilder1->SetPeriodic(false);
- p* a/ [# _. ?/ C) Y - studioSplineBuilder1->
0 i: H# ]" V6 }: }7 L e" O: N9 }' } - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ l1 E; z( h g
- std::vector<double> knots1(0);4 Z1 e U+ n) D4 J
- studioSplineBuilder1->SetKnots(knots1);8 p7 U7 D' N6 B. m0 B' [# u& ~
- std::vector<double> parameters1(0);
) u$ G4 T7 }, z. A - studioSplineBuilder1->SetParameters(parameters1);
3 c2 y* X; k2 R - Direction *nullDirection(NULL);1 N; _% v! F, A
- Scalar *nullScalar(NULL);% { Y3 B8 e3 _6 g7 o7 l- C7 X
- Offset *nullOffset(NULL);
7 G Y8 X- e$ c& W - 4 }. D! G3 D, K% N$ d' u4 w
- std::vector<Features::GeometricConstraintData *>& k' ~+ ^, r* q
- geometricConstraintData(thePoints.size());2 T6 T4 j& P; `2 [+ v
- ! \0 z. ?9 B( }* m
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)$ P. H7 Z) s i" N% C
- {& g/ b+ ?* e; |+ r( A+ e
- geometricConstraintData[ii] = studioSplineBuilder1->
& x3 h# ]8 v. _/ @( m. N - ConstraintManager()->CreateGeometricConstraintData();
0 o( o1 R$ j, P* L7 B - geometricConstraintData[ii]->SetPoint(thePoints[ii]);3 U# a( x$ v/ Y* J$ R
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(3 g9 [/ f0 o; ~6 L, S
- Features::GeometricConstraintData::ParameterDirectionIso);/ t/ O# j: Y+ g
- geometricConstraintData[ii]->SetAutomaticConstraintType(
9 W U7 d9 @0 T# U - Features::GeometricConstraintData::AutoConstraintTypeNone);2 K7 [) h1 D% J [1 @
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);# u# Q( y! b7 \. r
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);! A0 d, Q$ i3 |5 I5 u u
- geometricConstraintData[ii]->SetCurvature(nullOffset);
1 D, B5 l4 N! _# x - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
- m3 s( w: Q' \- Q# A - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 q5 S4 b/ t% k, s# S& j7 f+ q7 S
- }- t7 f* S4 w% z7 v
- 1 `1 Y- ^; D' x5 N; E5 S
- studioSplineBuilder1->ConstraintManager()->SetContents(
1 z% y. h2 N* P0 v7 b* ]6 T - geometricConstraintData);8 d7 o1 M2 |/ `
; m% ?' G) D3 @1 b! W; K- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
9 A) H! r" c, W - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
3 T( P* f' z& @6 I+ `: J
- h! \1 O7 S5 ^& f' m/ z- p- studioSplineBuilder1->Destroy();& {5 o/ O; v6 k3 v" i' i
- - x+ P$ O- w( F1 t p
- return theSpline;/ V$ N( h; C1 s# {8 p* G
- }
; _; O: a7 v. D/ V: M5 W4 s
: J: g+ `3 \- |6 a/ {! O- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)' C8 K# G7 @( {# g5 j# f
- {
, f$ x" _4 ?( r - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");* ?3 e" G$ M, b2 [
- if (!thePoints.size()) return;
/ ^+ @$ ~% \# y7 i7 O) E( Z
, j7 z9 h) }. k' G: B3 y `3 N- Spline *theSpline = createStudioSplineThruPoints(thePoints); B6 _ }' _ H2 i3 |* D
x y/ \! Y! z& D# c- if (theSpline)
1 B2 Z1 {: S0 z7 D/ O' L - {
) ~0 ~$ V+ Y% w2 ~" d/ h. } - theSpline->Highlight();; J( @& P# D( x2 K e! W
- uc1601("Studio Spline Created Thru Points", TRUE);# S$ V. l( ?5 z1 e
- theSpline->Unhighlight();
$ }6 s! k/ u0 x; s% C) H H% K# d' \- g8 g - }1 F# {1 j! U, F( T+ b# z h$ j# g
- }
5 V: P' i+ w/ M& G2 s - <p> </p>
复制代码 , I7 R% A7 j9 A
|
|