|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
' y! i( y; Y" [0 @7 M- G) r4 b5 _- #include <uf_defs.h>) r8 Q6 ~; l" Q, S0 a
- #include <uf.h>% k! c1 J$ X6 ]$ A3 ~6 b/ E2 K
- #include <uf_modl.h>8 b5 _2 {) X$ c& }8 j8 M8 _8 I
- #include <uf_object_types.h>3 ?' c" H/ w: N6 a1 N! ~
- #include <uf_ui.h>7 P( `" @* b+ S2 w
- #include <uf_modl.h>. ?( }) F' Q1 [5 W: V5 V6 \* K9 T9 Y4 ?
- #include <NXOpen/NXException.hxx>6 Z; v. A& ~1 F5 T' o+ Y
- #include <NXOpen/Session.hxx>
7 F1 `: L7 v9 d' |5 O: y& M - #include <NXOpen/Selection.hxx>; Y0 |' l. ~* |
- #include <NXOpen/Builder.hxx>9 z% B; X6 p# U. ?& ^: K
- #include <NXOpen/Features_Feature.hxx>9 i# K* G, j7 P, r# U* A' Y4 b5 h7 T
- #include <NXOpen/Features_FeatureBuilder.hxx>/ B8 g3 G! |1 r N" s( s
- #include <NXOpen/Features_FeatureCollection.hxx>
7 R3 T# P" f/ I. P" d - #include <NXOpen/Features_GeometricConstraintData.hxx>
8 e( [ {) @" p3 a q* b: ^ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
' u9 R: d& e- } - #include <NXOpen/Features_StudioSplineBuilder.hxx>
6 k C9 i9 k1 t* x" D" p$ L - #include <NXOpen/Part.hxx>& _. n. a1 V4 b) [6 p; b; b
- #include <NXOpen/ParTCollection.hxx>; t4 J, q+ h J1 Z5 X4 S
- #include <NXOpen/Point.hxx>8 D ~8 u( k; }, h
- #include <NXOpen/PointCollection.hxx>
, s4 N5 o3 ^( H8 B8 M6 h - #include <NXOpen/NXString.hxx>
( ^4 s; a6 _2 _" g A7 L& c - #include <NXOpen/UI.hxx>! x7 `* K, b. \" v
- #include <NXOpen/Spline.hxx>7 y4 b/ [$ C8 I7 K. P) ]
- #include <NXOpen/NXObjectManager.hxx>
; U1 b* ~5 b4 _' E( R. g% {+ a4 N
4 |% m, F: P& ~! a- using namespace NXOpen;3 j6 L3 I7 J( j& L& G
- using namespace std;$ ^9 a2 |0 s, W$ M" p o" a
- + }+ ]- j- x" t- l$ |
- extern "C" DllExport int ufusr_ask_unload()
[6 b% k2 N8 ]" z3 V - {! v# g2 t8 f8 l i3 v
- return (int)Session::LibraryUnloadOptionImmediately;
9 B% A9 A( X: k, W4 D - }
/ _9 D, P, T3 |8 y e5 `+ y - 3 N' l5 t* N6 P0 b/ ~
- static vector<Point *> selectPoints(NXString prompt)
* Z$ a' v/ _! N$ M) B g" z5 g - {6 C0 q. f5 ~/ c9 ^9 A; Y
- UI *ui = UI::GetUI();5 U4 q' `2 [3 O% n- _3 h
- Selection *sm = ui->SelectionManager();& R, K5 F6 w$ X5 {# S
- std::vector<Selection::MaskTriple> mask(1);
+ O' e9 @) R2 |) R4 T& _, J6 n5 t) }6 T - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);. p$ v2 y" ~+ L* B b @( z
- std::vector<NXObject *> objects;6 K& \) b$ n* U
" B8 k; V) ~' O1 R. f- sm->SelectObjects("Select Points", prompt,3 c2 X1 M: W7 }- p# O, M2 U4 U
- Selection::SelectionScopeAnyInAssembly,% K" g2 T# m3 |% h* U" E3 J1 h
- Selection::SelectionActionClearAndEnableSpecific,
6 r, I. ]; x8 S2 ^4 U. K - false, false, mask, objects);9 J3 d0 n/ g8 e5 Y8 g
: `2 I1 k; G2 G: U0 F- vector<Point *>selPoints(objects.size());9 \: f" _* B) b+ Z! l5 f( Y; ]
- for (unsigned int ii = 0; ii < objects.size(); ii++)1 w! |/ Z) ~" P7 b( N- H9 j" w
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# A7 B& M' m+ v5 { T: N0 ]
! `- q+ T% g+ U P) b- return selPoints;
6 n2 W& d& u- i4 I0 K' } - }
/ d% n( s8 P# t/ L6 m - % q/ z( ~) @& A- W: G2 W2 [' E
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 M a# i' \$ B8 I- l
- {
( }8 f4 n4 \; W0 J - Session *theSession = Session::GetSession();0 u3 Z5 O, B3 t, m# c) J! A
- Part *workPart(theSession->Parts()->Work());
; V5 J0 h1 T) S: T: B7 W
& r! j- m% N1 ?) i" q: g1 _1 A& S- Session::UndoMarkId markId1;
8 M: O: p6 h) m# D - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ k5 Y9 b& H( t" J
- "Studio Spline Thru Points");$ U. u! N; h( N1 U- h2 F/ `
! v4 K4 R" k) \# F2 _* \# B- Features::StudioSpline *nullFeatures_StudioSpline(NULL);) k1 K7 c- E$ w, I
9 l; o6 ~; Z, W/ c* A9 \- Features::StudioSplineBuilder *studioSplineBuilder1;
+ `( H( `; f+ \) o' r - studioSplineBuilder1 = workPart->Features()->
7 Q2 s& a# l) z) y - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
1 \# ^2 b6 N" H/ l# M' O* r - studioSplineBuilder1->SetAssociative(true);
. b* v; P6 h# d8 T$ y - studioSplineBuilder1->; P4 ]; s" M' c3 U+ B5 M5 m
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);% D6 ~: d' ^. m; U* n9 t h3 u
- studioSplineBuilder1->
1 o2 i' o6 T# S6 Y4 Z) n. E) [- P - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
' L2 D: G5 Q1 |7 f# X - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
: R( _' a" f3 J1 J - studioSplineBuilder1->SetPeriodic(false);
5 m3 j1 ?6 R+ M. _% E7 ]; F - studioSplineBuilder1->; a, G) J0 L# f- ^- }/ S# n# }- t
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
# T1 g' F: P! @ - std::vector<double> knots1(0);! Q+ x) L+ R" Y: V
- studioSplineBuilder1->SetKnots(knots1);- X! _3 V+ `. X" v; |) S
- std::vector<double> parameters1(0);$ w6 o1 ~, N V/ @8 N7 p
- studioSplineBuilder1->SetParameters(parameters1);
& J+ `/ h( P+ M- i - Direction *nullDirection(NULL);! g3 R; F4 G F# q/ U+ r" l
- Scalar *nullScalar(NULL);4 |; |- B t0 C7 Y
- Offset *nullOffset(NULL);8 \3 ]3 Q8 R7 x0 A
4 }1 x6 {% l% i1 e: F! K- std::vector<Features::GeometricConstraintData *>
" _/ A: I2 l8 c0 q2 _% N0 A7 U - geometricConstraintData(thePoints.size());3 q7 ?: V* p' ? r6 H1 i+ f$ j
- d) [5 i" F* z0 d$ U$ h
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)' L, T; g% d. z8 Y u
- {2 p/ K* H- A% z( D: C& V/ @3 w
- geometricConstraintData[ii] = studioSplineBuilder1->
D7 L8 z g1 y% y- n7 b( q - ConstraintManager()->CreateGeometricConstraintData();
9 g; y3 N( w1 J2 p5 [9 |, i0 L - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
* o* Y2 F$ i' S/ c( t: `4 E - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
7 f" c* v1 n( O- z) q7 a - Features::GeometricConstraintData::ParameterDirectionIso);7 h# P& y0 x( T! i
- geometricConstraintData[ii]->SetAutomaticConstraintType(. R) V& Q4 S7 x5 t0 [ @8 ]( @
- Features::GeometricConstraintData::AutoConstraintTypeNone);
. w* u! X$ \+ M+ O3 @; M - geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ x; ^0 N& f: _( H: g e
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
! A+ G$ G8 `+ Q: T1 x+ f - geometricConstraintData[ii]->SetCurvature(nullOffset);7 v0 o7 u3 ^8 N. k- m, H% u
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
2 U6 k8 m* L/ D, E6 d( S - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);& W5 c; [! O# M/ A
- }
2 Y; p- ~5 A7 K; R% |# ^* ]
6 H5 z D. m& \& ]( ^8 d- studioSplineBuilder1->ConstraintManager()->SetContents(1 f( u; {: |" a& }2 ]
- geometricConstraintData);6 S5 |2 C+ I! h, X
) n: w; X; O' ?( k, ~) [& C/ v# E- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
1 M& {- j; q2 K# t" n3 m. D# E) { - Spline *theSpline = studioSplineBuilder1->Curve();
) ^) ]; T% r) L# ?
+ l1 B4 p9 |9 Q6 X' T k1 D/ u- studioSplineBuilder1->Destroy();
; d& g! h# { E3 S/ N
: k$ L5 T' K3 F$ }/ `) c f- return theSpline;
5 N/ ~ `3 J( X. o( M+ p' y - }
$ Z A, G5 Z: k- ^; X& `# | - & y+ H) q% E8 S5 L. \
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
: s3 `* n' z( B ~' C - {
# p3 Q H3 K" s$ v6 Y: ]8 i - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
5 I0 M4 d! z) f! t" Q1 a: T/ p - if (!thePoints.size()) return; f' l& ^4 b* {1 f2 w/ }- e
- G" x2 z s4 p- Spline *theSpline = createStudioSplineThruPoints(thePoints);) j' l7 ? A; C$ B4 W9 M) ~
0 S, D/ x4 b7 f- if (theSpline)
, i7 b9 Q0 B8 x& g - {, p4 T, h3 s" C$ U& l
- theSpline->Highlight(); m( u) e% a' i) y$ H
- uc1601("Studio Spline Created Thru Points", TRUE);
2 O4 z3 t( g" B - theSpline->Unhighlight();
7 x4 c8 j8 M1 G! h# N/ d - }
+ y! h' H7 B6 a3 Y - }6 x. @- A S7 c" |# ?, i
复制代码 ) w! k6 g) v' w* A# e% Y* z
! ^1 v& G. v1 |* J! n
/ H. Q [0 b. \! G C! }1 S/ [' l; ~ |
|