|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
! W7 G/ Q5 y S& G- #include <uf_defs.h>
) Z0 L* j& ^3 V - #include <uf.h>
3 v# C3 f1 M0 F* Z \7 y3 j- z - #include <uf_modl.h>/ D6 |0 r4 ~! ~+ _3 C
- #include <uf_object_types.h>" c" z8 {0 Z' t0 w4 c# n; }
- #include <uf_ui.h>: t' F4 {+ ?0 M& B6 w) i+ K
- #include <uf_modl.h>7 g: U! Z; R( ^
- #include <NXOpen/NXException.hxx>6 M, @: p' `9 M( H- h
- #include <NXOpen/Session.hxx>
* O$ {/ S+ N% ]7 Y( r# [ - #include <NXOpen/Selection.hxx>
- z* i' O( E+ Z/ E1 D7 S7 x - #include <NXOpen/Builder.hxx>
0 o, J. H) ^+ R - #include <NXOpen/Features_Feature.hxx>
P0 z: L1 P& r - #include <NXOpen/Features_FeatureBuilder.hxx>$ S3 i6 ?7 H4 n# |' H+ z E
- #include <NXOpen/Features_FeatureCollection.hxx>
+ ^9 W! b6 K! c9 a( {* O - #include <NXOpen/Features_GeometricConstraintData.hxx>
8 J0 [9 ~" @: M" v - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- G' m% Q% o( {% d+ S9 |
- #include <NXOpen/Features_StudioSplineBuilder.hxx>- m/ r- Z' M O7 K8 F% ]
- #include <NXOpen/Part.hxx>/ {' C- Z; \; C+ U W8 X- z
- #include <NXOpen/ParTCollection.hxx>
0 e* p3 V v" L# G/ }9 Z - #include <NXOpen/Point.hxx>
, S3 j/ @5 c4 m. @6 I' h0 | - #include <NXOpen/PointCollection.hxx>
5 y% x3 R& X4 N" A; W& L3 d+ Q9 H - #include <NXOpen/NXString.hxx>& B' T5 y2 A) S T& E$ o6 Q
- #include <NXOpen/UI.hxx>, T6 w/ ?' ?5 v
- #include <NXOpen/Spline.hxx>3 Q5 ^& T* {0 j- Y. C; p
- #include <NXOpen/NXObjectManager.hxx>) i5 @- n3 J! k
- ! o+ l9 E" z* j
- using namespace NXOpen;3 F2 H% X( ?2 [' \
- using namespace std;
p3 X# ?5 p/ w* M) A
( F% N; H( Q" _4 H" |" J- extern "C" DllExport int ufusr_ask_unload()6 X5 Q8 `& ]0 k- p5 E0 V) D$ Q8 a
- {
4 ~# G9 e! H" ? - return (int)Session::LibraryUnloadOptionImmediately;
Z' _3 X! _( H9 M - }
9 s/ e! X% }/ }9 o c+ S9 @ - 2 a( j2 ]# y* j0 ~
- static vector<Point *> selectPoints(NXString prompt)
% U6 Q0 _# C, ?9 G; [ - {
" k* D; L2 J* m - UI *ui = UI::GetUI();
1 W" |: m$ K1 E% w$ a3 E# u - Selection *sm = ui->SelectionManager();
, t8 Q' L% f, m8 j - std::vector<Selection::MaskTriple> mask(1);
( {; X7 L9 w1 X! s" H! F - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% `! U' B# l: U
- std::vector<NXObject *> objects;
% ]2 ^9 H6 {* {. T3 i
! t7 U! @3 I5 u/ Y0 T- }- sm->SelectObjects("Select Points", prompt,3 q( M! V1 l2 e2 e% R$ o# t L8 i
- Selection::SelectionScopeAnyInAssembly,* M [6 \8 h1 i# B/ e
- Selection::SelectionActionClearAndEnableSpecific,
. s6 [5 V7 h+ {9 A- J9 H - false, false, mask, objects);
4 ^3 U q h7 r
) o1 |% B' t9 r- vector<Point *>selPoints(objects.size());* ]" z6 }- s, B
- for (unsigned int ii = 0; ii < objects.size(); ii++)
3 l- g! o7 w3 J) [) y5 D - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
/ Q# J: r) a8 {9 h" d1 q* ~' j9 {, P9 r
1 W' n4 z- \4 i- return selPoints;0 Y$ n, h! G8 T: e* B; V! f
- }
1 S3 ?4 I4 u/ r0 J7 I1 r - : I6 D+ E9 u O e v3 b9 n
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 ~8 |, A3 g& [2 v2 P1 j
- {
! @5 D; X9 ~6 Q- { - Session *theSession = Session::GetSession();
; t8 P, G. [9 |$ P, ~. L - Part *workPart(theSession->Parts()->Work());
: X' o. `/ a o" T/ o2 a/ u( d* X- i - ; i& g6 M5 H' w ?6 U7 L
- Session::UndoMarkId markId1;
6 k6 b6 L& @3 K, z7 I! y3 E. r - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
6 O9 z9 l G7 {: _ - "Studio Spline Thru Points");- y# @- P+ W, ]! o% V* o3 U
- 0 c& w+ {% i4 Z, ~, N/ V8 {: E: u! l
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
- ?/ @% F2 @7 P6 K! O7 H5 I: C, V - 9 d2 f+ Y- M8 E& v% E! v! F7 P
- Features::StudioSplineBuilder *studioSplineBuilder1;* U* \/ H' v8 h* @ u; `- U
- studioSplineBuilder1 = workPart->Features()->. c/ ]+ ` Y6 h, D2 X
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);, X! w/ g# H( [
- studioSplineBuilder1->SetAssociative(true);
$ a4 e9 i4 z4 e, Z3 C - studioSplineBuilder1->
% |9 b3 q3 \7 v$ P, `6 X - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
. z! y* n, L. B" s" H1 T - studioSplineBuilder1->* W, m; R! B# u4 _/ R3 N+ D
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
6 t+ a; k, ~9 U6 B* q# [ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
& M; c0 q$ r% ~! e) Z - studioSplineBuilder1->SetPeriodic(false);9 k$ F& v% p, H# @
- studioSplineBuilder1->: c7 r! L% `& ?& R/ A/ D$ [! X
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);7 D9 v" {: v# |( D7 U9 ?6 z( s
- std::vector<double> knots1(0);
# @- B# Y4 `7 k. B d - studioSplineBuilder1->SetKnots(knots1);
9 D0 c% @: h9 _! e% Z5 E - std::vector<double> parameters1(0);: N o S5 C; L2 l
- studioSplineBuilder1->SetParameters(parameters1);
& i8 v2 B+ H+ @ W) { N- X6 W# X4 M - Direction *nullDirection(NULL);
3 z6 B/ x/ ~( a/ @+ l: ?+ z - Scalar *nullScalar(NULL);/ S* i$ Y. J+ @% A5 s4 h
- Offset *nullOffset(NULL);# S+ `; F& B3 r% S
- & [7 C/ {( k- u _4 B0 s
- std::vector<Features::GeometricConstraintData *>. {0 v4 c+ ]/ f6 I7 f2 N8 s
- geometricConstraintData(thePoints.size());
7 C, Q0 G5 g+ d2 |# \
& x. i4 b- Y- U- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
+ _3 |" w8 z; X3 w8 V: s' c% s - {) l" m1 O; v" h* ?- t% c1 h
- geometricConstraintData[ii] = studioSplineBuilder1->
5 b0 s( d' \, X$ a - ConstraintManager()->CreateGeometricConstraintData();3 E# M% J L1 [/ O
- geometricConstraintData[ii]->SetPoint(thePoints[ii]); B% }3 h& r( s+ r) Y1 I
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(8 j: j# b4 `5 f1 i6 h
- Features::GeometricConstraintData::ParameterDirectionIso);( |& T/ p' B; [, D
- geometricConstraintData[ii]->SetAutomaticConstraintType(
: f$ N5 F- S! U8 ^/ W9 r9 }6 ] - Features::GeometricConstraintData::AutoConstraintTypeNone);
* V {7 f7 i1 Q" F2 a - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
9 H F, @4 V7 E9 j+ z% r: o8 j+ y8 b - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 l$ H: G2 c/ ~2 ~) Q8 U
- geometricConstraintData[ii]->SetCurvature(nullOffset);
) K( i G0 u% ?- J3 O - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
; w. K. {" \0 V0 c, ]9 w* H' S - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);# U$ V2 M3 | w6 r5 n+ ~
- }
! ]) e/ O, c3 h3 T+ U: S
V) H& N! ~3 j- v# i- studioSplineBuilder1->ConstraintManager()->SetContents(
; m) A6 f* l2 K - geometricConstraintData);2 F& I6 L. W) t. P9 I; m
) _ b$ P. m% O3 _$ G/ Y# r# {4 y- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();9 x' B7 a4 {) P
- Spline *theSpline = studioSplineBuilder1->Curve();( K# i# S9 O0 R1 p4 B0 z K
2 e" W' R d- `' R- studioSplineBuilder1->Destroy();. @5 r( I0 m: P$ ~+ S$ s k8 C3 C
- " e7 G% p' T% ~0 n) \
- return theSpline;
( ]7 y. c* [; b" s, J( F3 G - }( x8 _" a" h" j1 u X" }$ ]; O
- $ K% ?3 E* w& p" k& U7 y8 z. o
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
# y$ D2 I T0 v# D8 E) X - {
% [" B' b5 |5 W2 N7 W2 v" A - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
7 K3 \* ?& b2 Z - if (!thePoints.size()) return;7 A: T0 C) r; O2 T. h, D) ]/ w
+ T' p# O7 u. Y5 Y3 D5 y4 ~- r- Spline *theSpline = createStudioSplineThruPoints(thePoints);: d$ O( e. H; O( ]- r
; Y& l N9 N& I) l+ V1 M E# W1 t- if (theSpline)
1 ^' m4 W# h. Z( i. j# y - { [+ K Q/ B! F* M& T# t( L
- theSpline->Highlight();
' }* f+ y9 v9 H$ Z2 s7 d- v - uc1601("Studio Spline Created Thru Points", TRUE);
& Y( O0 t$ K( u- @; @ - theSpline->Unhighlight();
3 |/ Z& i0 _& ?: q6 |% Q2 x2 ]3 H& g - }
/ Q+ l. ]% R o; n0 q" O - }3 g* F; R8 X, n$ w! H: d. B, J) Q
复制代码
2 W& L2 O5 Y% i+ V% D+ t
1 ^! A: U$ p! j* j! K* s! \! A+ `- I* \
|
|