|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线9 C$ e9 t% G7 n, L8 w" v7 W
- #include <uf_defs.h>" g4 k- r- P# B& ]
- #include <uf.h>2 [2 ~* T& ]: e) `
- #include <uf_modl.h>: }% x( V6 j/ i
- #include <uf_object_types.h>
9 k- f6 s* q$ F' [# o) N$ ` - #include <uf_ui.h>7 r. l6 `( ]9 }8 r4 D. K3 W
- #include <uf_modl.h>! z$ y; M, I. U. B" Q; B& D
- #include <NXOpen/NXException.hxx>0 \4 c8 d8 n9 W# g4 \8 u' \
- #include <NXOpen/Session.hxx>* o" j: z4 F! h3 F6 l
- #include <NXOpen/Selection.hxx>& R7 y: i( \ v- q- s& b% e
- #include <NXOpen/Builder.hxx>
* i7 _$ c x: v9 Y, a - #include <NXOpen/Features_Feature.hxx>
! K9 ~/ D4 W2 y' T) d - #include <NXOpen/Features_FeatureBuilder.hxx>& z) T% l5 g" y& |2 w8 d3 z
- #include <NXOpen/Features_FeatureCollection.hxx>
6 @4 L; A5 T( |% r. U+ s - #include <NXOpen/Features_GeometricConstraintData.hxx>
3 R! j2 E& p3 k# ]/ p# } - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>( e! x. I; @5 ?- v
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
0 {) L5 T, Z6 l" M E( S - #include <NXOpen/Part.hxx>3 u4 ~' Q$ u$ g0 n1 y! T: z+ y
- #include <NXOpen/ParTCollection.hxx>
' y; u! [# i; {1 i: N p7 I - #include <NXOpen/Point.hxx>; l0 o0 F. k& D) {* u
- #include <NXOpen/PointCollection.hxx># E" H2 |# y- `% a
- #include <NXOpen/NXString.hxx>$ h+ R3 _" u3 @: y1 N; c7 g: o
- #include <NXOpen/UI.hxx>
3 ]1 W3 x" H# u( |3 S6 p - #include <NXOpen/Spline.hxx>
/ |* i) u$ M6 V( ` - #include <NXOpen/NXObjectManager.hxx>. ?1 R( A& d4 l: u1 v) ]5 z5 s5 g O
& E8 @. u. S, x s- using namespace NXOpen;/ K& v6 H! A) O% y: e* m3 h0 U
- using namespace std;8 H7 }, G- b' x! ^6 M( D
8 d' V0 n; X: p$ d+ m) D- extern "C" DllExport int ufusr_ask_unload()
7 f% ]! X; v/ o& _ - {6 c W9 T; \/ z ?+ G9 `. K4 P& `% ^
- return (int)Session::LibraryUnloadOptionImmediately;
$ \7 v$ O8 F! B6 @6 k$ w - }2 v( M3 Q8 s7 I' [
- 7 w2 W' o; x& l- X* {9 @, v7 ~) o$ w
- static vector<Point *> selectPoints(NXString prompt)0 U& ~0 _" I2 m* j& y- B
- {, ~! s Z6 F) r0 B" |* ]
- UI *ui = UI::GetUI(); D' v5 k. ~: s! \1 u: E
- Selection *sm = ui->SelectionManager();0 W8 Y" o1 a- I- [; o
- std::vector<Selection::MaskTriple> mask(1);5 u# p7 l" W3 ^ a+ ~
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);2 D% q2 ^6 @/ @. Z* A0 M
- std::vector<NXObject *> objects;
# o( ~! G1 C4 ^; b, X9 R. ]3 j
7 P8 m& r+ M! u% G- sm->SelectObjects("Select Points", prompt,! J* {' y8 `" \
- Selection::SelectionScopeAnyInAssembly,9 m M+ @0 Y/ V& B
- Selection::SelectionActionClearAndEnableSpecific,! Y; S% H# S T" B
- false, false, mask, objects);
8 K) |2 |8 [4 k. d, R, H; ]
: V/ v6 ?# q- k' l- vector<Point *>selPoints(objects.size());4 m/ _: j( Z) q
- for (unsigned int ii = 0; ii < objects.size(); ii++)
5 Z/ j1 W! O2 y' s, N5 c - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
3 w4 W1 J8 W0 r [" ]/ _! l' N - & q _: A# U; a
- return selPoints;1 j1 t! l; D# e8 ?& U
- }
8 U( w$ x K; \! Y; _
& H" J, [) n) B1 {0 U- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
) M: g7 V% f1 M* B0 g: ]! g - {, G' V9 _2 m. W5 m
- Session *theSession = Session::GetSession();$ P. B& @8 Z1 [* m1 `/ o
- Part *workPart(theSession->Parts()->Work());
4 u& U1 m7 G% t% l
) i2 Y. \) _. S- Session::UndoMarkId markId1;1 @. w; X4 D, z# U6 M: f
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
' G' l7 U( S$ ~0 V8 U0 K/ _ - "Studio Spline Thru Points");( ?" v' B4 {* |
' R3 J7 h/ m+ z0 Z- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
: q8 B( X: X' Q0 t) X( O
! P" s" E* m, N1 g- Features::StudioSplineBuilder *studioSplineBuilder1;6 U. ]2 |4 \% m3 Y
- studioSplineBuilder1 = workPart->Features()->% D% v4 L" O1 ^+ O
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 r( p) c7 a1 P( Z
- studioSplineBuilder1->SetAssociative(true);
5 ]. S' \. s# k4 j& K - studioSplineBuilder1->: ]% w4 ~3 \0 [6 |0 B( L
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);9 g* T# N( C: ^! t( H6 v# U
- studioSplineBuilder1->% F& |. J7 ^& u6 O- p* M
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
( @3 |/ F! r. K1 v/ r* w( t: w$ g - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);0 g3 ^; v" z" d5 q/ @( V }7 D% d. e
- studioSplineBuilder1->SetPeriodic(false);
2 {1 P: D' _9 t: D1 R+ n. a* i5 m - studioSplineBuilder1->
' D9 Q5 I( D1 U$ e9 T5 Q5 h - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
; J) d0 Y9 b, T0 A4 Y# x8 J - std::vector<double> knots1(0);/ K; t% B" y! H' G8 d' Y4 E E; d
- studioSplineBuilder1->SetKnots(knots1);. E; t1 a! z2 l+ P# p s& }
- std::vector<double> parameters1(0);, [: t' K! X2 [1 }4 Q
- studioSplineBuilder1->SetParameters(parameters1);" O4 N: @% d/ |* }; f" L! I1 B
- Direction *nullDirection(NULL);4 `" x$ }4 B% |4 H k7 K2 j; O
- Scalar *nullScalar(NULL);
% M) q' g. m. V0 Q - Offset *nullOffset(NULL);
4 O! i5 b c5 @0 I: V z
6 R8 M6 C% A6 z* a1 s- std::vector<Features::GeometricConstraintData *>( u: l5 j% \0 r( Y* j# j
- geometricConstraintData(thePoints.size());
6 M$ w3 S; n' U' I# v9 R9 s
2 Y- l) m; G/ z r; Q# ?6 i- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
" I! _$ h% ^, K4 D' K+ ^: V3 x - {
% G- G6 z# x' r" E3 J - geometricConstraintData[ii] = studioSplineBuilder1->
0 P$ G$ Z& g: j7 d+ H, `7 h% k - ConstraintManager()->CreateGeometricConstraintData();
& i: ^# o: y7 X p2 j- Y - geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 I8 a# I, z, [" e( r
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
9 S" \5 g+ ]$ E( [ - Features::GeometricConstraintData::ParameterDirectionIso);9 o! W0 x- I: d0 i8 S
- geometricConstraintData[ii]->SetAutomaticConstraintType(
' Z& r; ] [+ ~0 C0 Z6 A - Features::GeometricConstraintData::AutoConstraintTypeNone);( Y( Q5 z' w/ _+ g* X) c8 Y
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);& u3 W5 g5 k0 e8 ^+ K7 _; e3 S
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);2 x7 R$ Q0 {$ @" A. ^0 D
- geometricConstraintData[ii]->SetCurvature(nullOffset);% |' ^8 ]8 }# G
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
" b/ S& O+ [ g3 Y. b: H - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);: B3 q2 I6 [+ z* m+ a
- }7 P, m. d: `) ^& u6 K
* W, d1 A0 {! S( M+ N- studioSplineBuilder1->ConstraintManager()->SetContents(
, R9 ^8 t3 |3 b( H - geometricConstraintData);" O/ M' ]8 l9 O* m# Z
( v2 ], p, C c- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();9 i# Z+ U- d3 H* n; k) Z
- Spline *theSpline = studioSplineBuilder1->Curve();
& j9 Y# c& `3 C1 {4 C) j! @
/ Q2 b, G" u7 W0 ]( h2 G( q/ l& n- studioSplineBuilder1->Destroy();
/ U o n/ b7 S - : V0 ]- y6 d7 p: E; I
- return theSpline;
6 s0 \$ Z9 m& K! I - }
# X/ P7 |7 |! U$ J6 r# E+ I! p
* X$ n$ K1 ]- |( P2 r+ e7 K+ J- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len), @! G3 w( g2 F1 ?* n! O1 R7 C# C, c
- {
( P: E* z, O5 E! o+ p$ c - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points"); ~$ k, @ l& D! \! v0 f
- if (!thePoints.size()) return;
2 v8 d# u3 M3 X( n3 z- i+ h6 d9 ~ \ - / v N! w Q/ Z& e! A, \
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
. d K& g4 g- C8 ` - ' N3 G9 o+ Y' O8 o
- if (theSpline)
$ V" x0 f1 C# x | - {( O9 C# R# a D% p% |' o F
- theSpline->Highlight();
5 g$ U# t5 w& s+ Y. L3 W& N - uc1601("Studio Spline Created Thru Points", TRUE);
$ B3 P0 \7 O+ i6 @5 ~+ p$ s9 N$ @ - theSpline->Unhighlight();
+ m5 @, e; C6 R - }
0 h0 P$ x2 y/ L2 ^ - }. D4 v, U. }; m5 J# C
复制代码 9 ^: H5 p ]4 S
" A6 F' c: c* i& `# l: T, J
4 d3 {' v5 |+ J. j |
|