|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线( t' j2 J' [4 d' J1 D, N
- #include <uf_defs.h>
) I6 F3 O& h" C. {2 j$ y$ B# J - #include <uf.h>
E0 d& Q9 y n g5 @ - #include <uf_modl.h>
v* `) \0 R% l c- |4 k& \' D% J# W - #include <uf_object_types.h>
) g Z9 T* I, e% J- V - #include <uf_ui.h>
1 F) {. y7 }0 K; {0 I; P8 o7 q - #include <uf_modl.h>: u8 y& S( R4 x, X8 W/ b( a
- #include <NXOpen/NXException.hxx>
9 r7 d) N M% R1 h0 ^9 [ - #include <NXOpen/Session.hxx>
$ i/ D+ b3 U8 N. g - #include <NXOpen/Selection.hxx>
; c4 I# w" `5 M5 O - #include <NXOpen/Builder.hxx>
; k, [9 [( e1 o! O+ l - #include <NXOpen/Features_Feature.hxx>
- F; I9 g2 r3 {8 C9 u8 y' d - #include <NXOpen/Features_FeatureBuilder.hxx>& ^) \& P J* ^/ \4 S9 Q3 v5 y2 d9 z
- #include <NXOpen/Features_FeatureCollection.hxx>
+ ~7 x7 d; y* c: T6 X - #include <NXOpen/Features_GeometricConstraintData.hxx>
- O$ m( ~ S% Y8 \ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>+ ~3 i& a) d1 Z H+ k
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
1 G( A2 e' w7 ?6 q& P - #include <NXOpen/Part.hxx>
6 _% s0 r# o- P$ v. }5 B4 R - #include <NXOpen/ParTCollection.hxx>& o! D. O8 t c/ Y& u) d
- #include <NXOpen/Point.hxx>. u: ~0 b* f5 {% G
- #include <NXOpen/PointCollection.hxx>3 q* K) |; X! N9 q, u7 x
- #include <NXOpen/NXString.hxx>
$ t" |+ ]9 b' {% {- a/ `5 k - #include <NXOpen/UI.hxx>
! ~) F+ N! Q3 {6 F' u0 l: o) ` - #include <NXOpen/Spline.hxx>
* }7 j0 a! f. b5 ^- X8 W - #include <NXOpen/NXObjectManager.hxx>- s+ }, q) b0 W* D9 R% {. j
- ' k5 j) R" x: E% p/ G: k% [
- using namespace NXOpen;& F+ Q; O+ }0 ~4 E0 r% \
- using namespace std;
' n0 m5 I8 F# a q. r, U, T( N - + y- R& ~. j$ B5 y3 X5 B5 E' f
- extern "C" DllExport int ufusr_ask_unload()
# y3 V. ]& V+ P1 T n - {
! @% V% u- {: n { - return (int)Session::LibraryUnloadOptionImmediately;. V+ }4 ^' h: @% g
- }2 F1 ]/ Q" S4 ~3 X3 K
- 3 z O% Z" k! K+ ~0 y
- static vector<Point *> selectPoints(NXString prompt)
6 B% U: R7 F( K C, L; _ - {
7 u* H4 E3 J3 p x6 u - UI *ui = UI::GetUI();
! Y$ h' C3 O& F/ }" z! l - Selection *sm = ui->SelectionManager();
( G% A" g: S" j p - std::vector<Selection::MaskTriple> mask(1);' t* E, s% y( C$ T' `6 W& N; b# w5 |
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 j8 U4 q# k2 U
- std::vector<NXObject *> objects;
6 B; c# _8 O ^6 Y - / u; q* K& w K+ ~1 x
- sm->SelectObjects("Select Points", prompt,
) A7 o' t8 `4 _ - Selection::SelectionScopeAnyInAssembly,
8 Y8 S4 o4 ?# b$ w9 K% `8 ?. E - Selection::SelectionActionClearAndEnableSpecific,; D' @; ]" B% T; e1 F( P
- false, false, mask, objects);
* F" G+ E8 Q. y" I% @
0 e4 L! V- T# Q# l2 z* @4 k6 X; j: S- vector<Point *>selPoints(objects.size());
" Y6 Q1 G, N$ H' U" N; @ - for (unsigned int ii = 0; ii < objects.size(); ii++)4 n. R2 `+ Q0 J3 i: i
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
3 K! x$ I Q8 g/ V; _4 E* F$ { - $ ?2 a' q8 F" H
- return selPoints;
2 j0 b5 u; ` _5 K* i - }
m5 b+ m: T8 ^0 _7 ]* T - 7 r& N! m. G* R& }( a
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)4 o' \% X4 F0 g* F6 U1 V8 N
- {
6 [3 x1 R: Z) `# Z - Session *theSession = Session::GetSession();
: Y* z4 c L& z, q - Part *workPart(theSession->Parts()->Work());6 r. W9 v; I. m$ s/ \
- ! x6 |9 r! s1 G3 M E
- Session::UndoMarkId markId1;4 v9 j! \% ]. v$ I8 T+ u
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible," i r q: k$ r5 {3 ^
- "Studio Spline Thru Points");: Q! t3 D/ q, _& t- h
. e9 d/ K7 I9 r* O# [- Features::StudioSpline *nullFeatures_StudioSpline(NULL);: I9 Q4 P/ A% D0 m n: ]$ F& `- b
- $ @8 X% k8 X, K1 g3 G# E
- Features::StudioSplineBuilder *studioSplineBuilder1;/ f1 G5 v8 B5 E" H3 ]
- studioSplineBuilder1 = workPart->Features()->& I S# n7 m; P0 Q2 R- W9 t/ H
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
- d! n: I0 x- r B7 a# Y+ n; ] - studioSplineBuilder1->SetAssociative(true);9 C, l' C4 _& x- {# O" O' I" h
- studioSplineBuilder1->
& R$ \+ `& Q/ x* I - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
& i! g: g0 o$ f% ` e- o - studioSplineBuilder1->3 I: @* p! m6 c( f' X" y1 x
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 f. a+ v7 C+ B
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);& a* P7 }/ R4 M$ q9 }
- studioSplineBuilder1->SetPeriodic(false);
2 g P' y U% E - studioSplineBuilder1->" m5 e+ @1 L/ `# D- b B
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
# c$ p) w6 [0 ]& L& Z/ a' T3 p' B - std::vector<double> knots1(0);5 d" v3 u! G. ~# g
- studioSplineBuilder1->SetKnots(knots1);* l$ ~% i9 h" c" a6 b1 o: O
- std::vector<double> parameters1(0);
# {3 W5 R7 r0 Q4 R, ^6 s, p - studioSplineBuilder1->SetParameters(parameters1);
, x9 s. k0 B* s( \' B: H3 g( ?! m - Direction *nullDirection(NULL);& Q. S5 |: Q$ V
- Scalar *nullScalar(NULL);6 n+ Z" `: {* Z* f7 ~4 }
- Offset *nullOffset(NULL);
! G- Q* U3 i3 s8 I5 r - 5 w- U8 Q4 U0 U i3 a
- std::vector<Features::GeometricConstraintData *>1 o1 U1 n: w: L5 Y5 a7 a) g
- geometricConstraintData(thePoints.size());) l/ o+ ^+ |0 z7 m. W
- * d2 b7 D) l6 w! o j9 h9 u
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
9 R5 I) I5 ^# P; r3 ]+ x5 ` - {7 @3 O& V% O2 b% G& o: F' K
- geometricConstraintData[ii] = studioSplineBuilder1->
( B% e3 _0 h/ }$ Z0 `8 a( T" ] - ConstraintManager()->CreateGeometricConstraintData();
' v3 |# \6 B7 G8 K1 D - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
; z0 n* X2 N( @! E3 ?2 ~, d - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
1 E4 w4 W: M! h - Features::GeometricConstraintData::ParameterDirectionIso);4 `0 }6 L% s f( i( T7 L' o7 O- l
- geometricConstraintData[ii]->SetAutomaticConstraintType(
5 O* {5 }8 l* M: K/ J - Features::GeometricConstraintData::AutoConstraintTypeNone);5 F# o2 J! |7 Y6 N4 c6 z# n- ?8 c
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
6 H. `4 G# V _" A - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);- h, J0 f' V+ L) g, C: h* p8 T
- geometricConstraintData[ii]->SetCurvature(nullOffset);+ K P. x$ s9 f+ |/ \1 s
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. h! t0 d6 ~4 ?9 f- V2 Z# \9 S, z
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);" ]4 D9 P3 d8 i# d
- }
0 n. q' R$ E* }- q - ) r# u7 H4 z9 n7 L- G$ K4 T9 `6 w
- studioSplineBuilder1->ConstraintManager()->SetContents(7 q: P; m6 ~/ @+ \5 z+ \5 B' }- v
- geometricConstraintData);
8 }7 B- o7 j# V8 S+ z: {
1 X% m; W% Q4 H; O- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
& p9 F1 }5 C _- R - Spline *theSpline = studioSplineBuilder1->Curve();
, H% T) \* ~/ ~& I - - X. j$ |* o# K, }# G
- studioSplineBuilder1->Destroy();+ A- B6 x% v- e" J" t
7 A3 ]7 Y8 P( s: e1 ?- return theSpline;
; i; [0 V( W7 \3 i, q+ H9 m - }$ Q9 m% V- |& M# ~# I# F9 z7 J* i
9 D6 a- A5 d' g- r: B- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
8 k2 ?9 w7 ~: W# ]( d - {! S. P( H/ \* a7 k
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
2 p# @* Q; q/ ~ - if (!thePoints.size()) return;4 h- Z3 n C* V- M
- + H7 U' B5 r# b5 H; J3 Y: }
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
9 n1 ?0 p% R; t7 O. k; ^! L+ b* e } - / I7 ~3 t! J8 Q5 o# v
- if (theSpline)
" ?2 E- a E) V+ `3 J# E - {: O! h- Z, W& O) w9 Z, @
- theSpline->Highlight();" A- K& m2 y6 y( `8 i/ a& H
- uc1601("Studio Spline Created Thru Points", TRUE);% f8 y2 S- e" P0 h! G$ ~0 M
- theSpline->Unhighlight();
) b* z' w% s# X; V$ e - }
( }4 E# ^) |7 g5 X% Y - }
5 d/ C6 m$ X' s; z5 O/ { l
复制代码
) O9 d+ L& l8 ]$ I+ f9 Z9 `% w
: d$ E) x/ B& @! r5 g0 L4 p
5 k# @" O4 e) ^9 s0 o) X2 S |
|