|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 o0 F9 ?8 ]5 f$ BNX二次开发源码:通过选择点创建样条曲线
+ V8 ~! A" L5 x$ n9 m
?- Y) u- O: I+ Z
) @7 C( |/ o/ J8 K2 A. R, w( ~
+ D4 O8 c, }( m) g! z, Z# H3 ~- #include <uf_defs.h>
1 _7 {8 X7 L* t! O) P% R* T - #include <uf.h>
5 f4 h; {. P J+ b - #include <uf_modl.h>
2 _! V Q g3 l2 {! w( i, J- \ - #include <uf_object_types.h>* @5 ?4 Z9 T. L& a I0 {. x" W
- #include <uf_ui.h>6 g7 ]) w6 {* w b; [
- #include <uf_modl.h>* }8 n/ i4 m/ O4 R+ J
- #include <<em>NXOpen</em>/NXException.hxx>
+ j; ^$ ]2 C; Q, E8 m7 O. P0 { - #include <<em>NXOpen</em>/Session.hxx>. a+ ?: S5 ?) B- }3 F! X
- #include <<em>NXOpen</em>/Selection.hxx>
6 p& `. ^+ w. t1 z - #include <<em>NXOpen</em>/Builder.hxx>
( J* D2 w2 t2 J9 ]/ W9 s - #include <<em>NXOpen</em>/Features_Feature.hxx>; c, A g5 L: B
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>) D. h) n* T5 ?+ ?1 v7 b& ?
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>) l& D: m0 s7 O: u5 z# \
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>4 \3 r3 L( t, X; R) t P0 P' u
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
4 o/ J0 Y" B$ b7 |6 O* I2 N - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
6 ^! r! C; q3 G0 Q - #include <<em>NXOpen</em>/Part.hxx>
6 U, L9 z4 m2 s( I }/ K; Y& O0 }0 p - #include <<em>NXOpen</em>/ParTCollection.hxx> S* Q, \& R5 @4 }
- #include <<em>NXOpen</em>/Point.hxx>) j5 @0 G" Q$ S2 T b8 ^% C
- #include <<em>NXOpen</em>/PointCollection.hxx>
$ ~0 K$ \, ]" E* `! w - #include <<em>NXOpen</em>/NXString.hxx>
- |, {1 x& ?! Z4 {+ C; E8 z) N - #include <<em>NXOpen</em>/UI.hxx>
+ S/ v9 E/ Q2 H7 K& E - #include <<em>NXOpen</em>/Spline.hxx>; k) B6 r6 i P! C9 A% d" ]& n
- #include <<em>NXOpen</em>/NXObjectManager.hxx>
9 g, }( H. ?: f5 C- O - + {7 D4 ~4 P9 S# A# Z( d8 K; n" R5 P
- using namespace <em>NXOpen</em>;7 f# {9 H" E6 g$ Q$ n
- using namespace std;
9 u @9 b# | j) \" D5 b) D - & H0 E/ a/ l/ O
- extern "<em>C</em>" DllExport int ufusr_ask_unload()3 I4 W3 w8 ]% A
- {
4 V3 g- R# ]' m0 f9 |- m# z - return (int)Session::LibraryUnloadOptionImmediately;3 w6 T# J; H9 {3 m8 Q& U* k
- }5 _' @0 W. S0 E' E8 s
* s; U* H; z0 x5 l0 ]: o; s( L9 ?6 ]- static vector<Point *> selectPoints(NXString prompt)* k0 v9 Y: V3 v( e
- {9 ]( B1 [5 ~ a( I7 X
- UI *ui = UI::GetUI();
5 ~ K1 F- }+ v' x' \$ u - Selection *sm = ui->SelectionManager();
, K9 w# y/ g4 i8 o+ ^/ U - std::vector<Selection::MaskTriple> mask(1);! { N& a& N) q& Y$ y% b
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);5 n# a7 q `1 s+ H, x
- std::vector<NXObject *> objects;
t9 c; L' ]. a9 J" s3 F) V - 9 g4 a( {+ f# P3 q' I
- sm->SelectObjects("Select Points", prompt,/ V" A3 J% x1 ~
- Selection::SelectionScopeAnyInAssembly,
! r: o( D$ j: ?( \! C k - Selection::SelectionActionClearAndEnableSpecific," k$ P4 E- x C# {! Z0 v) K
- false, false, mask, objects);
) Y4 l G9 C- D. y
. f1 G! a, m0 o. _1 Z- vector<Point *>selPoints(objects.size());
& K& r( S }& }1 g - for (unsigned int ii = 0; ii < objects.size(); ii++)
}1 `% |# J, n6 [( Q$ Z' ]7 f0 y6 { - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
3 H6 D; e0 ^( C
6 ~$ d. l7 u2 v- ^. ]! @ `- return selPoints;( J8 `0 W( L" ^1 s8 w/ N F
- }
2 h9 N% X( i* c$ n0 b. j- ^ - 4 _; [" X8 `3 K; q0 V
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
4 b, n Z: A6 ?6 G* H) c+ h( A0 T - {
8 L& W3 \& E# l+ L2 ]9 a6 r - Session *theSession = Session::GetSession();7 d% d! z6 z8 }7 A" N4 t
- Part *workPart(theSession->Parts()->Work());
, p% K! x, R' U
& Y4 S. S8 `3 }- Session::UndoMarkId markId1;
9 Q0 `! ?& ~% h2 q' G - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& @) ?$ L- w( h
- "Studio Spline Thru Points");9 O2 I r- N _# s. d( r2 I
: C/ x1 `9 o9 I) F- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
. P* c2 l( f# a; d& P - / \# P9 Z) Y8 B6 A
- Features::StudioSplineBuilder *studioSplineBuilder1;9 P( C9 N' L3 T& ]% @- S/ t# E
- studioSplineBuilder1 = workPart->Features()->4 \' f' p' H; T$ ~+ n
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
, N9 q6 X# _; f - studioSplineBuilder1->SetAssociative(true);& n& @7 r6 W. i4 m3 t0 s2 S, A
- studioSplineBuilder1->: ~4 f# E; p/ O1 z$ O; J1 Y& x
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 u1 e1 B o6 o0 Y3 V
- studioSplineBuilder1->4 g- N7 r- ^! z' ^; ^, r- N4 W
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
5 C, ]+ @/ T# M/ t - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
8 }# }6 E5 [( ]* C - studioSplineBuilder1->SetPeriodic(false);/ O. c( Y, f: S. o7 A* z
- studioSplineBuilder1->
/ H8 w3 W& L; W - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# J/ B+ S) ~. t
- std::vector<double> knots1(0);# @3 {$ x* n* }2 R! L
- studioSplineBuilder1->SetKnots(knots1);. g7 q5 B: o/ U0 W9 n
- std::vector<double> parameters1(0);
+ [- P0 Z2 M2 w - studioSplineBuilder1->SetParameters(parameters1);
$ q8 a5 x& n! j3 D; i. A, q - Direction *nullDirection(NULL);3 @: S: ]- x, O1 V$ r# v3 Y
- Scalar *nullScalar(NULL);
# e3 f3 \7 [6 X- L& L3 a - Offset *nullOffset(NULL);
" _! @2 h7 _9 e$ c( w: D) f+ b - 2 ~7 B: f0 _2 {' Q, {
- std::vector<Features::GeometricConstraintData *>2 Z" V! f3 x* E0 n6 Y( J
- geometricConstraintData(thePoints.size());
5 p+ K7 S k; F
0 G, Q4 Q- l |% Y/ |& d- for (unsigned int ii = 0; ii < thePoints.size(); ii++)' W6 u2 V; x: R$ k
- {8 d$ P6 }3 [! X% v: [( p
- geometricConstraintData[ii] = studioSplineBuilder1->
' I, @/ f6 C' w - ConstraintManager()->CreateGeometricConstraintData();* A+ l6 V! R2 e
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 q: X% U/ o) y! ]
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(0 I# U+ N' s* l i; B" j/ F4 ]
- Features::GeometricConstraintData::ParameterDirectionIso);' v, e8 }+ D5 l# \ k; ^5 Q
- geometricConstraintData[ii]->SetAutomaticConstraintType(
& _; ^ p4 {8 I3 j* D# F - Features::GeometricConstraintData::AutoConstraintTypeNone);
* R ?, z- g, i% U+ K2 v) u - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
0 r3 F& H8 v" }* b: J - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
0 Q2 Y/ F. W' D5 T8 f$ Z) g - geometricConstraintData[ii]->SetCurvature(nullOffset);
0 e8 e) f8 c* e6 L- B - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);8 R$ F m4 o) v; G4 O' a
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
. Z: q3 l& Y, s1 p; ~) f* A0 G5 {2 X% Z - }% _; _# N8 L# ]! o; M
6 w* u, i8 Y& }0 G7 D8 ]& _- studioSplineBuilder1->ConstraintManager()->SetContents(
) N g: x7 n7 \8 t7 k - geometricConstraintData);
5 P" L' o" {* E" w
% Z0 {4 }% f' N: }6 C: L* @! r- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
# v' |3 Q/ T4 _# Q5 r - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
& N2 u" V0 o5 R! g - . R2 i- X/ @5 D; Q& u' ~
- studioSplineBuilder1->Destroy();
2 O3 C" J% Z$ K7 s, a; c2 }4 _, H$ i
1 Z# h# h9 G3 `! n% e6 k5 x% t$ X- return theSpline;
3 b" `( `( i$ F- x6 W2 l% D Z - }
% g- Y2 y8 H1 ^6 |# x - " Y1 D0 \1 T. u
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len) f- [" R" j9 n/ |" G
- {$ d, M; L# T; Q3 S0 V& J
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");, C. E' M$ f& |8 ^9 u* p
- if (!thePoints.size()) return;2 T* F9 s3 G. p* t! u# D
. O9 Y) V! V* G- p* `+ ]- Spline *theSpline = createStudioSplineThruPoints(thePoints);& X& I: [! ?0 X0 |* J8 m
- 9 A$ S& u& A6 V5 X" }
- if (theSpline). P/ L" c( k" T* ?$ _4 A' O
- {% g9 @6 L2 [' G7 V1 @& `
- theSpline->Highlight();
5 ~9 H: U0 u+ E* L) ~ - uc1601("Studio Spline Created Thru Points", TRUE);
% h d2 x( [, e7 r M- p - theSpline->Unhighlight();7 n$ N. V& z( A6 Q
- }0 X9 T: l+ j( E
- }
' D' O7 L0 V; i! M - <p> </p>
复制代码 4 u% `5 l& }6 O
|
|