|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& j* w' @0 o7 K- W% [NX二次开发源码:通过选择点创建样条曲线
0 j: X7 X% e1 ?! g* `2 S. B
5 Z3 u' w4 o0 Q$ {; g$ q1 Z8 _
3 {/ y7 u) o- G( x& D- ( H) s3 ^) e) b) x: ?! I
- #include <uf_defs.h>+ M" U# |" N( c- p G
- #include <uf.h>
: v9 H a7 v9 \ - #include <uf_modl.h> p Z4 B6 g1 N, Z; b
- #include <uf_object_types.h>, t& z* G+ A& y
- #include <uf_ui.h>$ `* W( ~, ]4 r# l
- #include <uf_modl.h>! ~: }$ {1 ?7 b' M- T
- #include <<em>NXOpen</em>/NXException.hxx>" I5 O r; Q' m# B& r
- #include <<em>NXOpen</em>/Session.hxx>) [5 a2 m- V2 L0 e1 h, d* Q
- #include <<em>NXOpen</em>/Selection.hxx>
4 _8 ~) I* ^* [- c - #include <<em>NXOpen</em>/Builder.hxx>9 V; S" v+ O' i0 o! v+ B
- #include <<em>NXOpen</em>/Features_Feature.hxx>5 {+ f0 m7 l! L) D! J
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>& d& g8 t% C0 z9 ^
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
/ s1 K; u% e! v/ \1 I$ \ - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
% w/ H/ |+ h* B) @! \ - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>6 @4 ~" w* B* k T
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>% z: P. I( `' o i1 f
- #include <<em>NXOpen</em>/Part.hxx>+ P4 |; `& J( a6 n1 |6 o! E
- #include <<em>NXOpen</em>/ParTCollection.hxx>3 ~8 v6 f. ~$ i2 X' N7 P" K7 u
- #include <<em>NXOpen</em>/Point.hxx>
8 z- [0 n/ b3 M& D+ M6 d - #include <<em>NXOpen</em>/PointCollection.hxx>) d; P, J1 A& X5 }/ Z: W# D( P
- #include <<em>NXOpen</em>/NXString.hxx>2 F9 q* P: ]4 I1 C
- #include <<em>NXOpen</em>/UI.hxx>
" g5 n8 R( ~) j) I' p4 j4 B* [( U; j* L; C - #include <<em>NXOpen</em>/Spline.hxx>
! A9 S" l0 W& c% Z6 ? - #include <<em>NXOpen</em>/NXObjectManager.hxx>
2 I0 B# S5 G8 f6 u2 C
& w* O1 e7 U& T$ h- using namespace <em>NXOpen</em>;
) {. F& O; v6 L4 S/ f& m - using namespace std;1 `; w! D+ f$ Q' H' b
- ! V( A4 s6 D" @0 r2 x3 o% [4 |
- extern "<em>C</em>" DllExport int ufusr_ask_unload()& e5 T3 w% t% n0 z
- {
% T B2 f& e9 S+ h5 l - return (int)Session::LibraryUnloadOptionImmediately;
8 R2 ^) W }; q7 ]6 b - }3 ~2 E. V5 J0 o. l$ s- u4 y
7 V: D3 G+ T) }$ W- static vector<Point *> selectPoints(NXString prompt)3 L0 t; o) y- A: B9 W
- {
9 D; U7 r, a* g5 S5 P5 c - UI *ui = UI::GetUI();
$ E! }: ~+ }5 W4 h2 }9 {4 p. M - Selection *sm = ui->SelectionManager();; o+ e& H2 H) W! ~
- std::vector<Selection::MaskTriple> mask(1);
8 y5 s. A+ g+ F2 d - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 \& w4 q3 Y7 R: q9 i" g
- std::vector<NXObject *> objects;9 R% f7 ~8 d5 g# k9 _+ Y
- 3 N) G {6 h! I5 S6 L8 d
- sm->SelectObjects("Select Points", prompt,, f* t$ L6 q; Z9 I# X" l9 w
- Selection::SelectionScopeAnyInAssembly,
$ ] N- Z' U. D5 f$ ]7 r3 E - Selection::SelectionActionClearAndEnableSpecific,7 M3 s" y6 n* Z) `
- false, false, mask, objects);* ^0 I K4 Y" v6 V/ ^- G
- 7 x4 X' M# [: Y3 q% ?1 w
- vector<Point *>selPoints(objects.size());
$ A3 Y3 ?; m& m8 z - for (unsigned int ii = 0; ii < objects.size(); ii++)
6 M5 v/ M" d$ N% N - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
3 u" l' j" K* M - 2 m0 x% l5 l* ?, d7 i+ O
- return selPoints;
5 d# Z, P( O7 y9 V - }
V, l \$ s/ D% p8 V; A$ ?4 z5 V - 5 e y- E$ L- q# S; m: J
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints); y& J* S/ ]# l" M3 l; `# d
- {$ ?2 Z+ l7 l/ t+ w& \- L- x
- Session *theSession = Session::GetSession();* E* B/ }; a1 S% f8 H9 t$ p, o# m
- Part *workPart(theSession->Parts()->Work());
. Y( L: s C, a
6 x/ k P0 h" e: H( W- Session::UndoMarkId markId1;
u% F# s: c6 N3 p- z( Q! e - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
4 X }) s9 n+ Z. N: k3 y - "Studio Spline Thru Points");
, S& J2 ^. _: G% l# R3 p. G
+ j$ {, w) ?3 b- Features::StudioSpline *nullFeatures_StudioSpline(NULL);" [4 X6 x$ ]3 w) z; m7 x
- 4 b3 ^" O- o# d% m \+ ^
- Features::StudioSplineBuilder *studioSplineBuilder1;
! S" A. t2 K% p- x - studioSplineBuilder1 = workPart->Features()->1 K; z& j7 ]2 s
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);, l) s( @/ ?! r! Q2 t& O# ~
- studioSplineBuilder1->SetAssociative(true);$ U4 A+ ^8 q& i7 A6 T
- studioSplineBuilder1->
# G' _* p. n( m2 T - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 {! C/ Q) A* P8 Q
- studioSplineBuilder1->
/ Z% o( A% l. B& Y! } - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);' A; M B8 [. ^* X, D( {1 p! M
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
- a& M( V0 e5 @* A - studioSplineBuilder1->SetPeriodic(false);
$ y4 j5 O. L" p) t0 P# I; f - studioSplineBuilder1->
4 R7 O5 d# H4 D+ g. i - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% M( L, p. M, e' t
- std::vector<double> knots1(0);; S8 T# Y' L1 Z% x! m; E) W
- studioSplineBuilder1->SetKnots(knots1);
9 X5 S, j# J+ `3 X/ [/ U - std::vector<double> parameters1(0);
! B' S. @1 `9 w' B- o - studioSplineBuilder1->SetParameters(parameters1);
( P' |9 E- R, Y, i% | - Direction *nullDirection(NULL);
7 |8 e9 R' c: K- O* J$ W - Scalar *nullScalar(NULL);) M9 l% Y7 u0 l. l! \6 \
- Offset *nullOffset(NULL);
- |9 B7 [" y; _3 k
8 V: `- U% d4 b1 ~- std::vector<Features::GeometricConstraintData *>- L; S5 T7 h5 `. b, o. @2 F# Z
- geometricConstraintData(thePoints.size());) U8 v" P0 g7 J8 a. w4 [
& m3 h9 T1 e: h9 @; z R- for (unsigned int ii = 0; ii < thePoints.size(); ii++)* d" x5 C+ l, W/ @* c8 [: L
- {
# \: r/ ]! U0 S* P2 n/ \ - geometricConstraintData[ii] = studioSplineBuilder1->% Q% \& i! M5 ?5 y
- ConstraintManager()->CreateGeometricConstraintData();0 v [9 A1 v1 v! ^+ d
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
) g. {8 ^" o `) O8 P2 U - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
) W! D, s+ E/ @! ` - Features::GeometricConstraintData::ParameterDirectionIso);
1 a/ F1 t' |" |7 a1 B4 ^0 M8 I - geometricConstraintData[ii]->SetAutomaticConstraintType(/ ^7 U, _/ W$ R! v: e
- Features::GeometricConstraintData::AutoConstraintTypeNone);
3 P \# s2 Y3 N5 m6 M - geometricConstraintData[ii]->SetTangentDirection(nullDirection);) R: {. ?4 K8 X8 l6 M
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
4 h* I9 \+ E/ M. B/ K8 w0 s9 B - geometricConstraintData[ii]->SetCurvature(nullOffset);
! Y& G# q; t- h! A# ^3 D - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
, I4 N% Q( K) c4 F1 \ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" S& X0 l# C& b7 z8 Q& L' e
- }
. s" O( w' P' @: P/ I: H8 A5 x - / p W0 f1 m2 J9 D
- studioSplineBuilder1->ConstraintManager()->SetContents(
; K% g( F9 w4 Y+ m& T - geometricConstraintData);8 L) Z8 C4 h L& H! y
- ' \; M+ B6 M& T2 x7 Z7 H) r
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 {& v* k1 z% \& o- ^
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
7 b; b- R# ] a6 j
2 S6 T& K* \" g% o+ A- studioSplineBuilder1->Destroy();# u6 o) A: v; M! T( p- f
# _8 P, H; G/ D9 [( G7 t3 R% W- return theSpline;
: ^) @9 H; w( m' s x. a( } - }
, n8 [9 @+ H3 a/ j- E& D" V
; Z2 [7 F) ]; ?$ S" Y- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
6 n- ?8 n) {2 M - {
! K6 K, @+ V; N# Z. M* a% W8 u! } - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
; @/ t: g" ^8 c4 H - if (!thePoints.size()) return;
2 z5 K6 E/ q9 _$ d - ; g' o" ]5 L2 @7 e y
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
2 ?) ^8 p) L/ [- f, j
2 z, x2 M- X9 J1 m% B( S b4 K- if (theSpline)5 |% P2 l# v* j6 G
- {
) c+ l! |1 b8 G1 J! b- N - theSpline->Highlight();
( u# J5 }& h; R6 P - uc1601("Studio Spline Created Thru Points", TRUE);' e) R1 P! d6 z
- theSpline->Unhighlight();
* y! b1 w* p4 { @( r" f - }: t& f. H$ K7 D
- }8 J+ O2 o( y7 Y% v3 e
- <p> </p>
复制代码
. {" V4 q) g3 H i5 B |
|