|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
0 _3 g; Z# y7 e2 d" |- #include <uf_defs.h>7 {9 A# B2 {% K. A' l7 X/ B8 b7 K/ k
- #include <uf.h>
. m* p ^" F- J* U8 g - #include <uf_modl.h>
5 f! R) o' i/ m5 W - #include <uf_object_types.h>) I `( G9 u2 J1 O8 T8 j
- #include <uf_ui.h>! o" z2 I+ N1 r, J% E6 {
- #include <uf_modl.h>
( Y# F. H) y' _. u W! v- G - #include <NXOpen/NXException.hxx>
8 v; b( Y4 B" d- V - #include <NXOpen/Session.hxx>
( a; m* c8 n. [1 i; T- B: E - #include <NXOpen/Selection.hxx>
' ]5 `, X9 w& r% |7 M! {5 h: | - #include <NXOpen/Builder.hxx>* _5 z- g% X6 d+ ^( A# M
- #include <NXOpen/Features_Feature.hxx>! n; K3 i6 C G' l5 E4 y. l
- #include <NXOpen/Features_FeatureBuilder.hxx>, }0 Q2 @8 ~# J% R7 r" O- n
- #include <NXOpen/Features_FeatureCollection.hxx>
6 C6 q; ^* K/ T3 \ - #include <NXOpen/Features_GeometricConstraintData.hxx>, |' k9 W* o5 W' u
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
0 j2 F* d7 |- v3 I- x - #include <NXOpen/Features_StudioSplineBuilder.hxx>
5 {1 @* v( U1 x& K/ F - #include <NXOpen/Part.hxx>
" Q. L, f! V! d/ F& Y# z' n# D - #include <NXOpen/ParTCollection.hxx>
8 p5 X6 m; h4 f. V - #include <NXOpen/Point.hxx>5 C& p# ]6 a$ W: s. ^& b1 _: B
- #include <NXOpen/PointCollection.hxx>$ v7 w, N4 A i7 @. y& |
- #include <NXOpen/NXString.hxx>
+ a4 j" T( e" \0 I) T8 u - #include <NXOpen/UI.hxx>
) d |: d& H6 A# {$ H - #include <NXOpen/Spline.hxx>
m6 L1 ]- D* J9 C1 m - #include <NXOpen/NXObjectManager.hxx>
+ d1 \/ o, O' L2 n: t4 B$ w - # c$ x! m5 d+ x6 U( K+ P
- using namespace NXOpen;
% j, q1 J' _' C1 B+ w4 c - using namespace std;9 S, H9 D8 X- q; r1 W5 g
, P8 N2 n( \% f2 N- extern "C" DllExport int ufusr_ask_unload()
/ U: [+ Z7 H" F5 H" F - {
# U# u% h' J# F% _ - return (int)Session::LibraryUnloadOptionImmediately;
9 r( [3 j7 J" M. T& W- o - }0 W, g) F( z; U. c5 B& w9 w; T
- + }% e4 L' i1 d4 x" Z# R3 z3 A# G
- static vector<Point *> selectPoints(NXString prompt)
5 |4 } M V: u- l! Z - {( m e$ Q! S- n
- UI *ui = UI::GetUI();% l' z9 S# c- {$ h2 d0 r2 o9 w
- Selection *sm = ui->SelectionManager();
. K& B9 h* a c - std::vector<Selection::MaskTriple> mask(1);' W5 J$ c9 V5 ]- ^$ F4 k0 B6 ]
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);, a7 c" D2 ]8 @4 L: `9 a+ c
- std::vector<NXObject *> objects;
& u& l! F! v9 _) S
8 A5 Z0 K- j& l* [1 h- sm->SelectObjects("Select Points", prompt,
k. n! ]" s) J: E- C' W0 c( _ - Selection::SelectionScopeAnyInAssembly,4 I, a8 g( H' y# j$ c4 |7 v
- Selection::SelectionActionClearAndEnableSpecific,3 I! a0 A4 ?7 d. z; K1 l7 t) R
- false, false, mask, objects);: [- r$ M' b" D6 z
- 1 g- G) O7 m8 M; `/ a* v% w! i
- vector<Point *>selPoints(objects.size());3 _; H: N- x' C1 t3 X2 c
- for (unsigned int ii = 0; ii < objects.size(); ii++)
~1 G! G$ x6 \2 m2 C+ j - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
% `) | T% p& A% T- }; r! x+ U
9 e) ?/ q! w R, E: v1 b9 `, j9 k- return selPoints;
8 s3 {! J8 Y+ G6 ^: b- X - }
; f$ ?- f0 e/ d. F+ p& P
6 y+ `* m5 i5 i/ M% M6 x S- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
! D* s8 y2 E; [2 \& B - {4 h, Q; c4 U$ _9 H) z; R
- Session *theSession = Session::GetSession();
' q8 G: G: u; n0 s ] - Part *workPart(theSession->Parts()->Work());1 R( H" b/ z* l' i/ u" C4 R9 i' R
1 |% X& O6 u" j, a3 H4 k- M4 E' s- Session::UndoMarkId markId1;
' G( b' ~4 h) E+ |1 ? - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,6 T' _# m1 H: x* W, H6 `# T, W
- "Studio Spline Thru Points"); }; e: m* B: G+ I2 _( z
% b4 ^$ Y ?- ?- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
6 n/ R- z3 h/ I
& @- F/ A; K) Y m7 ~- Y% |; _. n( T- Features::StudioSplineBuilder *studioSplineBuilder1;- I5 R/ U3 e( ^0 f
- studioSplineBuilder1 = workPart->Features()->/ V; U5 ^) i' c
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);( r- ?3 Z& A5 }! g, n6 \! N6 d
- studioSplineBuilder1->SetAssociative(true);) z3 @7 z. D1 u* m% h4 [
- studioSplineBuilder1->. s/ t5 p1 p. {8 S
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 n( \; Q! ^0 s
- studioSplineBuilder1->
" R6 E$ a6 @: x5 g9 n3 m - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);/ X9 G; M: ~: r N. t
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
( h$ K+ o3 X4 D! l# N3 a* T* ? - studioSplineBuilder1->SetPeriodic(false);" k: a; @& r; v! n9 h
- studioSplineBuilder1->/ A2 C0 e! f$ E$ u( |' ?
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);1 E2 A# s' t/ c. t
- std::vector<double> knots1(0);
2 Y7 V' N# z9 L% S) U# f9 F0 E - studioSplineBuilder1->SetKnots(knots1);2 c) h2 p- [! @4 P8 h9 I
- std::vector<double> parameters1(0);! ~! Q5 V$ `9 e2 ^+ Q
- studioSplineBuilder1->SetParameters(parameters1);' Z; o& R4 \* B, S; C
- Direction *nullDirection(NULL);
" i! M- |3 v) U7 ~2 v - Scalar *nullScalar(NULL);0 ~" m& A5 t3 c: J
- Offset *nullOffset(NULL);
8 n* f4 W2 S5 }* C
+ q+ p: p' v" i1 s% [+ A/ W- std::vector<Features::GeometricConstraintData *>9 i# ^, d" P) A' w2 A$ F
- geometricConstraintData(thePoints.size());
- y. N! z& \/ g( `* R3 R F
! p4 \1 [6 w9 v# Q! p$ M+ M- for (unsigned int ii = 0; ii < thePoints.size(); ii++); t" c7 u/ N3 O; c1 D1 [
- {% |5 g1 `9 W0 I) H
- geometricConstraintData[ii] = studioSplineBuilder1->
" C K* x+ ~" Q/ U |# }2 g# g! L5 l - ConstraintManager()->CreateGeometricConstraintData();3 L4 G& B( o/ h
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);8 ^9 y6 R$ g2 x% i" ?# @+ X
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(* | w* E* T4 M& K# ?
- Features::GeometricConstraintData::ParameterDirectionIso);
7 z' P# J$ p# n" D5 l+ S - geometricConstraintData[ii]->SetAutomaticConstraintType(: W5 w0 n0 D* w/ r% b3 H) Y( Y
- Features::GeometricConstraintData::AutoConstraintTypeNone);
4 @; T0 n5 [# ^2 n - geometricConstraintData[ii]->SetTangentDirection(nullDirection);; I+ g1 _6 s9 ^1 F. v
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
, M8 P1 }3 B. j8 b - geometricConstraintData[ii]->SetCurvature(nullOffset);& h S* o1 d" Y1 e! c D3 l1 U
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);/ ~ K4 @ Q" H7 t" p- h' q
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 J) E, T. A) ]1 V, W
- }, \8 E& a4 c/ a E& _8 _' A; _$ C3 p
* r% _2 }( q: o; M- studioSplineBuilder1->ConstraintManager()->SetContents(
" R& {' Y: X* Q" V- A# c- n - geometricConstraintData);) ^$ |7 q. [9 h9 |
8 S7 Z9 M5 ?# k# a: m8 I2 u- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
7 n- \! ~( v$ Z N% G3 a4 { - Spline *theSpline = studioSplineBuilder1->Curve();* N! P" I& p, v, H0 b; p' H1 p
- + k4 i' X/ Z+ ]$ g+ u. v
- studioSplineBuilder1->Destroy();% _7 k4 u! b) l c# q" a2 [* G
8 K( E8 e, i" q; z- return theSpline;! v' a( U k# j* }0 I; d. V
- }' D7 B* v; v) ^3 X/ L7 n
2 h& x- d M' K: v- Y5 q3 n; T& O# W- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)8 e/ E- h7 L2 ?. ~% `( I
- {
" L. Q( ^4 ^! a& G - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");/ L4 G" L7 a* {# o( r. x1 B) D, L
- if (!thePoints.size()) return;1 ?5 @# ?3 U, E
- ( U* F8 {3 {$ t0 e
- Spline *theSpline = createStudioSplineThruPoints(thePoints);* A. A1 O3 K0 N: a& r, p* U
- 6 q, V3 ~; k2 |) b5 n1 x9 E" t P
- if (theSpline)0 g, `0 [9 v0 q$ D5 O
- {
) u$ _7 i& I( F6 Q+ j - theSpline->Highlight();) T% F4 ~+ x U6 b0 W% i/ h' g- L
- uc1601("Studio Spline Created Thru Points", TRUE);/ [# f1 w: n: {1 y
- theSpline->Unhighlight();
9 {8 x' ]# P; _2 t5 Q - }9 z( J0 ]* L# Y1 c
- }9 s" u4 z7 B* C V$ f8 I. `7 Z8 D, j
复制代码
: s# t0 r" y, N: f% d0 x
$ O. \0 g2 m% Z+ i' N+ i" d$ J, X D w( t6 B$ [ v0 n! V
|
|