|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线2 Z, }7 h, T; T: ^0 z
- #include <uf_defs.h>1 A& m2 _; X+ O' c4 H
- #include <uf.h>
; m: ~% G! g6 R3 W0 m2 M/ u( h% A - #include <uf_modl.h>8 v$ E- P- Y& ?4 R- W4 ]
- #include <uf_object_types.h>
2 b" Z5 p3 f+ i, V9 P6 v$ } - #include <uf_ui.h>
( \; g d( o+ A% e - #include <uf_modl.h># S! T( w. J5 g% s7 H3 L
- #include <NXOpen/NXException.hxx>
% T' z( i1 `3 [7 A' ]. m3 O) v2 z - #include <NXOpen/Session.hxx>2 v0 r9 g; u3 I' n$ W5 n6 `! K2 t
- #include <NXOpen/Selection.hxx>! f6 h3 j4 }" Y2 r% s
- #include <NXOpen/Builder.hxx>2 r" ~( R$ ~& x$ L
- #include <NXOpen/Features_Feature.hxx>
4 N: X1 H! C3 e - #include <NXOpen/Features_FeatureBuilder.hxx>4 e7 x2 I# h8 B. M: z( [: L: | M
- #include <NXOpen/Features_FeatureCollection.hxx>
% N; H9 c3 \9 v& B5 m& i7 l - #include <NXOpen/Features_GeometricConstraintData.hxx>( s$ ?8 U; H: y& b
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
% t' |8 h9 R+ z# ?0 m- h/ B - #include <NXOpen/Features_StudioSplineBuilder.hxx>
$ k$ b, @. B6 N& K9 ^ - #include <NXOpen/Part.hxx>
; s/ P1 j9 b d- ? - #include <NXOpen/ParTCollection.hxx>0 X& D" s: _+ Y) E! n+ }; h
- #include <NXOpen/Point.hxx>
1 w1 k4 E* m; d7 p, F - #include <NXOpen/PointCollection.hxx>( I' }0 k( w/ y( N ~% V2 E Y
- #include <NXOpen/NXString.hxx>
n8 ]7 n, b4 F* ~" V+ G - #include <NXOpen/UI.hxx>
2 F0 G3 P3 z4 D6 b. L5 n, L - #include <NXOpen/Spline.hxx>3 A6 d G9 o6 Y
- #include <NXOpen/NXObjectManager.hxx>
9 Z- D% O7 j. I3 b0 r - ; J% U4 K5 `6 Z8 h% l4 R5 }6 a
- using namespace NXOpen;3 W. R# W6 Y" B( l
- using namespace std; T) Z- @7 v7 v. q* k
- 9 f& q$ l3 O9 |. {$ J
- extern "C" DllExport int ufusr_ask_unload()
" \8 r1 [! l- _- V1 N - {
/ i; p7 J7 E7 |3 n" [4 P8 ?& l - return (int)Session::LibraryUnloadOptionImmediately;! I4 q; }& w2 C: u P
- }
+ j9 I9 \, J8 W& y8 r* X& i" o
, S+ Y' p4 m# B! n9 f- static vector<Point *> selectPoints(NXString prompt)" A" W0 j+ U& W
- {; X8 u: U. B+ ~) ]* z; M: s
- UI *ui = UI::GetUI();. C, I: r `, _2 Q- ^3 M7 m, y) M
- Selection *sm = ui->SelectionManager();6 }2 [% z% V, D; K# o, h
- std::vector<Selection::MaskTriple> mask(1);
- ]. G+ ]5 `9 c/ }/ k - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
; g+ t: j/ H2 v2 `3 E9 K - std::vector<NXObject *> objects;
' _6 u; \6 q( p8 S: p
) U% V! ?' c% d' P- sm->SelectObjects("Select Points", prompt,8 X0 x# q! r- F3 U# c' j/ X4 b2 u) a
- Selection::SelectionScopeAnyInAssembly, v' ^) {1 b2 X' H$ _. m
- Selection::SelectionActionClearAndEnableSpecific,) r! P @% r; o. k, U* c! q
- false, false, mask, objects); o/ p+ z6 X% V' j' U3 s
$ O d$ l+ ^; b" K J/ H2 |- vector<Point *>selPoints(objects.size());: d# m) D2 O- y$ i1 ]8 J
- for (unsigned int ii = 0; ii < objects.size(); ii++)
6 ?: ^8 U4 }2 z$ u5 _ - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
6 Q" I( y' }5 I: N' N8 t - + i& U- u7 j& M7 [* s
- return selPoints;
6 `* x/ ?; w+ w - }/ E* G) i* K @3 T+ L! C2 m% y
0 I6 @# Q/ C( `+ J P5 ^- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)) y2 {: H: J: M- D) m* }
- {3 w, E( n$ t6 `/ q0 y' p( I4 M
- Session *theSession = Session::GetSession();. ~1 U2 {) I8 g9 ^/ Z! K' M; R
- Part *workPart(theSession->Parts()->Work());& J" c* }3 P" K
) x. |( O: e+ u& H. q* D' d- Session::UndoMarkId markId1;& t' y( N4 m' ?1 n7 a- N7 }: r7 x
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,5 u1 @+ q7 H$ r; c4 }) W# S4 q: n5 o6 v
- "Studio Spline Thru Points");
) _' Z& M9 D' u* `6 \9 y3 ^) a
6 J( `# Z8 `. N8 V$ r/ _# ]- Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 u: w1 j/ V O
4 X" u! E1 t4 E7 P' {7 O- Features::StudioSplineBuilder *studioSplineBuilder1;& ^- g0 A D, J+ }+ n; m, {5 e
- studioSplineBuilder1 = workPart->Features()->
% c/ D% U# z+ ^1 m! I - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
* C3 A1 z/ s. m. [0 i6 ?/ p! P - studioSplineBuilder1->SetAssociative(true);
) S* H9 q, a! D. \ - studioSplineBuilder1->2 \. r2 Y' r) Z, D0 m O
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);# h* _1 Q( S5 E( W5 A
- studioSplineBuilder1->( b% Y* N& n8 b% l1 l
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
3 P5 \% U. j7 F/ \4 K) z7 G4 \$ @/ | - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);. L4 b }' Q* p1 ^
- studioSplineBuilder1->SetPeriodic(false);
+ s/ L& `% R0 L - studioSplineBuilder1->
7 ^5 b* K) E( e- E0 n" d- S6 ^1 ~* | - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
+ U& k3 B2 Q1 E, F' c! ?1 a - std::vector<double> knots1(0);; ?: [2 g7 ^; y4 q9 q5 V! p' O
- studioSplineBuilder1->SetKnots(knots1);
! V2 N, F' G, |) P% r8 i$ o' t- x, |& ` - std::vector<double> parameters1(0);
2 l7 o4 s+ ^- p; U* `5 V - studioSplineBuilder1->SetParameters(parameters1);8 q; K, q2 _. Z6 }1 [$ j$ U+ B
- Direction *nullDirection(NULL);
( ?: o+ X8 _0 S( x - Scalar *nullScalar(NULL);
6 o6 F: N9 ]( s+ L - Offset *nullOffset(NULL);+ `4 \3 _+ s* M. g
* d% E! o7 O- R- std::vector<Features::GeometricConstraintData *>
. u6 @: |. R+ o1 b - geometricConstraintData(thePoints.size());
$ Q4 N) h) {, F3 z
3 S5 L3 R4 j4 d) q2 F2 K) B; _- for (unsigned int ii = 0; ii < thePoints.size(); ii++)1 ] Q: o/ X/ s$ V
- {! h) O5 ? x u, k7 p" [. o, E' b
- geometricConstraintData[ii] = studioSplineBuilder1->
9 D) _0 v: ]* t6 ] - ConstraintManager()->CreateGeometricConstraintData();" ~& [$ [ e1 |9 |" C, T; H, y; t
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 K4 N _, T1 m: V
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(* D' x' P% n" @6 v0 }3 a; v
- Features::GeometricConstraintData::ParameterDirectionIso);; q% Q# n& p1 O+ R
- geometricConstraintData[ii]->SetAutomaticConstraintType(
. m1 l- R/ u* |7 D6 [; f" i - Features::GeometricConstraintData::AutoConstraintTypeNone);
4 @- T k9 M5 ~' L u: E, R - geometricConstraintData[ii]->SetTangentDirection(nullDirection);9 L) w$ R6 c5 n2 x3 E0 R
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
( V' v; }- G( ?4 P; m- y - geometricConstraintData[ii]->SetCurvature(nullOffset); v- q; z; V! a* p5 t
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);* p* B1 ^5 B ]* b& @( ^! v2 @
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
9 Y- m g1 F' I* G& `* B# A$ w# X - }2 _1 ^/ n8 a' G0 a: r$ D
- # T3 V* K& _$ Z
- studioSplineBuilder1->ConstraintManager()->SetContents(( r) R$ k; V% E
- geometricConstraintData);
4 w( R2 }, Z; ]; N9 y. ^; M. O& ~ - % U$ |9 l% j4 P5 \
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();) T% |# e; T) n; M
- Spline *theSpline = studioSplineBuilder1->Curve();1 |& v' }# Q! U' p( E
- 5 h+ s u1 R3 i8 H8 q3 s
- studioSplineBuilder1->Destroy();
& p1 B& y" k/ ?* @9 k0 @
8 v6 I4 T& G+ s K! C- return theSpline;; t* l, ]1 \0 w* T% V. q
- }, }" V+ K2 P- o: N8 f
. O4 F1 Q+ e8 |, M- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)1 @8 ?+ j$ L3 a4 A6 `2 i
- {
0 ^! n! Q8 a0 g - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
- T6 O, [+ V* ~- K+ W8 \& @ - if (!thePoints.size()) return;# d4 f/ B5 {1 ^( T4 v' I; r- P
V1 {. M3 T/ Q4 j4 Q k- Spline *theSpline = createStudioSplineThruPoints(thePoints);
2 h, G( e p3 K# ?# B
# K, V M7 u: U7 n- if (theSpline)
8 ^; K. S5 w2 n5 v - {
. r3 Y7 u& a* } - theSpline->Highlight();
% |/ C" D% ^$ Q7 r, p# T# e7 S4 N5 s - uc1601("Studio Spline Created Thru Points", TRUE);# T5 s1 B4 E6 i6 I( A" W
- theSpline->Unhighlight();5 Z: n) x2 n0 k% s3 z
- }4 j7 X8 c q$ ], ?5 x U1 m/ Y
- }
0 e' x: V; V' C& E5 Y, r
复制代码 ( o6 F- I. b# V( W& \: p# e
- R% O- P# o. M1 [' b' J5 k8 v: v2 \; ?! p5 M' m
|
|