|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
# q. g! c( A+ y; e" j$ d- #include <uf_defs.h>" X. u. I* ~- d5 W. n+ y1 S9 k
- #include <uf.h>1 Q& J5 [4 u- N g8 w
- #include <uf_modl.h>5 [9 l1 u# U5 }+ q
- #include <uf_object_types.h>, x# y/ R9 ^/ J. S: }; q0 V
- #include <uf_ui.h>2 h8 u8 U* u8 Y( h9 q8 S0 W( t
- #include <uf_modl.h>3 U( z& r$ [" C! f& s Y
- #include <NXOpen/NXException.hxx>
4 S! K! L/ }/ Z+ d. S* y - #include <NXOpen/Session.hxx>
9 s; b! H% y$ ~9 k" S& o - #include <NXOpen/Selection.hxx>
' N( }' _9 T* J: }+ Q4 Q) v - #include <NXOpen/Builder.hxx>. |$ I* N7 c7 {* L
- #include <NXOpen/Features_Feature.hxx>( m; n6 C! b+ Y/ j0 t) h+ a& p/ a: x
- #include <NXOpen/Features_FeatureBuilder.hxx>
% m A) J* }2 m i - #include <NXOpen/Features_FeatureCollection.hxx>
+ d: w9 f! V- H9 K5 U( K1 U2 m' f0 I - #include <NXOpen/Features_GeometricConstraintData.hxx>
, i/ q A2 ~: s - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
) t+ i1 Q+ Q) Q; c6 P a3 T" d - #include <NXOpen/Features_StudioSplineBuilder.hxx>0 g; I- A1 Q* l7 ?# Q! e. y" ]* Q
- #include <NXOpen/Part.hxx># c" ~% @. {# y0 X- Z
- #include <NXOpen/ParTCollection.hxx>5 L( t2 O6 M1 T1 B5 d) s! c
- #include <NXOpen/Point.hxx>2 g4 Q0 T+ v) B j& `1 H+ A7 n# n
- #include <NXOpen/PointCollection.hxx>$ n4 b0 W0 H1 P
- #include <NXOpen/NXString.hxx>
5 r/ n$ M9 [) E8 f4 m* W - #include <NXOpen/UI.hxx>, b$ i# J3 l K$ q4 {
- #include <NXOpen/Spline.hxx>5 w( M) C& l" `4 V7 ^
- #include <NXOpen/NXObjectManager.hxx>3 w9 I5 D# K7 n7 f
+ b2 U3 p$ F5 [7 s' u6 h- using namespace NXOpen;
0 K0 S! i# W/ t! `1 E2 t. H! f - using namespace std;5 x: S" B: U9 C t# F0 G
- 3 n5 p/ u- v8 g3 \/ v
- extern "C" DllExport int ufusr_ask_unload()
. R, R+ H0 u* D* }/ S4 z - {
2 m) J( j+ m( z; o5 V8 K - return (int)Session::LibraryUnloadOptionImmediately;
$ Z8 f1 H* [& k: f: T - }
* h% N8 b: k/ p3 Y" ]
- P$ w+ |2 x& r8 G4 Z+ c" {$ a- static vector<Point *> selectPoints(NXString prompt)
6 ^3 n# t+ w- }, R3 j1 q9 t - {6 o- F& [: }' U. T6 l- i0 a
- UI *ui = UI::GetUI();
; B- d/ ~( R9 d5 J& j# v - Selection *sm = ui->SelectionManager();; c$ A' P8 ^0 c
- std::vector<Selection::MaskTriple> mask(1);3 b* C) R2 l$ _: u5 z, q: G$ h1 W
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
3 _7 f" K- | l7 ^( n6 X: Y: N9 p - std::vector<NXObject *> objects;
# A9 Q0 G& T8 }: k% |3 ]4 y
" q9 L, Q; q: N- h6 k- sm->SelectObjects("Select Points", prompt,
/ l" L: t7 h! d/ U" k7 D9 V4 \6 T: W - Selection::SelectionScopeAnyInAssembly,
/ U, L% D) Q0 [7 f* @" S7 v7 y - Selection::SelectionActionClearAndEnableSpecific,
- {' z% l& E/ Q' Y9 i* k/ F - false, false, mask, objects);
4 A/ X h4 ^; R* K! e - : o" }; E+ m* j/ @6 w/ o
- vector<Point *>selPoints(objects.size());- z0 w& [3 l5 B3 i( F* r
- for (unsigned int ii = 0; ii < objects.size(); ii++), t( O6 I5 N3 e! G% h5 B9 c
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);) u6 X' j& F0 T! l4 [- I
+ \( A- {. A: U( M% V7 H' q) X- return selPoints;. t7 w3 q3 C/ j4 k2 J+ u3 c) o0 L
- }0 q' c0 G( l; h$ @9 d$ U1 V
- - @( P) A' q' T0 Z% f) U
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)# Z' k3 W3 H" d8 T! ?0 |
- {2 p' i" T3 @+ i
- Session *theSession = Session::GetSession();
) c3 Z" N: M9 B6 U& m& m - Part *workPart(theSession->Parts()->Work());
. M; ^1 B8 y( ~8 }3 S
5 L# n( Z2 g/ i: r: s& e5 U9 W- b! N- Session::UndoMarkId markId1;- e) t \9 s9 E4 c7 G
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
2 ~' {; P0 X' _ - "Studio Spline Thru Points");
/ h) {+ ^7 F) u# R' B
, s+ k6 E+ f/ S/ C- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
5 x0 X$ a; s/ j+ A) ~; M. \/ z - ; d4 U. x9 s. \7 g7 q
- Features::StudioSplineBuilder *studioSplineBuilder1;
' c2 d! p" a; E. N+ z: } - studioSplineBuilder1 = workPart->Features()->
) C- y! w( r" O5 c" b# s7 B @ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
- B% u4 N0 @0 q( G - studioSplineBuilder1->SetAssociative(true);* m+ V% y( R1 l! n b
- studioSplineBuilder1->$ D( I% P! q# j6 Y' N. l& \2 f o* L
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
$ b% t4 E* _9 q( Q - studioSplineBuilder1->: Q6 {" Q% m# P V4 }$ ~/ @
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
/ c' z6 X8 c$ f1 r1 ~# i K' a- e- l( h - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
$ x6 H( e* y' x - studioSplineBuilder1->SetPeriodic(false);0 |3 \- b4 T. W0 M6 o" F' c
- studioSplineBuilder1->
/ Y# i0 j9 i: F - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
7 C6 D$ K( s6 V+ l - std::vector<double> knots1(0);
# D j7 r! S$ {* I7 r$ ~0 h- ]6 A - studioSplineBuilder1->SetKnots(knots1);
* V+ `7 S' S. ^7 T& ^% J3 ] - std::vector<double> parameters1(0);
7 E9 f7 d# l7 J$ z& z% D - studioSplineBuilder1->SetParameters(parameters1);8 O+ L2 ^- S0 M5 \' J8 s4 d
- Direction *nullDirection(NULL);' e4 s9 ^) w0 f _' {4 z
- Scalar *nullScalar(NULL);& v+ e& H7 W' r% c' f! @) s2 R
- Offset *nullOffset(NULL);
/ R' L2 z, e) e4 s) u
* a+ w( U0 g& x- ?' H- std::vector<Features::GeometricConstraintData *>
* d( a, g! P# l y9 }7 H) @; L - geometricConstraintData(thePoints.size());( m9 W! ~" w3 ?
3 z5 b& h! o5 G+ j9 {0 j- for (unsigned int ii = 0; ii < thePoints.size(); ii++)$ b# p. ?5 Y ]' C8 w; m
- {) I9 v: M: A. P* h9 g: {! [1 q# G
- geometricConstraintData[ii] = studioSplineBuilder1->+ ?2 R2 p v1 h8 e. _
- ConstraintManager()->CreateGeometricConstraintData();
- ^% r3 |: G/ \' V4 M* U - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
: x7 p8 E* h: O) X6 h - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
" O' O7 J% N0 P4 C* } - Features::GeometricConstraintData::ParameterDirectionIso);
' c0 \# D- ?* s& | Q1 f - geometricConstraintData[ii]->SetAutomaticConstraintType(1 |7 a7 x6 v9 x0 r. ~
- Features::GeometricConstraintData::AutoConstraintTypeNone);0 B' H0 D i C$ [
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
, T+ z' N/ h4 L1 Y( [ - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
: T: r3 \4 S q7 i% W+ c& | - geometricConstraintData[ii]->SetCurvature(nullOffset);2 D& T/ P" [8 h1 K$ ?$ B
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
; q E$ k( Y, t) V) ` - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);+ j, N* F% s7 F0 n9 B
- }
9 [1 M/ @$ N0 ~( ?1 b' \ - + ?, q) }4 @5 M. d/ f
- studioSplineBuilder1->ConstraintManager()->SetContents(6 i8 L% ]. w" T1 E5 X- S
- geometricConstraintData);
6 d/ L' i% \+ u8 [" @ - 4 u) ~) d) ?9 i; M9 D* s5 Z& M
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
* i: _* r2 N" [& K# B - Spline *theSpline = studioSplineBuilder1->Curve();
% ?9 O6 P7 O6 R/ N' p5 m1 U$ U) R - - T) u3 B' D+ w+ [+ C4 U
- studioSplineBuilder1->Destroy();
) Z8 s. p$ P& i; C
2 k1 F: Y7 c8 I- return theSpline;( U; Z; [0 O* b3 }2 o1 i# r
- }
3 b* y6 E! O& S. p2 t; m
( k! C$ O+ t) E% Q2 @- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len). y, Q. C) M# O6 S. n
- {: q* @5 v( E. b7 k# B
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" |6 Q4 B& T: i% T% V' R: {" N
- if (!thePoints.size()) return;+ T% w; }$ L9 U2 j6 b
% z2 |6 T; m Y" C5 \& e, B- Spline *theSpline = createStudioSplineThruPoints(thePoints);5 c+ ^4 d$ Z8 k: ?# e
) O, R+ e: k* W! ^" b- if (theSpline)( C' X( J; A6 R
- {
0 }# P. U' q- z/ R9 \+ N' m/ ^# F/ a - theSpline->Highlight();. V- q4 L' q. ^
- uc1601("Studio Spline Created Thru Points", TRUE);' m9 W; e' w2 q, y8 C3 A
- theSpline->Unhighlight();
8 y, l( V- @4 Y1 [* T0 r5 L y - }
! D* F ]6 a: j$ X$ F - }% @4 ?. b( y% Q* v, t! v1 a
复制代码
* Q) }: B" N U. a, Y9 v/ C! z" s) R5 [8 l9 e: |! R! H# c$ V
7 ^% ~# s% G% J' T- ^3 J9 f. H |
|