|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线3 J5 ~# y3 l8 J# V2 V
- #include <uf_defs.h>- B; Y% F# G3 w6 d; F
- #include <uf.h>6 |, q* J- X4 L7 D
- #include <uf_modl.h>0 |) @( X# u& b! E. q
- #include <uf_object_types.h>( e* a% F% m9 V1 [ ]0 @7 U: R
- #include <uf_ui.h>
/ V8 n; T! d5 F - #include <uf_modl.h>4 `( K* W6 D! i% {
- #include <NXOpen/NXException.hxx>
' {( |4 f$ x% K7 k. F; a9 T - #include <NXOpen/Session.hxx>
' @; \: W8 f: O# l - #include <NXOpen/Selection.hxx>
, n) z0 \# t0 c% |+ s6 R - #include <NXOpen/Builder.hxx>4 z3 X6 _" `- f0 n
- #include <NXOpen/Features_Feature.hxx>+ D/ l2 W0 A7 d3 L1 ?8 J
- #include <NXOpen/Features_FeatureBuilder.hxx>3 S* B8 M* ^ r% s# G' ?% e
- #include <NXOpen/Features_FeatureCollection.hxx>
3 `7 E, f1 R/ b- Y3 H. { - #include <NXOpen/Features_GeometricConstraintData.hxx>
/ V+ i' @4 }7 j% H - #include <NXOpen/Features_GeometricConstraintDataManager.hxx> f+ [; C' G# e6 e
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
3 L. B" l( u1 R4 v% I - #include <NXOpen/Part.hxx>& K! k8 L3 p- ~1 U c* s( \6 R
- #include <NXOpen/ParTCollection.hxx>
3 e! D W. _4 k$ S; P - #include <NXOpen/Point.hxx>
x; H. }6 O3 G$ @5 P, N% |% r - #include <NXOpen/PointCollection.hxx># p' E" d4 _: T$ p8 g
- #include <NXOpen/NXString.hxx>
( A N* O% t. R7 t7 C - #include <NXOpen/UI.hxx>
2 B y8 | M! z4 h4 X& h - #include <NXOpen/Spline.hxx>
) n) X. q2 S& z$ ?3 Z" G - #include <NXOpen/NXObjectManager.hxx>
: E& q2 m+ K9 L0 U$ W1 \4 a; f
# o' k# h3 g' z- using namespace NXOpen;
+ d8 {; q4 |! I% ^' Z/ N - using namespace std;
* J- p4 j8 g) S8 G( f
& p" N) U3 z( M3 j8 k6 A! L- extern "C" DllExport int ufusr_ask_unload()' a6 A7 c ?0 Y# h: P/ A" P% k, m) X( I
- {
5 q6 b1 H8 K$ w% s* c - return (int)Session::LibraryUnloadOptionImmediately;% n" D3 `' H# r: e, L
- }8 S3 V+ E. ]% m8 V/ r+ q- }1 a- A
7 C9 ~) T! y2 {9 w, j3 y- static vector<Point *> selectPoints(NXString prompt)
# H- A- ~0 R& d - {
; f+ {! A3 t1 J( q# Y: ]/ `9 Y - UI *ui = UI::GetUI();; R, s; o( M* O7 B0 @
- Selection *sm = ui->SelectionManager();
" ?5 Y L5 m1 ] - std::vector<Selection::MaskTriple> mask(1);
* e7 W$ A6 Z) K) T& D - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
: }0 G+ i2 e, U, [ - std::vector<NXObject *> objects;& y. j7 b8 i8 e+ h5 O9 d
- ) s% _9 K' E6 ^" \& |( l
- sm->SelectObjects("Select Points", prompt,
9 Q1 V- x/ v0 ?1 N. |/ u - Selection::SelectionScopeAnyInAssembly,5 W/ ^, f F6 @3 y- v: l
- Selection::SelectionActionClearAndEnableSpecific," l! L+ v) I, d' u
- false, false, mask, objects);/ O) v! g' M% \6 M
. b; }! O" n$ ~! b+ j/ f- vector<Point *>selPoints(objects.size());0 |9 D: V) ~( u0 m0 `* i7 d
- for (unsigned int ii = 0; ii < objects.size(); ii++)/ H) [/ C2 w" d8 n0 q
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
2 x' i6 {2 W# q
) o+ S/ @3 U" H- return selPoints;6 a/ Q ?! k( d% H1 ~2 h
- }
5 i: p. a W' c7 g# O' k
7 x, Q) |- C# P! l, A- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)' \( d$ U6 S# Y/ u5 X/ Q1 q' i
- {
3 X+ t7 G8 p2 \9 H - Session *theSession = Session::GetSession();% W C$ y1 |6 K& ]* Q
- Part *workPart(theSession->Parts()->Work());6 F; S0 m* z, p0 \# o
$ x& o0 V! t. c2 d- Session::UndoMarkId markId1;
) ~% n, ?" |) `% R" k& [( g - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,3 e8 M5 F& V7 h9 X2 `
- "Studio Spline Thru Points");
7 Y5 M, u# o% `" g7 q7 _0 W- Q& t
; V1 [* U4 u8 C x- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
& K" R3 c2 Q) O% l0 H- D$ J
2 y: _0 P, x2 n# U. C- Features::StudioSplineBuilder *studioSplineBuilder1; g, i& M& N3 R% E) f. q
- studioSplineBuilder1 = workPart->Features()->
$ z0 P0 \1 o1 F5 J - CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 q& X% o I. D2 S
- studioSplineBuilder1->SetAssociative(true);
- K o8 @8 \& B. P - studioSplineBuilder1->- _, T' `1 t1 X& M
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);" L, |4 Y. |2 g0 J
- studioSplineBuilder1->% Z' h1 e- B S$ _
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# ?& y) k1 C9 {% T. }
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
8 k+ U! X* U2 M& ?- ]3 ] - studioSplineBuilder1->SetPeriodic(false);2 N2 Y3 N/ @9 u: y
- studioSplineBuilder1->; U) q* l- f# t. Q
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
! u1 w/ S# k" S% y* b. {0 R - std::vector<double> knots1(0);4 s* e1 h" z* s/ j/ p" ~1 i/ |
- studioSplineBuilder1->SetKnots(knots1);. Z! D- A& \4 g& f0 n/ y' ^ q
- std::vector<double> parameters1(0);
+ l, S. C) r9 t! B4 j, d - studioSplineBuilder1->SetParameters(parameters1);1 F+ z; x+ ^& S8 P" J+ }' F
- Direction *nullDirection(NULL);5 {: x* r4 y7 g8 K' M7 a
- Scalar *nullScalar(NULL);
7 L* [- }" l! N4 g- L0 L& u - Offset *nullOffset(NULL);& y! ^4 @( M [* E2 E
- 1 p& ~* `0 j' ^( W$ x: Y
- std::vector<Features::GeometricConstraintData *>% E w& V! Y3 P/ ]2 H
- geometricConstraintData(thePoints.size());
- } T" K h, ?1 I
$ `3 a6 S& f5 z! E% |7 l- for (unsigned int ii = 0; ii < thePoints.size(); ii++)# T( @8 x) w/ m4 o% E
- {
9 x" n9 n: J5 C& v& x# H# L6 g - geometricConstraintData[ii] = studioSplineBuilder1->$ J+ y4 O2 |2 }2 p% y8 L$ s
- ConstraintManager()->CreateGeometricConstraintData();5 |7 x$ g7 r7 J( X+ v& g
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
5 t2 ?0 }% Z1 D( o - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
1 @. W$ ?# u& d) d - Features::GeometricConstraintData::ParameterDirectionIso);
$ U, }3 l5 m2 c9 q8 d" s - geometricConstraintData[ii]->SetAutomaticConstraintType(
' Q7 y; m! j+ G; L" b - Features::GeometricConstraintData::AutoConstraintTypeNone);
; {; {7 ^/ f% s" a! L7 | - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
) ?9 j! D; j6 S9 _6 u ]1 d! t8 z/ Q% X& C - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
! g: V ?/ f, E& h1 C* f, A P; ` - geometricConstraintData[ii]->SetCurvature(nullOffset);% S; L$ W4 {( z4 ~5 S0 G
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
6 j c* ^/ R0 j) V$ t5 A4 _ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
8 K p1 W' Y, t - }5 o8 w! q1 x; A. _
& A7 E& X/ Z' y7 E1 g/ z- studioSplineBuilder1->ConstraintManager()->SetContents(' y: K# q" o) p5 }
- geometricConstraintData);: [- c5 A4 L$ p% |! X( c
- 0 [" d3 Y' `, h$ ~. W9 W0 O: r
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. T' C+ _( Z# U* D' H
- Spline *theSpline = studioSplineBuilder1->Curve();
2 ]0 C a. V' s4 s# W - / _: E2 S% _* s. c
- studioSplineBuilder1->Destroy();' ?2 Q6 q2 x8 }3 Y
4 u/ e* l' t6 I' o- return theSpline;4 c8 z2 v {, g' } w6 u h5 \
- }3 `7 i7 [0 y/ t
2 C! V1 C8 }7 M# d/ {; q) g- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)( `! m/ r P( N9 e& N& l
- {
6 M* v' t3 K; n' z6 }( _) t - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");5 P" Z0 N) U) F, W
- if (!thePoints.size()) return;
4 S7 q& u- s' Q# {
$ n1 M% M- T6 _% A/ W& K! ?- Spline *theSpline = createStudioSplineThruPoints(thePoints);! C, D8 x5 {4 Z% a+ h, H
- ) c- \0 y! d. p4 V
- if (theSpline)
& l* \+ w2 c' F3 g0 I3 E% _% @ - {- z6 b- I$ p" v) M# Z$ H. J: ^
- theSpline->Highlight();( X1 o* i. {, H6 M- K
- uc1601("Studio Spline Created Thru Points", TRUE);# Z$ S; @7 ]4 n5 q9 v7 i- L
- theSpline->Unhighlight();2 `# C" k: @( p5 Z# V) c
- }0 A# T& f: h8 q8 u* `
- }+ _6 m" A4 T# x, S1 |
复制代码 4 g; X( F/ K- i+ ^: n$ [
* O4 [9 K7 a6 p4 v$ g6 @
/ ~- C# K3 }$ r9 q/ B" c. }7 y1 H, o
|
|