|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: D! h3 D. |$ I3 S
NX二次开发源码:通过选择点创建样条曲线
# h0 D& o) }0 _3 W. e+ u: |
) r6 I- s5 }" Q( |3 [2 G% d5 ^* N5 Z/ R9 b. k& r( V& ]' E" W
3 `: w% n$ G5 n2 G! C- l W- #include <uf_defs.h>
/ e+ h, m9 S! U4 X7 w+ ?6 Q4 x7 { - #include <uf.h>2 |- E: A8 C' S! c0 s0 N8 U
- #include <uf_modl.h>. D; d- a6 T n! j4 J' i( k4 T
- #include <uf_object_types.h>
+ }% q! k3 }8 u, m) p - #include <uf_ui.h>- E% Q! c2 a. N0 r5 k
- #include <uf_modl.h>
/ H" E% C; B. H7 b) V: ]3 S - #include <<em>NXOpen</em>/NXException.hxx>$ W, L6 f4 P" U, i0 v) J4 O
- #include <<em>NXOpen</em>/Session.hxx>7 n2 I# z* U" _( @; ]! k
- #include <<em>NXOpen</em>/Selection.hxx>
2 R% u2 [2 {0 D6 d2 ?+ W' r - #include <<em>NXOpen</em>/Builder.hxx>- `# \" N$ K R8 j
- #include <<em>NXOpen</em>/Features_Feature.hxx>8 i) G8 O+ m. {0 m- h3 q/ M
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>% j0 {) _ K/ R
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>0 f; L, f. N7 m0 D; }4 h
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>5 v) ]: J, E" T- {
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
+ L, T2 J' V% M* S# @. w - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>- Y2 J: J7 x \& k9 G& `4 O
- #include <<em>NXOpen</em>/Part.hxx>
$ w# P& I7 X; W2 \/ u+ g - #include <<em>NXOpen</em>/ParTCollection.hxx>7 h3 y1 M1 H# S1 X
- #include <<em>NXOpen</em>/Point.hxx>* n9 O0 ~: i5 w$ @
- #include <<em>NXOpen</em>/PointCollection.hxx>. k5 u* e6 L& w+ k* w5 R
- #include <<em>NXOpen</em>/NXString.hxx>
; f6 B& j4 V% `7 P# T" w5 Y6 [ - #include <<em>NXOpen</em>/UI.hxx>
0 D: H! k5 _- z& C9 h- r - #include <<em>NXOpen</em>/Spline.hxx>
7 B7 }9 Q- f3 S' W o+ R; E - #include <<em>NXOpen</em>/NXObjectManager.hxx>
6 d, q' J8 O4 K( K" c
/ W; Q( D3 h3 ?0 {# m- using namespace <em>NXOpen</em>;
0 B( ^" E, X1 h8 _ - using namespace std;
1 d/ \/ R6 A% ]1 g8 d6 i
- j0 `3 y7 }, Z' g+ ~8 j# S: [- extern "<em>C</em>" DllExport int ufusr_ask_unload(); z) w( S u0 V: h w, ]
- {
( T- I* m0 A+ J6 m1 o - return (int)Session::LibraryUnloadOptionImmediately;
& E$ N" e2 C2 H8 m/ W! t - }
# M; ~* s' _$ J/ D
7 ]- a( T0 |9 H. i& j9 u- static vector<Point *> selectPoints(NXString prompt)( ~9 b, x! i+ {3 [: u5 e3 ~4 o
- {7 k) J0 L5 ]" P7 M: {
- UI *ui = UI::GetUI();
) k0 B0 |7 }* M2 Q0 i5 E# e$ Z - Selection *sm = ui->SelectionManager();
/ z" z# ] P, L! j7 A. n6 { - std::vector<Selection::MaskTriple> mask(1);% d/ O- \4 w9 w X+ a
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
% o& G# i4 Z9 U* j - std::vector<NXObject *> objects;
: n f& I' y$ u
/ q4 e7 Z% R, q$ a/ s- sm->SelectObjects("Select Points", prompt,
- Z& P- b2 g$ V2 B2 J - Selection::SelectionScopeAnyInAssembly,7 q; Y# l9 U3 X# b0 c
- Selection::SelectionActionClearAndEnableSpecific,
- h6 h6 Q" }* ^! `, W, \ - false, false, mask, objects);
) H$ d: L1 T- V( k+ ~* D - " D' U# V: _, \
- vector<Point *>selPoints(objects.size());/ t9 W/ L: a4 E) d! V' x; b) b# g
- for (unsigned int ii = 0; ii < objects.size(); ii++): \7 Z" P6 O/ M! } `3 ^
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
* C$ R- `& w1 D2 d) } - / Q2 d D/ b" G# `4 T* s+ b
- return selPoints;
( i! j1 w) {& A' T$ ` - }
3 E$ y1 K) V5 } - , P: h' F8 N2 C# f3 ~5 M, B
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
" t/ A, E) W6 }1 \, ? - {
( m; D0 O9 m5 H ]% p( l1 d - Session *theSession = Session::GetSession();
! \- V' g/ |* g - Part *workPart(theSession->Parts()->Work());
6 E; l$ N) N' L: R( Q+ t - 4 v% @4 T! K' d1 L. |
- Session::UndoMarkId markId1;
; T1 X; C, X8 v9 s, Y9 X - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
{: g0 \% v+ O - "Studio Spline Thru Points");0 V1 w+ G Y* h' V* k
- ' e1 F- I* j" o# V
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
. r! t- l# u1 \2 F - / I; X! v$ n. j
- Features::StudioSplineBuilder *studioSplineBuilder1;
' X5 S) Q4 g; ?/ {- n7 Q. B C - studioSplineBuilder1 = workPart->Features()->" u3 {- B( l/ ^. O
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
# y& q$ b% F" k1 J* E% V - studioSplineBuilder1->SetAssociative(true);
% }3 O8 \( E3 p1 t0 E8 t - studioSplineBuilder1-># b. x4 ?$ E/ u0 h5 }
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);, F2 `. p/ A6 \; C8 Z" F* `: P
- studioSplineBuilder1->1 B1 `' x: h; r
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);; v7 c9 ~! q3 c% X3 d4 i* e3 h
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; M5 l% P: Q) p7 y2 \8 F) m, ]" n+ N
- studioSplineBuilder1->SetPeriodic(false);
5 u9 x! [; `: r! `( z - studioSplineBuilder1->* c! t- c0 e& l1 A' A- A
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
4 }& I# c0 {5 E( M# H6 X( O - std::vector<double> knots1(0);" Z0 e/ M& a: E* C! ^* L
- studioSplineBuilder1->SetKnots(knots1);, j' R$ g6 o, j, o
- std::vector<double> parameters1(0);
- X9 I: _$ `+ _ - studioSplineBuilder1->SetParameters(parameters1);, m/ h$ @4 \4 a" G+ Q3 V
- Direction *nullDirection(NULL);$ y+ ^3 H) w) [2 U0 ` h3 s! D
- Scalar *nullScalar(NULL);6 |0 y( }% E9 i9 x$ i/ ?2 N
- Offset *nullOffset(NULL);( \& W7 r6 ^% m1 n- i
7 M1 ?- k3 C- M5 T+ E7 i \* t- std::vector<Features::GeometricConstraintData *>
0 Y, c7 }2 d/ s5 r! [# x8 e - geometricConstraintData(thePoints.size());
5 B! m4 P# R3 P$ n6 S7 j( Z+ T - # B% L, ~3 [* J S& d. J
- for (unsigned int ii = 0; ii < thePoints.size(); ii++) l4 }0 E! J' J' [4 k" G) [
- {
8 L4 W) a$ u9 h3 p z% f - geometricConstraintData[ii] = studioSplineBuilder1->% V( I& y$ _# w* c( X+ R# q
- ConstraintManager()->CreateGeometricConstraintData();
1 y6 ^9 g7 s" ]& p* O( ` - geometricConstraintData[ii]->SetPoint(thePoints[ii]);2 [1 M$ ~+ j- I
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(& y1 T$ D3 P0 F) ]8 v8 Z! b. E
- Features::GeometricConstraintData::ParameterDirectionIso);6 Z# R: i. c7 f( n; y
- geometricConstraintData[ii]->SetAutomaticConstraintType(
) s, B3 |( A+ m' g6 K% A - Features::GeometricConstraintData::AutoConstraintTypeNone);: ]" z# [- I; [
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);' c; ~. ^3 I0 ^( G/ W" L* t
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);, @8 y4 W% {/ f( ^
- geometricConstraintData[ii]->SetCurvature(nullOffset);" V. L$ d0 w9 c% D8 f0 D& z
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
* {* p2 M1 F f1 [; N& @7 L - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);8 D4 j1 h# }# v( r. B
- }
4 T" p7 `- @0 r
! W: v9 N: z3 s; h' Q# q5 P" S `/ [- studioSplineBuilder1->ConstraintManager()->SetContents(
, g$ w) U( |, e( k - geometricConstraintData);
4 X% T) ?9 D( L5 q8 P# X h
" O! o8 o( X. H O. G6 {$ I- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();' }. ?1 c3 K1 i8 c
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
) w' x: y6 T1 z( H* L
. B3 m/ z. n! s- studioSplineBuilder1->Destroy();5 u6 H7 i% U2 W) x4 F0 w3 P+ b
- 3 T" I8 d) n2 E. L0 p( ]* C g
- return theSpline;
7 M' H4 g7 f x- O" q" A( w; v - }
" L _$ x+ Z: e% Z9 S# v& J3 v
" j0 N( k+ H/ r+ K9 @- e- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
8 v- e1 s& ?# C6 X; d - {
" y) b8 t+ a d - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
& P+ r5 D# p y: S4 _ - if (!thePoints.size()) return;
4 h" h; t' q9 Z* n% ?- G& u6 m
+ p: s2 ~1 ?, u, w- Spline *theSpline = createStudioSplineThruPoints(thePoints);
7 u6 ?/ F' y4 C+ P# F
- [, Q/ b8 y, b4 P- y! v- if (theSpline)
, { Y1 M' Y* N2 ^) D% e' y - {
" m, o0 N' j9 p" h3 b% l - theSpline->Highlight();) |3 Y. @* |( V, S3 `8 F
- uc1601("Studio Spline Created Thru Points", TRUE);8 N. V! L& n. q2 T1 {
- theSpline->Unhighlight();. S" e a( V! c# g8 x7 i {
- }
9 w& o/ o$ t' {+ L: X( K - }
* ]7 }1 T0 R( ] - <p> </p>
复制代码
5 z( ~* s# f+ M3 U( J+ D: i3 E |
|