|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线- e8 m) T6 J/ N5 G0 a+ [: U
- #include <uf_defs.h>7 @! ]& | B9 N7 o! v E
- #include <uf.h>
8 c, b1 B I* e - #include <uf_modl.h>
7 N# T9 q% N2 D# e0 o1 ]( M - #include <uf_object_types.h>; H/ J/ @' |+ H; w6 T
- #include <uf_ui.h>: ^/ D r+ _8 S+ ^
- #include <uf_modl.h>
) u+ d- _0 N$ R' u& I/ O - #include <NXOpen/NXException.hxx>4 z# o) s4 `4 ] } f' v
- #include <NXOpen/Session.hxx>4 M( q5 r2 R6 \( |4 E1 m K0 t+ N
- #include <NXOpen/Selection.hxx> H3 B) `- X- S: F
- #include <NXOpen/Builder.hxx>$ G" L' L7 R r# v
- #include <NXOpen/Features_Feature.hxx>
8 l& s3 r/ |+ I2 G& Z+ n8 W* j - #include <NXOpen/Features_FeatureBuilder.hxx>
2 S' X: B! f$ @5 D+ S( } - #include <NXOpen/Features_FeatureCollection.hxx>+ F* ^1 C r8 a7 T6 \
- #include <NXOpen/Features_GeometricConstraintData.hxx>
! C* I: S& Z4 k9 ]9 N9 \: d$ X - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
5 X, g8 P+ _# R1 u - #include <NXOpen/Features_StudioSplineBuilder.hxx>
% t/ T' f7 S/ ?, W/ `6 l0 g - #include <NXOpen/Part.hxx>
8 m: t: S6 z9 U* y5 o* Z+ Q4 n6 K! B6 w - #include <NXOpen/ParTCollection.hxx>2 [% D* U( C# N
- #include <NXOpen/Point.hxx>$ g- y) A7 o1 [, q+ \, J
- #include <NXOpen/PointCollection.hxx>
$ j( }$ B0 X# @" l( j4 n" h - #include <NXOpen/NXString.hxx>
3 f- k* N- s' [/ H5 p, V" X- ?8 _$ f3 } - #include <NXOpen/UI.hxx>
4 [: i U% M; x$ [$ [& | - #include <NXOpen/Spline.hxx>
/ g& ~1 x( L: b/ y! L/ ~$ r - #include <NXOpen/NXObjectManager.hxx>$ O/ q" i. g# p7 N+ o7 }1 T1 s
- / C! y# J, G; w2 p. |5 G7 `/ f
- using namespace NXOpen;+ F9 B3 d X* O) _( c8 _. ^) P) [
- using namespace std;
* k* `7 X l7 I; f5 P
) _$ J& u* N- r/ `- Z& [! l% |- extern "C" DllExport int ufusr_ask_unload()$ v2 }- H/ p2 [2 }
- {
/ N6 ] I' ]. A3 k - return (int)Session::LibraryUnloadOptionImmediately;/ i' D5 y) J9 Z! z
- }+ t8 M9 O3 N. `/ r
5 m& u1 o% E; t5 H$ F+ R- static vector<Point *> selectPoints(NXString prompt)3 |% {! |4 }2 e
- {
: `% K Q! @" z/ }+ { - UI *ui = UI::GetUI();
9 N9 H. [3 z6 F( f* p4 p% E - Selection *sm = ui->SelectionManager();6 A, X$ j [! X, `2 P7 I
- std::vector<Selection::MaskTriple> mask(1);
+ x4 a8 a. B! u7 x' e K; j/ Q- B - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% [8 ~' N, h) `; y
- std::vector<NXObject *> objects;
& D" W7 p! j0 I1 H5 m/ @' _ - $ r$ }% u Y! Z2 l. D1 N0 H
- sm->SelectObjects("Select Points", prompt,
8 k0 c0 M. f0 I' r$ r - Selection::SelectionScopeAnyInAssembly,# a& D0 Z1 e/ }% n$ n. C: L
- Selection::SelectionActionClearAndEnableSpecific,
* E& M0 @% ]' _9 b - false, false, mask, objects);1 K4 c. u& f I2 z
- ! Y" W8 A2 W; |' p+ i, O3 h
- vector<Point *>selPoints(objects.size());, h7 Q7 h6 B5 [9 n' L; N m( d
- for (unsigned int ii = 0; ii < objects.size(); ii++)
8 y8 W" Z/ C2 J9 {! f; g/ U9 w) D - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
' ^/ i. M( k" W
5 n5 {: Q# H; G1 |5 c# M) m0 r& |/ A- return selPoints;
+ k" u. C- X7 `+ i - }
! c/ ?, B- ~( ?! }. r. I X# a2 B1 X - 9 n Q# w1 Z; a
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 D8 o& N% z4 h' \% @% P
- {
4 ^' i) H% o T8 @4 o - Session *theSession = Session::GetSession();, U$ r0 ]1 j1 h. A- {
- Part *workPart(theSession->Parts()->Work());! r' {6 u% u. c% y+ f. V8 F$ R
: j8 z0 n( w) f+ i0 U- E* Y! Q8 _- Session::UndoMarkId markId1;- y( P3 U0 n" F, ~& n9 t2 w) t( L
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,5 |+ c; \* G8 z. ^ {
- "Studio Spline Thru Points");
4 |+ T9 m: Q4 p8 }: q' m
& |: k6 e# M) {3 G0 d4 }- Features::StudioSpline *nullFeatures_StudioSpline(NULL);: c r/ I% f0 G. S1 Y
- / a% ]7 G; L- O4 \' l n. N
- Features::StudioSplineBuilder *studioSplineBuilder1;
2 I: L1 s$ _6 i# l. T5 I - studioSplineBuilder1 = workPart->Features()->
& r- v; ^( c. h) }) V J4 m - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
$ R" J1 f, H) [- L - studioSplineBuilder1->SetAssociative(true);% b5 ~# Q9 A. m" R7 @0 _* M
- studioSplineBuilder1->/ \1 Q2 v; f0 G0 \5 K
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
: q, F& L; u" K. O- {& S9 S: o - studioSplineBuilder1->9 y& D, ]5 H3 W; ?) @6 R; ~
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);$ b! V7 v" I; z% @
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
- m v) Y9 F3 |* V - studioSplineBuilder1->SetPeriodic(false);0 U& r6 F/ a+ i0 @* D! _; {
- studioSplineBuilder1-> n) a" l( I* E
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ |9 p. N9 ~% n. o& i, c6 L
- std::vector<double> knots1(0);
- x& G% M# I2 n4 X4 }2 ]& K - studioSplineBuilder1->SetKnots(knots1);
' v8 U- r9 b- n1 Z3 l* e - std::vector<double> parameters1(0);: {/ @6 m2 G) Q1 [ m1 Y
- studioSplineBuilder1->SetParameters(parameters1);! G8 R+ M/ I& \! K7 z. ^' Z1 b/ Q
- Direction *nullDirection(NULL);
; r" E' W4 d" x- i - Scalar *nullScalar(NULL); h9 ^& X1 _8 ~5 I3 |: W1 D
- Offset *nullOffset(NULL);
! \% Z Z" b* V/ d
# z" p% b8 e* ~, k# D+ I- std::vector<Features::GeometricConstraintData *>
- K6 `; F% n$ v7 C' u M - geometricConstraintData(thePoints.size()); |; \8 t* r7 p# ^
4 f2 n$ N; {& ]' ?! [$ E& s, o9 ]- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
, U% U" l# O" X! V# _ - {
/ X I; R+ a, N8 l - geometricConstraintData[ii] = studioSplineBuilder1->$ b* m# V4 f1 K8 |! f9 z+ \8 L3 [( L
- ConstraintManager()->CreateGeometricConstraintData();# J% U* ?0 f, Z. n7 {5 U
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);% t8 K% S9 }4 k" e/ `0 G
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
- B1 Q! _: s. I- [ - Features::GeometricConstraintData::ParameterDirectionIso);/ c2 T6 h+ u' W; F/ `* \% E7 l; U0 L
- geometricConstraintData[ii]->SetAutomaticConstraintType(: w& i2 d8 G6 q9 j! N
- Features::GeometricConstraintData::AutoConstraintTypeNone);: d6 f+ v$ s4 Z2 J% j
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
) U4 [4 p' O+ H# f0 w! d. M - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
1 N9 G3 _' [) c9 C2 a+ }2 X$ Y - geometricConstraintData[ii]->SetCurvature(nullOffset);9 C2 b, l! t5 D. X' S4 r3 B, y
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
$ p& b5 ~( W1 U; {. x& m - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false); q# I" @% O1 J7 y
- }8 {" _1 Z5 j( t- p
1 l) a) x& M( K% L- studioSplineBuilder1->ConstraintManager()->SetContents(
& m/ w, l! c" O9 k' s$ K% b - geometricConstraintData);0 r: [2 H% ^. [9 a3 C h+ I, n# q
' K9 ?% s- ]8 Z; T1 R9 _- ]- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
. y3 m3 _6 Q: Y- B - Spline *theSpline = studioSplineBuilder1->Curve();- I) b- F2 v7 m/ e. R m' p: z
6 }' f6 J0 o# H- studioSplineBuilder1->Destroy();! B2 ]2 @; z8 u; p# |; I8 m
/ |9 f/ R( T/ _- return theSpline;
! B' l" p2 q9 M8 T7 t$ R - }
4 _; z6 S5 S0 c7 l. V* W# H - 1 U" z) r3 z. o& n$ T7 {% _, j
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
4 u) T' \2 X4 C; r) b6 j5 X - {' Y. T5 g/ y( L9 t* T
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");7 d4 c( E4 y+ }( ~5 R, X7 ~, ~& u) t) X
- if (!thePoints.size()) return;" ]- d! Z' o, g
* ?1 J" K2 O( B* R7 _ d6 C+ B- Spline *theSpline = createStudioSplineThruPoints(thePoints);
" V l1 G* y! @% @+ l) [0 z- w
. N4 S: Y) w. ?* S5 Q5 ?: m- if (theSpline) G& M* M. D; o6 e
- {
2 z) G5 q1 R7 } - theSpline->Highlight();
) s: u9 T2 ?/ K b( i( p - uc1601("Studio Spline Created Thru Points", TRUE);2 X# w' G; S9 r1 T0 \
- theSpline->Unhighlight();6 z" y T3 D: R8 Z
- }/ I7 |1 `8 _7 B) U& T, d
- }
1 H6 ?0 x0 T0 X. B4 I4 z# n2 N! {
复制代码 s0 L% {7 N u* W: y
, Y$ @4 T2 P* T0 a" V v& `, Y2 s9 U6 h
|
|