|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
0 ]/ N* B, `* n' B. y' x2 l
NX二次开发源码:通过选择点创建样条曲线
8 M- Q7 s; z5 e: T) z& U. ~, T$ D: s' @& p8 X W
9 P* i! m) D% i5 \' T' k- 9 t1 {, r; { H: y+ x) ~
- #include <uf_defs.h>) _* r% Y. r' x+ v
- #include <uf.h>! N. }2 N5 K. V) T
- #include <uf_modl.h>% Z: O% d' r3 J
- #include <uf_object_types.h>
: z6 Q: D2 l& `7 |3 J* q5 U8 Y - #include <uf_ui.h>
8 e3 C0 |9 M# X( l - #include <uf_modl.h>
2 w+ {. E" u( ^( A& [" n h - #include <<em>NXOpen</em>/NXException.hxx>
2 @* p& j7 z) @& F% ~& |8 g9 I - #include <<em>NXOpen</em>/Session.hxx>
+ G: J) y" k& j2 f2 E8 B - #include <<em>NXOpen</em>/Selection.hxx>- U& d' H( {! U( q6 _
- #include <<em>NXOpen</em>/Builder.hxx>
; F x l6 n. m/ {2 b: B - #include <<em>NXOpen</em>/Features_Feature.hxx>
# j9 K7 i+ O# R7 c& |+ ^# @. r - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
! f1 ~* m- N& c3 l: {6 i) K - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
1 k; Y) c8 X" q h$ k$ |$ i7 z - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>8 D% ?1 }% R2 ?7 V
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
- o7 o0 d' p3 E0 V - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
8 P/ M+ w/ B* q& L( P - #include <<em>NXOpen</em>/Part.hxx>, K, C/ S4 t2 y* j& x5 g
- #include <<em>NXOpen</em>/ParTCollection.hxx>
% B9 f6 k: c5 U. {$ ~+ N- S. g; s - #include <<em>NXOpen</em>/Point.hxx>
: n" y( Z/ Q1 t6 a4 [3 A" j - #include <<em>NXOpen</em>/PointCollection.hxx>" C9 q- x/ q( s* @% M' o' e
- #include <<em>NXOpen</em>/NXString.hxx>
2 ?$ W* ]. g9 Q7 }! ^7 m - #include <<em>NXOpen</em>/UI.hxx>4 ]; ]. Q7 F; P
- #include <<em>NXOpen</em>/Spline.hxx>
6 ]7 ^ f5 d& r$ @: k - #include <<em>NXOpen</em>/NXObjectManager.hxx>
& J- j1 K$ _$ Q4 Z% O& h
; y- c4 K4 q0 ?; w9 ?- using namespace <em>NXOpen</em>;
0 H [/ D% ^5 b - using namespace std;0 B/ u6 \5 E1 e- n2 u9 i
- . k1 ]4 s/ t1 N; R+ f7 h8 \
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
/ [$ H9 ]. L" t; }; Y( ~ - {
6 x: ?8 m4 } s - return (int)Session::LibraryUnloadOptionImmediately;
# V- H4 Q, l0 ]5 V0 J& M4 K - }! X- g3 A+ T+ E% t4 O* [
% o9 V4 A& O1 ^6 w3 j- static vector<Point *> selectPoints(NXString prompt), n: g+ C* Z$ Q
- {6 Y# \4 C% _: K% P
- UI *ui = UI::GetUI();+ a1 O9 {" U% T
- Selection *sm = ui->SelectionManager();
, C; t, Y* k( L5 ^ - std::vector<Selection::MaskTriple> mask(1);6 @' Q1 ^0 m1 o% S
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);6 |6 d( S& u/ l
- std::vector<NXObject *> objects;
$ G. N o8 t' G( z# v" B7 B - 8 \4 y& s Z( j: m' b
- sm->SelectObjects("Select Points", prompt,: j# P6 N7 b' h& ^3 S/ u4 U
- Selection::SelectionScopeAnyInAssembly,
' W9 u/ q; h% q2 A( d5 I - Selection::SelectionActionClearAndEnableSpecific,
; y9 Z+ D: l1 K, T - false, false, mask, objects);) j8 F' [$ {, ? @6 p" h
- % d! n$ `! c) y$ `2 \3 B
- vector<Point *>selPoints(objects.size()); _. F2 J4 o O: m) T
- for (unsigned int ii = 0; ii < objects.size(); ii++)
2 y! s; h% p- k$ l4 o/ z* ]3 z - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);( b' J/ T3 Z; t( Z: X
8 E! U1 D( f2 H+ E- return selPoints;' V9 r e A( f
- }2 @* w4 n+ z: d+ I% J$ a
" M3 v7 t$ J% i- @ P- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
$ P; a* }7 ^; d& @ - {8 c5 @/ D) H: N9 S
- Session *theSession = Session::GetSession();
" e( b$ k* y) f8 N - Part *workPart(theSession->Parts()->Work());
+ U( @& {4 R6 w( G) J
2 b) d1 }" O8 I3 N2 z7 M- Session::UndoMarkId markId1;
# B( L9 T( t' ~( X - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,- D6 Q4 G( d+ r9 s. {* x; C
- "Studio Spline Thru Points");
/ t; b6 v& \3 ^) J+ H1 \
; {- h* T0 ]3 L( d; Y- Features::StudioSpline *nullFeatures_StudioSpline(NULL);7 _! Z7 w# \" ]" n! [' R
- $ `6 |& N! ?6 S; s/ q9 I# h
- Features::StudioSplineBuilder *studioSplineBuilder1;- b0 x- K3 D" {2 b3 L. i! c
- studioSplineBuilder1 = workPart->Features()->; y! j+ z$ O6 c' B
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);' a& g, i* D& q M4 W
- studioSplineBuilder1->SetAssociative(true);
5 [2 a" {% q- p2 a4 n; }$ }; K - studioSplineBuilder1->4 W/ }9 E s( e8 {4 j
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
8 x1 ] M0 {. W. ] - studioSplineBuilder1->3 d% O2 U# ^; h0 a; ?& K2 x
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);3 [' J' p7 _6 w3 V0 t( O
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
L/ O; I" V3 R& {6 X, X - studioSplineBuilder1->SetPeriodic(false);6 X3 A; u7 s$ G9 @$ i& ?+ q
- studioSplineBuilder1->
. \% }( R4 T- m - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
5 Y9 _' r! ?3 J. n6 U- T - std::vector<double> knots1(0);
8 I' r5 t$ z4 y - studioSplineBuilder1->SetKnots(knots1);% I$ k9 b5 C/ n1 S
- std::vector<double> parameters1(0);2 p/ e! H2 F: {% V5 K
- studioSplineBuilder1->SetParameters(parameters1);* ?9 {; M9 \% |3 n
- Direction *nullDirection(NULL);% ]) X! j: R, D; O) q# x4 S2 ]
- Scalar *nullScalar(NULL);
( `, Y! u$ D$ c; ~7 [! }# @ - Offset *nullOffset(NULL);% Y) q0 Z9 m. W; ~
- " U0 S1 Q/ i6 N' J7 G- c
- std::vector<Features::GeometricConstraintData *>
& c3 r% o" Z2 ] - geometricConstraintData(thePoints.size());* ~% i: V: j0 G" x
- 8 v% \9 l' c4 Z5 W: L6 \& F
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
: M5 a& C, q V" ?" S5 p2 L - {
7 o9 v8 S; s2 i8 E, N c - geometricConstraintData[ii] = studioSplineBuilder1->+ {* R0 X9 n5 T7 P) T# D
- ConstraintManager()->CreateGeometricConstraintData();
1 [2 p* c1 ]% S+ k% Z* R - geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 j. V# Y8 B2 z1 v- o; ?- q
- geometricConstraintData[ii]->SetAutomaticConstraintDirection() R' |4 H H3 z
- Features::GeometricConstraintData::ParameterDirectionIso);' G6 A6 \' E2 F, S$ d" b d- R
- geometricConstraintData[ii]->SetAutomaticConstraintType(; u" M3 X) A9 K0 p: G
- Features::GeometricConstraintData::AutoConstraintTypeNone);- `5 l1 l& \0 r Y
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
0 S2 S1 A4 k' Q - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
/ ?: D9 o) ?) m, p5 ?8 I - geometricConstraintData[ii]->SetCurvature(nullOffset);1 W- S, u" a; K1 C" ]
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);5 m6 f+ Z. X5 N Q
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" t6 X2 R; F1 m0 |* D
- }: K8 l2 H( N- A0 e
6 h8 F) P$ S; w# M R/ a! L u% ~1 j- studioSplineBuilder1->ConstraintManager()->SetContents(
# A- e, x8 y9 @+ o- N( r1 D$ u. n( X - geometricConstraintData);) P, Z. t: {; i. f
- % B+ C; a# {' l n0 P. T
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
- z7 @8 N+ P& r+ Q- J! ?. ~ - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
4 e p1 i4 v- q, k - * ]- \7 y+ g. }8 g* h
- studioSplineBuilder1->Destroy();1 P+ V% j# Y% B2 L2 w
- 0 O$ V4 J- B" p h. y/ u7 o! S j
- return theSpline;0 x, ~4 i: z \* B. j9 D8 R
- }- S. H* p* |1 x. W
' a# N# s/ N9 U: g1 p) [- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
* ^9 U# F- X3 v8 j# \7 O% }7 A! k - {
4 P! P) w: d; F# m% M - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
4 x" B5 G5 s4 A s+ v% B - if (!thePoints.size()) return;
" ?2 N: P5 h0 U6 K/ N+ n! f' q
. L7 \- O4 I& `6 J5 _+ A- Spline *theSpline = createStudioSplineThruPoints(thePoints);$ M7 ^& Q4 [ o: \' A7 W! R
- & |) U8 y' A% W$ C9 v+ d7 W7 O9 Y* |9 o
- if (theSpline)
" K1 p7 V2 t" \/ r4 v% D - {; w/ b4 [6 S/ A) H2 ^0 C/ A
- theSpline->Highlight();
* m) q7 S# h o! M! R - uc1601("Studio Spline Created Thru Points", TRUE);3 D" n8 G* }( K/ `) P
- theSpline->Unhighlight();
+ \( O( } t6 P/ D2 _$ z - }
! M# S0 u+ ~8 a; l% B - }9 J0 U6 D' R: ~/ g
- <p> </p>
复制代码 1 A* R: K0 u. l5 K1 D4 Q0 S+ j
|
|