|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线! D: F( q4 e6 y4 X- W2 X: z
- #include <uf_defs.h>
4 {! z7 H7 x# r, S) Q$ o2 y- Q. {: M - #include <uf.h>
7 e# R. O* _1 U% n6 [ - #include <uf_modl.h>
5 k9 r7 j B* a; B& `( u - #include <uf_object_types.h>
* F. I* s+ n, y. z' `: O" Y: Z+ y - #include <uf_ui.h>
. i0 T! s+ n2 e, S4 k( g - #include <uf_modl.h>* u" Z6 H" I* {$ t1 r
- #include <NXOpen/NXException.hxx> K" x* q& w' m/ s
- #include <NXOpen/Session.hxx>
& m+ U7 F. z2 d - #include <NXOpen/Selection.hxx>
1 @8 X, E( `5 @+ A( y' o. Z" t - #include <NXOpen/Builder.hxx>
, H+ e; u- q3 _; R; ~ - #include <NXOpen/Features_Feature.hxx>5 x7 l H; X8 H! ^. O8 X
- #include <NXOpen/Features_FeatureBuilder.hxx>
2 W) E( }$ a. s {1 [& t# ? - #include <NXOpen/Features_FeatureCollection.hxx>
( T5 {7 Y3 V* L& W6 A9 y. q/ ^ - #include <NXOpen/Features_GeometricConstraintData.hxx>
' T/ D$ d; u+ f2 a( t" M. N0 R - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>! k( l1 r+ W# X/ {: ]: \
- #include <NXOpen/Features_StudioSplineBuilder.hxx>! V3 A4 p" F" a8 R0 q7 g+ w
- #include <NXOpen/Part.hxx>7 e% z% X: l P, x+ ^, U
- #include <NXOpen/ParTCollection.hxx>
4 E8 R: {9 t3 a3 k2 h. j - #include <NXOpen/Point.hxx>
4 {- D& S9 |/ b# P4 k1 m - #include <NXOpen/PointCollection.hxx>
/ s, `4 s* ~3 ~ - #include <NXOpen/NXString.hxx>9 R, X/ u$ b7 C$ K) A
- #include <NXOpen/UI.hxx>$ s3 y( x x* q9 {
- #include <NXOpen/Spline.hxx>( P$ ?) u+ X% }" c
- #include <NXOpen/NXObjectManager.hxx>
- f3 L# M1 C; [& X ]% H - 1 n, `, M/ n8 i: ]6 |% ^* A
- using namespace NXOpen;
0 j% Q) e0 t1 F: `" i. Q% L - using namespace std;6 X) ]* d7 b) G' e9 }$ x! t
8 O& u" a" m- o; T0 E2 f8 ^+ |. g- extern "C" DllExport int ufusr_ask_unload()
: F: i" o8 O% H8 T! t# z - {9 H/ O2 s+ g5 n$ O
- return (int)Session::LibraryUnloadOptionImmediately;
3 f" m! X/ C/ o* }6 S - }
* d1 ?. I/ e6 G
( K G3 [1 N9 i- static vector<Point *> selectPoints(NXString prompt)
# b- t3 I! K$ m: r* }* S/ Z - {
, o) K! ~! f5 L% n, I7 Q2 M - UI *ui = UI::GetUI();3 A1 i7 |( p& j
- Selection *sm = ui->SelectionManager();
. ^1 ^) I! n- ~: S. q0 f* M, w - std::vector<Selection::MaskTriple> mask(1);
6 c! u `" {% h0 ?$ t! ` - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
- Z6 G9 w' M( B/ S2 w7 S( A$ R) t - std::vector<NXObject *> objects;
; x7 X; r8 x' {1 h* G0 n' L( |
8 W! ~8 v3 D+ ]8 K, ~, o; K+ t- sm->SelectObjects("Select Points", prompt,+ { a3 M* n4 a" V
- Selection::SelectionScopeAnyInAssembly,- |; O3 \7 h! F7 _
- Selection::SelectionActionClearAndEnableSpecific,0 m) Y& J8 ]/ J9 Q) a( ^
- false, false, mask, objects);
- X2 U; n9 k4 F - 1 E* Y2 B& }' c6 {
- vector<Point *>selPoints(objects.size());
* g* j' C1 x" X7 k& C. _ - for (unsigned int ii = 0; ii < objects.size(); ii++)
7 _ u5 U) [, z6 X7 B - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);6 ^7 O' N" d! `+ _
- * ]4 j! E* ~; b. b1 X$ O4 ?
- return selPoints;
$ G4 Z( [1 V1 m5 T* B) t - }! u! C, A8 ~$ ?( B4 a1 _ e
- ' a1 N% ~5 u" N7 X d) K
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
( Y4 i* Q0 Q; w( i7 `4 m - {
" e1 f! `: T+ c J, Q+ w - Session *theSession = Session::GetSession();6 e4 `& o, x F8 H
- Part *workPart(theSession->Parts()->Work());
7 G: Y+ p! E+ N4 P3 g5 G) O6 e1 ` - + r k4 ~+ e8 G S% T; @
- Session::UndoMarkId markId1;
( v6 ^5 @/ a1 D+ S2 [9 v7 ~, Q3 K/ ?4 ] - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,9 c. s. J( r6 R' L7 N3 C. H" d
- "Studio Spline Thru Points");3 Z- K5 J2 f( A/ z
' c+ a, R' W3 `- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
: ]1 @3 }5 g) T, w5 j$ N9 H - - q3 d2 T# x) S- E( z
- Features::StudioSplineBuilder *studioSplineBuilder1;: L0 V4 |9 L& ]4 G
- studioSplineBuilder1 = workPart->Features()->
% h% f) ~0 K3 J5 F3 r - CreateStudioSplineBuilder(nullFeatures_StudioSpline);' ^$ }/ Z% Q0 j$ k8 y9 x& D5 \
- studioSplineBuilder1->SetAssociative(true);) x+ E2 p. k# z" r# {
- studioSplineBuilder1-># i( L) E0 n z- Z) E6 A
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
+ k4 ~6 B4 Z) S1 y0 }: `* G - studioSplineBuilder1->
& A# A$ u9 K- H X) c; u - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
3 F1 S; U! X6 F `& i - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
6 _6 i% ?" K; D+ R' S5 c - studioSplineBuilder1->SetPeriodic(false);
8 ]% c+ Y L% X0 @ w1 s) b - studioSplineBuilder1->
. ?/ ^; b$ p- z6 g - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
9 i' T( [ R( Y( ?( @& J' u9 { - std::vector<double> knots1(0);
/ \, Q% K- Q5 F& ?6 W - studioSplineBuilder1->SetKnots(knots1);
8 g2 R+ p4 k Q2 `: X - std::vector<double> parameters1(0);
3 r( q' }; ?; M! T; [- R% u3 N/ n1 e c - studioSplineBuilder1->SetParameters(parameters1);
& D# s/ w$ ^, U3 m. [ - Direction *nullDirection(NULL);
9 V$ B" y1 o) j4 J' E. } - Scalar *nullScalar(NULL);
% j2 A0 u/ M- V) _* i1 { - Offset *nullOffset(NULL);
, K: Q9 Q1 V# K
9 S/ _5 I, |( \' {( i0 f# E6 g4 A* h, b- std::vector<Features::GeometricConstraintData *>& q: N# F. Z h1 U: J$ A. `* O# ^
- geometricConstraintData(thePoints.size());+ T( Q: i$ B, k: ^! F
- . [5 S3 [8 Z. ~
- for (unsigned int ii = 0; ii < thePoints.size(); ii++); ]1 x% |( Q$ D$ H7 C* k: }
- {1 z( y! ?6 \9 C2 k
- geometricConstraintData[ii] = studioSplineBuilder1->
. D7 l4 `0 y# J% Y6 F: n+ | - ConstraintManager()->CreateGeometricConstraintData();; b. H) m: R/ V4 Y2 p o% S
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
& `8 e+ f1 o+ `2 Z8 D3 C& f4 F! V - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
4 h) a' d# a: F- g- t' u2 h& m - Features::GeometricConstraintData::ParameterDirectionIso);
3 L8 G% r9 G. u. r* R - geometricConstraintData[ii]->SetAutomaticConstraintType(
4 o; x5 [: a; o9 n; y - Features::GeometricConstraintData::AutoConstraintTypeNone);
/ X0 g g9 U+ L& e- X- N$ s) J - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
# i3 t: o/ q, A8 x0 c - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
/ O0 r& H# Y3 K; o - geometricConstraintData[ii]->SetCurvature(nullOffset);
3 m6 p. D0 u z" Z* W8 H: u3 a - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);- Z& l/ S( H' x' q
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);! ?. U: \0 G% [( G: L6 }' J
- }4 `7 e% _, b7 b3 @% c( \
, Q$ Y' B% P8 ^) ~3 |- studioSplineBuilder1->ConstraintManager()->SetContents(
1 o, `. v' m! @8 S( P# E - geometricConstraintData);
; A$ ?/ e) x. }/ E8 e+ k8 D - 8 @8 w; b8 a5 y. H+ o* m1 i
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. D! I2 D C/ R* d$ ^3 D
- Spline *theSpline = studioSplineBuilder1->Curve();
: X9 B* [" G, P- |7 @/ e+ z( b& T - 1 t. n" H5 P) A. v! ?9 D
- studioSplineBuilder1->Destroy();1 k5 [. J) e& u3 \
- 9 B4 A \; h X( V' I; U3 J, f
- return theSpline;
q! ~! }# \$ d4 k! P - }' t. M8 {9 K# w' i' @6 I( a5 F7 \1 e
& M% K$ e! e. b" \" o% T* u- _4 C# u- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
! p/ j& H8 ^& f9 k0 T: |; ~; H0 S" C - {
0 |. i ~* z/ k* R6 K - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
$ X, |2 |$ c( Z* } - if (!thePoints.size()) return;
3 x7 N: k- [2 ?/ ] - - A3 y3 y' P9 B. V$ n
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
# ?& s# q) Y/ |6 E
$ w) K; |# |1 q- if (theSpline)
. {1 i ^( U! `6 _* k3 k- z! K Y$ @ - {; h/ L3 e" B! k" I
- theSpline->Highlight();% M. \4 Z) `. F
- uc1601("Studio Spline Created Thru Points", TRUE);' U+ F5 f: X/ v% [& ?
- theSpline->Unhighlight();
. G8 r/ \( g9 J J5 c( i# J. A - }( V+ O0 {8 K5 C# b" C9 G
- }0 \4 o! x7 O7 J- F
复制代码 ; S3 Z: R* M! |& K1 u# G# R
7 |5 h; s8 k% m4 u+ `$ v9 t
% X6 w/ N' Q; E( a. C7 P |
|