|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线5 H2 v. E; q+ `7 `
- #include <uf_defs.h>
( F% [$ t p! k5 y* ? - #include <uf.h>1 h. A! m+ u- Z3 j2 A* _. m
- #include <uf_modl.h>4 \/ V! o% l$ r/ v: Z' q- Z% u: i
- #include <uf_object_types.h>
8 V, g6 r7 }* a( J - #include <uf_ui.h>
) P" z- s3 j0 b$ s$ L [ - #include <uf_modl.h> b( _/ H |/ A, I
- #include <NXOpen/NXException.hxx>
* L _% z) w4 ~4 H - #include <NXOpen/Session.hxx>
, S' K% G6 ?8 { - #include <NXOpen/Selection.hxx>
A$ Z3 W/ s- b( f2 I0 Y - #include <NXOpen/Builder.hxx>- o# {# B) L! M- v4 M$ Z
- #include <NXOpen/Features_Feature.hxx>6 \. u; O( a3 i" J0 \( m4 ]' u9 w( ^# N
- #include <NXOpen/Features_FeatureBuilder.hxx>
, r, N+ R c8 p7 Q2 P+ y - #include <NXOpen/Features_FeatureCollection.hxx>
3 A- J: H+ e% [ - #include <NXOpen/Features_GeometricConstraintData.hxx>
( U' t% x2 C8 i# t' [5 [ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
% a3 T' ^( h) H% k) x - #include <NXOpen/Features_StudioSplineBuilder.hxx>) s8 K @/ C# |; I
- #include <NXOpen/Part.hxx>
# \& u; u3 [, _* |& i - #include <NXOpen/ParTCollection.hxx>
: l8 {" I# g1 r; V. O) ^) Y' z6 M - #include <NXOpen/Point.hxx>+ I* O* O1 Z1 o3 O" W; g# `. \) D
- #include <NXOpen/PointCollection.hxx>
' t* W; P3 s* e! F. _( {5 {5 M - #include <NXOpen/NXString.hxx>
- v7 r, B' F4 g5 i$ m( P& ^ - #include <NXOpen/UI.hxx> q" L) R. s- S% Y6 E+ S
- #include <NXOpen/Spline.hxx>
5 Q( O. W/ |, y8 s - #include <NXOpen/NXObjectManager.hxx>
7 R& t* [) ]+ }& w6 n3 ] - - b4 v V( h4 ~, u8 f5 ? A
- using namespace NXOpen;
5 r0 V0 |) X6 z - using namespace std;
$ P0 r6 o3 f& T+ v# w$ q1 o& f
% X+ `% B* B& w7 A; W. Y/ t1 s7 C- extern "C" DllExport int ufusr_ask_unload()1 t, p# m. a) O- e! Q) s* s
- {& k) F: x7 h2 `! R7 r4 n
- return (int)Session::LibraryUnloadOptionImmediately;
/ O) ]- M" J) \7 D/ P - }6 s$ y, R: h: q' ^8 _
- ' O. @$ L* J1 t" V
- static vector<Point *> selectPoints(NXString prompt)
7 [9 I) G! i) l' H7 h - {
, B' K/ M7 `2 `% T - UI *ui = UI::GetUI();
5 \9 e9 C7 V, |- l! u! s - Selection *sm = ui->SelectionManager();+ w* N1 g$ l1 J( u- N* u
- std::vector<Selection::MaskTriple> mask(1);
8 A+ u6 c: \1 ~* J, P - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
D7 |$ r* D& Z - std::vector<NXObject *> objects;
. m4 j9 p& w% B7 W) O3 v5 A$ j9 E: o - 4 A, N% R7 [; M6 v. [# \
- sm->SelectObjects("Select Points", prompt,2 { r/ s( f5 s3 a
- Selection::SelectionScopeAnyInAssembly,
1 q0 A3 D' R+ T9 A- ~3 d - Selection::SelectionActionClearAndEnableSpecific,
4 I# }, j3 M) m/ S2 Y- C2 A( m# u9 O - false, false, mask, objects);% C& ^& Q9 q7 {9 _7 [1 X
- 0 r0 o) B8 K9 Z6 M! A& \
- vector<Point *>selPoints(objects.size());$ L( Z! Q8 X8 y5 a; Y/ v
- for (unsigned int ii = 0; ii < objects.size(); ii++)
/ t) t$ R) }$ s7 ~9 N- g. J! R - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ s- ~+ k, }+ }' Y+ C7 _
9 T" O. f. ~* z) {' C. A% ~: T- return selPoints;
+ U8 o$ R! ~! ^- w: s- \8 Z9 A - }
; c; n' t' x; z
l. w. d2 A' M" u* x; Z( q4 }- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
' u. ~. I+ t* f1 q S8 G1 ~9 E - {
H* F1 W( p! ~4 w1 ]: Z& ~8 _ - Session *theSession = Session::GetSession();" S4 D2 g9 q7 i" k# }2 O' Z$ \
- Part *workPart(theSession->Parts()->Work());8 L8 u3 d" v# {, s, F( e7 I
- $ M1 f$ S; N. e7 b0 U" W( h
- Session::UndoMarkId markId1;$ P) B) D% C) [5 \* w
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
# S, Z& `- _) K/ K - "Studio Spline Thru Points");
$ K- r: A" z' @9 J" z# H- h9 ?! T6 X
2 B4 N, e, H3 K/ m, e5 r- Features::StudioSpline *nullFeatures_StudioSpline(NULL);2 L3 [6 F4 k) c) o# ^
- + P: H7 K: m4 u. Z1 u* e
- Features::StudioSplineBuilder *studioSplineBuilder1;$ C: G1 s$ z* K4 C
- studioSplineBuilder1 = workPart->Features()->
4 [) `! {/ _0 ~, m9 L5 a% | Y: _ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
) W4 d& {6 J) u% A( _' @+ y, N8 V, I - studioSplineBuilder1->SetAssociative(true);# }* |8 j, m0 M
- studioSplineBuilder1->
* B k) n2 k Z& f: G& L2 w+ {/ P - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);, a$ t- M4 N0 N7 X4 Y% v
- studioSplineBuilder1->
0 H4 C- u! a8 h3 G - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
T5 s+ P4 E [$ J- _ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
( y' X* M! {; K* T5 t* l; ? - studioSplineBuilder1->SetPeriodic(false);
q2 i* G% g* ~4 |# @ - studioSplineBuilder1->! f* D3 X c% q2 }. j/ I2 I6 {
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);" v- H- p2 e u) e, M8 j
- std::vector<double> knots1(0);
# L& W% a8 \& m1 u - studioSplineBuilder1->SetKnots(knots1);
$ C/ [) }" o$ h - std::vector<double> parameters1(0);
: n0 W1 w8 M1 F9 t7 | - studioSplineBuilder1->SetParameters(parameters1);
. s* s! [* F- J; G# t& M - Direction *nullDirection(NULL);8 `' _# |- e7 Q
- Scalar *nullScalar(NULL);
# G0 ?% I, h" ~5 m8 A$ P. s4 I - Offset *nullOffset(NULL);
4 h, `9 m7 O* Z+ L$ L( E
3 D! z1 C% t c9 v' R0 J: i4 k, @- std::vector<Features::GeometricConstraintData *>
u# |0 A: w0 C2 d. t a { - geometricConstraintData(thePoints.size());
: e1 d* T1 o% f u. i+ m
1 z+ D+ | I2 }, }7 T) g- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
; l8 W( O" \$ g2 j - {
9 e$ w5 R. y7 K* _) Q - geometricConstraintData[ii] = studioSplineBuilder1->
- u5 m( x/ J2 c( u) v8 i, h( S - ConstraintManager()->CreateGeometricConstraintData();" j7 I" }) \# W. {8 i, K% K
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);! k% t& c* o) Y8 x
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
! j+ E, o$ U9 N4 B4 `$ R - Features::GeometricConstraintData::ParameterDirectionIso);
& @7 w# m2 ]1 y1 G/ U( k0 u' _ - geometricConstraintData[ii]->SetAutomaticConstraintType(
3 }$ i" w; s1 D. I7 P2 P- `! z3 ? - Features::GeometricConstraintData::AutoConstraintTypeNone);
! [8 F4 r A3 m' E, R1 G/ Q, F/ J - geometricConstraintData[ii]->SetTangentDirection(nullDirection);" N" t/ ?- o- \2 ?" k+ D
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
1 L' p/ ?& g5 h - geometricConstraintData[ii]->SetCurvature(nullOffset);
z1 \4 A" {% A$ N! V - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
5 H4 U5 T b% @3 {' j - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
' T" w1 ^$ n/ W2 Z3 t f) b0 l - }
3 a+ }, T$ w7 F9 e/ s
~; E: Q- b3 W) b1 e. _3 [4 S- studioSplineBuilder1->ConstraintManager()->SetContents(
% R# ~8 J; R1 }. u/ ?( B - geometricConstraintData);: o/ l3 i0 i8 Y* J" ?4 K
- : B/ F- k( G# g6 c/ Q0 e& |6 y) R
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
& Z# H+ ?# n" T; E - Spline *theSpline = studioSplineBuilder1->Curve();9 x- O7 q1 [7 S4 ~
" F* M* p$ ^% b- studioSplineBuilder1->Destroy();% g0 {( @% K G0 U; d6 t. ]
( p$ t9 |) X4 _- return theSpline;
8 W4 A9 }2 d% ]+ |4 P - }
7 r1 ?) }0 e- u4 G# K7 j6 R - 3 W5 d8 Q: b. ^% E5 ^; d3 S
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
$ J+ Z) ]' w1 x6 { M - {5 W! p; ]6 @) `
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( k1 K& z0 t: M- z/ }3 f9 g
- if (!thePoints.size()) return;& R" z; K1 _5 a% M
- : b4 p. ~9 Q' Q0 k( g5 H
- Spline *theSpline = createStudioSplineThruPoints(thePoints);1 Q' W- _+ E% o5 U: k
- ; q; ^$ Q1 j: i: ^( W& r! I
- if (theSpline)6 ^5 ^6 z* S* Y2 P# a, o
- {
( C5 O' J& e9 x! x+ p, d# V! T - theSpline->Highlight();* V7 B: A) i. _3 O1 d
- uc1601("Studio Spline Created Thru Points", TRUE);
0 U0 [. r, b" m( V% L+ w6 I - theSpline->Unhighlight();( L) m, O1 ^5 A% Q/ A( U4 `
- }
, g; j/ }7 ^( M; j' ~3 X; x& a, p - }7 @3 y6 d/ ]) k' @+ ~
复制代码
" v1 A% I+ \$ F! V& J* T. r9 E- \' ^
8 ~8 x* O2 u& ~9 {0 |$ I( z$ H6 |( r5 K# y6 Z
|
|