|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线' B8 m1 r0 K. r! g4 p* g" [" _2 B
- #include <uf_defs.h>
/ x( K4 H) B3 u6 w+ ]$ N+ f+ [6 _( `$ [ - #include <uf.h>' p) ?' `! A0 n- _+ W5 A- ]1 s
- #include <uf_modl.h>
; _7 U1 f0 y2 ^% o; v* ~0 P - #include <uf_object_types.h>
6 Y2 |9 @5 F# D M, \ - #include <uf_ui.h>
/ c( d& U4 n9 e J5 r, ` - #include <uf_modl.h>
1 w7 k2 o' }) a/ K - #include <NXOpen/NXException.hxx>+ e% C* I6 J6 j* M; [' J; Z: K; m; p
- #include <NXOpen/Session.hxx>! W$ t# Z4 u+ J- {
- #include <NXOpen/Selection.hxx>) J6 M5 y+ R. n( m7 Q9 D. J
- #include <NXOpen/Builder.hxx>
3 Q: z2 l) h- K2 D e - #include <NXOpen/Features_Feature.hxx>+ J7 \5 B9 b4 y5 l% W0 n! [7 ]8 Q
- #include <NXOpen/Features_FeatureBuilder.hxx>" w% E5 ^) n; M6 i* t
- #include <NXOpen/Features_FeatureCollection.hxx>
# ^/ m3 S. p( `" R( w% y! `0 I - #include <NXOpen/Features_GeometricConstraintData.hxx>8 W% T! ]# N; C& j/ M
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>" ^$ ^6 F+ ?$ F& B( `
- #include <NXOpen/Features_StudioSplineBuilder.hxx>) b+ _* d2 W0 ~& ?# |
- #include <NXOpen/Part.hxx>
+ u/ \: @# H/ B! }/ ^/ ~ - #include <NXOpen/ParTCollection.hxx>
# U: O& E- w& j5 }2 Q - #include <NXOpen/Point.hxx>/ [ L" K( D6 }: ?( V# F, h( w$ W
- #include <NXOpen/PointCollection.hxx>
9 G" G3 D! V* O1 Q3 s - #include <NXOpen/NXString.hxx>
4 t5 B1 {5 u5 v& ? - #include <NXOpen/UI.hxx>
) h( m2 k* q/ c0 z - #include <NXOpen/Spline.hxx> J( H- j. G6 ]4 o* O; x+ Q
- #include <NXOpen/NXObjectManager.hxx>
/ _7 X) h) [ A5 U! Z' Q" \2 u - + o8 z$ `# l6 U- Y9 F/ |% N Y8 P
- using namespace NXOpen;& M7 {5 f( J# N" R F$ k
- using namespace std;
6 E8 `* v* y. B9 f
) C/ d" b$ ?+ Y- P7 y, W- extern "C" DllExport int ufusr_ask_unload()/ B2 z- ~7 N a8 I* W4 N
- {0 q4 i! N" {- l1 H |5 l
- return (int)Session::LibraryUnloadOptionImmediately;! A9 f3 G3 l/ z d! S6 _# j
- }! C+ D3 r2 O; ~7 }% J' m+ w% Z$ E5 h! H
1 L3 N% X4 @) j; m' R3 y! V! P- static vector<Point *> selectPoints(NXString prompt)8 N: b( [1 P1 w: k1 v b
- {) |5 Q: k1 L" N- W9 K. s2 I
- UI *ui = UI::GetUI();0 B" ], F. h' Q, r1 q' ?5 o. p
- Selection *sm = ui->SelectionManager();7 l0 f- G! P7 M4 ~& C, W- i
- std::vector<Selection::MaskTriple> mask(1);& N6 v# c1 |- W% Q A5 ]8 M! R
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
! F" W9 z8 a$ n5 ~ - std::vector<NXObject *> objects;* J4 W3 F( p! F3 L
- : R6 R( E' X8 z" H6 w5 p p t( z+ l
- sm->SelectObjects("Select Points", prompt,
4 N7 P) @; }: d - Selection::SelectionScopeAnyInAssembly,/ h3 o0 g2 o2 f9 V# }
- Selection::SelectionActionClearAndEnableSpecific,
3 j2 T+ j/ l$ k$ H - false, false, mask, objects);
v# r' {5 K* v6 M; @1 g - z% ?! O" O0 s
- vector<Point *>selPoints(objects.size());8 t) e; [" z9 \& e+ j, M8 O/ X
- for (unsigned int ii = 0; ii < objects.size(); ii++)
8 T) w# ^2 o& N9 H" t% H) R- l* p - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% ?2 F, f. @. t6 K. q) T
( C) j4 U" `" H0 D- return selPoints;0 m" O" D/ V6 U0 L1 k
- }
& @) V! s! t: ]
0 z/ O* T! u T) O+ f& N/ ~- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)1 M3 [% C- F* X7 T) @; ^3 g8 r
- {
4 K; k) X! I- r: _$ C2 S - Session *theSession = Session::GetSession();
]+ A2 w* s5 l. d* m0 ? - Part *workPart(theSession->Parts()->Work());% C3 y B) L& x7 T8 N" j: Q
- " Z* e, i( Y9 N, p" ?
- Session::UndoMarkId markId1;! ^" Z8 d( J& C. j4 O7 B; W
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
, f7 C# ~" H; M+ w# ~7 ^ - "Studio Spline Thru Points");
5 u) K u9 A' S - ! Y3 X! p* G. \+ M' y7 r# b
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);7 E+ y; P4 _1 x6 O! ]# o7 p% H
/ {) U3 a% \5 {0 d7 w: h- Features::StudioSplineBuilder *studioSplineBuilder1;) ^ v) j6 U# h* ~
- studioSplineBuilder1 = workPart->Features()->
/ i5 h+ W& Y$ W* M- g/ ] - CreateStudioSplineBuilder(nullFeatures_StudioSpline);: {$ I; j: a6 |
- studioSplineBuilder1->SetAssociative(true);
* ^; u& A# Z: x* F+ m8 S( x, U6 L - studioSplineBuilder1->
3 o2 V' i b% o, R: q - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 Y% T7 u V% B5 |6 |/ @
- studioSplineBuilder1->
7 y& L, `3 s- l" n/ v5 _ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
4 g0 B8 N7 i" j9 \$ f6 z - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
$ M. z- [' K" u - studioSplineBuilder1->SetPeriodic(false);4 u1 a3 M1 o2 y
- studioSplineBuilder1->+ L9 ]/ G: q; ?4 O+ Y0 u' J
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
3 N7 b) [* B7 ]4 @; l4 d& I* c - std::vector<double> knots1(0);4 {6 L5 b2 u2 ]; S& E9 ~( C
- studioSplineBuilder1->SetKnots(knots1);
* P w; T" r! w& A - std::vector<double> parameters1(0);
( {" K: c7 D& M% f - studioSplineBuilder1->SetParameters(parameters1);# m' m$ v' Z" M( z) v1 k
- Direction *nullDirection(NULL); h8 H2 `; }+ I/ Z- [
- Scalar *nullScalar(NULL);
i# f- L. B5 P4 o- }+ P3 I a - Offset *nullOffset(NULL);$ W, g( M( s& U
- ( n& f: _* E! `
- std::vector<Features::GeometricConstraintData *>
+ G5 q7 E9 j, O: c - geometricConstraintData(thePoints.size());
; b x* |1 o7 J$ M
R2 S4 E$ q2 @/ P2 F- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
6 F, N6 Q) v/ J9 q9 D - {
$ z7 }- S3 m5 S5 o) p7 V5 j9 o - geometricConstraintData[ii] = studioSplineBuilder1->
( h0 k% J8 y# U: e: A6 C - ConstraintManager()->CreateGeometricConstraintData();6 ?$ v6 ^1 x* b$ h1 H }
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);& b* k" T2 w: [; H
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
0 m4 L$ z; G+ v. G2 @& {' c9 r# `0 w - Features::GeometricConstraintData::ParameterDirectionIso);
$ ~' Q/ d: C4 n# ]: m- b. B, D - geometricConstraintData[ii]->SetAutomaticConstraintType( ?7 m3 W4 M. U( H% t/ a
- Features::GeometricConstraintData::AutoConstraintTypeNone);
. w" `/ `/ n) N3 u4 m - geometricConstraintData[ii]->SetTangentDirection(nullDirection);3 C: f* ]' I2 F3 b2 q: z
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);9 f. V! D* t, t
- geometricConstraintData[ii]->SetCurvature(nullOffset);
7 v' a' I5 [5 }$ Z# q5 y - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);; M) v% Y; |, P/ l8 c3 Z1 F5 D
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
* t9 e5 N$ j/ D% o6 C" P - }
7 g6 j" h6 c0 v: g6 s" G$ S - . _5 ^- G: K9 {( P& R# @
- studioSplineBuilder1->ConstraintManager()->SetContents(
* F. f3 L' K. L7 G3 t - geometricConstraintData);
3 R/ x" E0 c; `4 h: x3 @$ b - 1 h+ P) {( m/ Y+ A
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
# z4 ~8 n5 ^( C' t - Spline *theSpline = studioSplineBuilder1->Curve();
1 { t/ N/ f8 o' k - ) r/ N! Y7 {1 d+ H# k8 m
- studioSplineBuilder1->Destroy();$ ]# t& _' i8 Q3 P9 D& C; ~) W) w; `
. {+ c( S2 f7 x! ~- C# p- return theSpline;+ X: e/ {, B, \2 I' ~5 E) G" y2 \
- }
+ c _7 p& h: b$ l# V7 I - * R& M' V1 t% U" U5 G/ \
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)3 Q9 D. o7 U7 R: g1 g1 K
- {- }. X _3 l9 v: f2 b# E. _, l* ^
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
5 k1 x% ]! k* I, r, w: f/ d - if (!thePoints.size()) return;3 u5 f- M3 t! U I% W7 v9 N
& @: k4 Y4 ^/ E) b4 g4 Y- Spline *theSpline = createStudioSplineThruPoints(thePoints);
; j/ B9 @2 y( T- {/ y* s7 R" w* } - 4 _' d4 |+ p" V7 }+ Z6 S& ~
- if (theSpline)# v @) U/ k i" `; ?- @: L
- {
. s7 t, P9 ^- e% S3 O0 [! \( T - theSpline->Highlight();8 C/ L; ]# v- f
- uc1601("Studio Spline Created Thru Points", TRUE);7 {3 \# `+ p" k- h9 b5 }3 h8 x
- theSpline->Unhighlight();* P* t% g9 P; A$ T! ~
- }- x6 b& m/ c# j! v) ]' O5 P$ e
- }' {+ k" n% l. V" ?% {! {
复制代码 1 L2 _" I3 c) w" k2 ~0 o
' K0 U! y0 E5 w
9 Y$ u! S/ R' x5 j$ H4 } |
|