|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: a k' t$ \: ZNX二次开发源码:通过选择点创建样条曲线
2 R. u+ T# z }
) T! ~+ X" r5 P# H' s' W* p
R5 r1 n a/ a# f/ X
! }9 Q1 T0 I1 J" U- #include <uf_defs.h>
; f, {( G( J- u) W! p. |- S8 R - #include <uf.h>1 O$ F8 o' D# T/ K0 x
- #include <uf_modl.h>+ j9 r! v+ V% I/ F& @3 C
- #include <uf_object_types.h>
6 M+ D D; K9 h) }! A' b& z - #include <uf_ui.h>
, W! l2 @6 g: d, X5 K. j- @ - #include <uf_modl.h>
0 s! {5 [& X! q3 J: }% W - #include <<em>NXOpen</em>/NXException.hxx>
9 S" z8 W! P+ r$ E$ R7 l - #include <<em>NXOpen</em>/Session.hxx>
" R" Q: f* E$ D9 Y - #include <<em>NXOpen</em>/Selection.hxx>
) m. l+ v3 p& x! C4 S - #include <<em>NXOpen</em>/Builder.hxx>4 C0 O% i) ^$ \! e
- #include <<em>NXOpen</em>/Features_Feature.hxx>! i4 W$ u# O- y; v7 C
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
. y* ^" B8 i, n% K - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
& S: o- t3 o" t - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
k8 [6 x' W3 g: x# `! P0 \ - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
7 f5 c2 Y) L0 L* g/ c l8 K5 G - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx># l' r3 ^9 p' N! k/ l9 g+ W
- #include <<em>NXOpen</em>/Part.hxx>
& L# g: ~- h+ v0 h$ Y( P7 J* _1 Q - #include <<em>NXOpen</em>/ParTCollection.hxx>
6 f. x' z4 P+ E, K# S% | - #include <<em>NXOpen</em>/Point.hxx>
' M$ Q' W$ u" w% R; N) L, r - #include <<em>NXOpen</em>/PointCollection.hxx>
& v6 U& C+ \5 C* I' o/ d% \; w6 P s0 @ - #include <<em>NXOpen</em>/NXString.hxx>
& r. `7 o% {6 b6 ? - #include <<em>NXOpen</em>/UI.hxx>3 v( b- J' d7 i7 ]$ s1 C
- #include <<em>NXOpen</em>/Spline.hxx>
" D, w. B( x. m - #include <<em>NXOpen</em>/NXObjectManager.hxx>1 h- O' H) F J. Y9 X
- : ~( @$ B( h! L6 p
- using namespace <em>NXOpen</em>;
; i( ~2 r% s4 W7 Y - using namespace std;
* l2 V6 X: h" I8 k% I - , e! O2 l" c8 y3 I+ T: r0 b+ }+ `
- extern "<em>C</em>" DllExport int ufusr_ask_unload(): r1 C ~' y% S$ I! {, L2 ^$ Q
- {
, J ?4 w' c- R& Z% z - return (int)Session::LibraryUnloadOptionImmediately;( l- }+ R4 ?" |7 R7 Z
- }
& _( J8 N( s5 v# U+ H+ B
* t: g' S* ^8 C* e0 M2 W4 P- static vector<Point *> selectPoints(NXString prompt)* C. Z8 u) g; C/ x' W, \ l% u
- {
) b+ y% t0 E+ ~* _, B) C! C) f - UI *ui = UI::GetUI();/ V( B" n/ Z$ K" R- l
- Selection *sm = ui->SelectionManager();
; F5 R! e( t* y; r5 K* F - std::vector<Selection::MaskTriple> mask(1);: e9 k8 Y' j( V
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
5 g3 Y! w/ b3 ?6 {. y. j' C: K - std::vector<NXObject *> objects;
; a& D$ q8 R( ^- r( `
; }& `% p1 N( a; f6 {4 {- sm->SelectObjects("Select Points", prompt,
, h& r$ ? t( l0 |" p - Selection::SelectionScopeAnyInAssembly,4 M. c0 ?7 G; M5 {
- Selection::SelectionActionClearAndEnableSpecific,3 a% P9 r1 n& s/ d8 _9 I ^
- false, false, mask, objects);$ \) M( }! q. V4 m. H; ?1 \+ Z
- # h6 c7 b- P* m( O4 u3 @; u5 `* E" o
- vector<Point *>selPoints(objects.size());7 ~5 Z! R9 a' G
- for (unsigned int ii = 0; ii < objects.size(); ii++); M2 Z# Z: L7 w. z: K: @/ z1 F
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
7 m- K# J+ A9 \- U. x - ; \( u; x4 B, X" h
- return selPoints;" T5 T! W" K6 B6 f
- }6 r. x# ^1 c: i( t1 _
- 2 q0 i$ ^ D' o$ [. a2 P2 S! {
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)7 V2 _6 _! c5 ]. u3 U
- {1 f. O/ |4 q9 h* V8 B
- Session *theSession = Session::GetSession();8 |, J6 c. j8 y. v/ ?6 ]
- Part *workPart(theSession->Parts()->Work());2 `% P9 r( }0 S- J8 r9 m- M( k; m
3 |. s% w8 K' [6 A# a" c- Session::UndoMarkId markId1;
3 ?3 w! o* p* Y - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,. M! f5 D$ J: z) G2 O$ j7 G3 Q
- "Studio Spline Thru Points");4 `& C- {- p1 t P( H# A4 Q
, Z, j9 b6 Q. m' [9 I! H, r- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
% V- I. ]1 i0 |, i+ W8 y. g) {1 `( j
U) K8 H6 U2 F- Features::StudioSplineBuilder *studioSplineBuilder1;; o+ T. h3 p, y( h* b
- studioSplineBuilder1 = workPart->Features()-> N1 N3 l, v, `" W) f, l! \
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
4 T' y1 X7 P, y - studioSplineBuilder1->SetAssociative(true);
6 X3 `" L( E3 |, ^- S - studioSplineBuilder1->% [4 r3 X4 E! t4 x6 g% T; M9 G
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);1 w" K- c3 g) ?/ W1 ^
- studioSplineBuilder1->
1 D' a4 g* G' B( k) _& r _ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 B7 P t t. A3 n7 Q
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
% O% g0 A0 ]6 x% g8 k; I9 A - studioSplineBuilder1->SetPeriodic(false);
) K6 a8 V: i$ \, d, n - studioSplineBuilder1->
( {6 I7 e0 E5 e# t j0 u - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
& z, S- A) V. t3 A - std::vector<double> knots1(0);
0 y% o/ z3 n. k8 w - studioSplineBuilder1->SetKnots(knots1);
8 R! `' m' _% w k6 N - std::vector<double> parameters1(0);
7 ~$ c) G4 d9 A2 H" |! z - studioSplineBuilder1->SetParameters(parameters1);
^0 j* w( z. {4 _; B - Direction *nullDirection(NULL);- i4 U# u" C+ B$ j1 _0 j
- Scalar *nullScalar(NULL); K2 i$ D4 k3 G3 b, w
- Offset *nullOffset(NULL);
9 g% t- I4 w: k: S - 5 ?3 }+ }# f$ k1 R
- std::vector<Features::GeometricConstraintData *>* P6 s- E8 q% ^5 Z
- geometricConstraintData(thePoints.size());
# g4 W9 r1 u) ^* l. c _
9 L a9 H/ l' ^' e# |6 l- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
$ ?' Q9 J# R; G; K& ?9 T0 V - {3 v( d& p2 P8 F' G+ P7 M$ ?
- geometricConstraintData[ii] = studioSplineBuilder1->
' v+ m& z: I: _8 B3 ] - ConstraintManager()->CreateGeometricConstraintData();( j2 q+ r# v$ H% z5 O. L3 F
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
" p! M: c& o; {2 b# M8 v4 r+ V; { - geometricConstraintData[ii]->SetAutomaticConstraintDirection(" N ?% S. G1 Q/ f3 X$ {
- Features::GeometricConstraintData::ParameterDirectionIso);0 `1 l# l8 r4 O/ m- M: ?: q; w
- geometricConstraintData[ii]->SetAutomaticConstraintType(5 b$ U- C+ H( t
- Features::GeometricConstraintData::AutoConstraintTypeNone);6 V% N( f# e2 P u. H
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
/ m' p8 }* x' K8 B9 v1 x* d2 L - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
2 ?) C' E5 a. F6 C3 { - geometricConstraintData[ii]->SetCurvature(nullOffset);
# F& C% [( c: i2 J3 t- \' a6 { - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! z7 e7 Z# x6 ?
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
7 ^1 a$ f( C" r! w) C+ o& r' D" s/ ] - }
# x/ u- h& e! d5 }( r& q7 | - 8 a6 `# V0 L9 N, z4 r4 M% d1 C
- studioSplineBuilder1->ConstraintManager()->SetContents(+ r1 w0 u* ?: j) ?8 u
- geometricConstraintData);
0 G1 g$ f7 _- ^2 ~ - & z1 ]; m# G$ b) n
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
* y/ ]) M! r2 a8 `- V - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();7 A- f( q r a& D) j4 G
# v8 |7 ~# M. G- studioSplineBuilder1->Destroy();
1 @ I( Y* O$ V& ~' Y9 c
' ]8 F! \4 W; Y' V) A' p& J- return theSpline;3 e- o p/ g0 ?
- }
- T' F: X$ |- ?0 w" F. |! s9 A, x& ] - : k- H$ p) Y9 `* W7 l' x) ~
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len); V6 Q( E; Z6 w/ A
- {
7 C8 V! w0 a& k6 K) V. k - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");5 D# H; l, y6 j
- if (!thePoints.size()) return;
# K4 P% O, I4 w2 k4 m
% a2 ^2 P# G" K% y- Spline *theSpline = createStudioSplineThruPoints(thePoints);
6 } g9 y. r9 h2 Q( w - , r$ v7 e$ q: y' q& x* e2 v
- if (theSpline)3 S5 x8 x( I; I$ `3 n2 E
- {
U4 O8 Y0 g6 ~8 H - theSpline->Highlight();$ N4 {2 ~3 Y) ^5 v
- uc1601("Studio Spline Created Thru Points", TRUE);- U2 Z7 T: i8 E& j7 t8 V/ x; d
- theSpline->Unhighlight(); w7 Q' D. d4 @' }; e* X3 `9 X
- }
- p$ i1 V! Y+ I0 R7 t* ^ - }, n* G6 x" d! D$ O; [' D
- <p> </p>
复制代码
2 q5 s% O! m* }' B1 y |
|