|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线) |9 r' W# G& ?7 e
- #include <uf_defs.h>& C2 ~. w8 d% ^2 f6 s, U1 Y
- #include <uf.h>
; b# M4 a# ]* `! t - #include <uf_modl.h>* S- O8 Y& N/ ~4 M9 ~, F1 r
- #include <uf_object_types.h>. P- V% Z2 g/ m, O: p) Z4 P' L
- #include <uf_ui.h>
* g) I6 m5 s! N9 v - #include <uf_modl.h>
3 @& G3 I9 C4 O, t3 i - #include <NXOpen/NXException.hxx>7 A' X5 J. F+ A2 _8 ?' i$ u
- #include <NXOpen/Session.hxx>
1 y) M0 z% T" p - #include <NXOpen/Selection.hxx>
# v' E( ^: D* g' k, ] - #include <NXOpen/Builder.hxx>, {) r2 `3 m- m' r0 i2 L
- #include <NXOpen/Features_Feature.hxx>
/ x( S/ {9 v8 W- y! r1 |0 V$ P2 c2 C - #include <NXOpen/Features_FeatureBuilder.hxx>+ ~2 P( ]$ V7 K0 ^8 J' m& x6 S
- #include <NXOpen/Features_FeatureCollection.hxx>4 R& y4 u& j" E9 ?" [
- #include <NXOpen/Features_GeometricConstraintData.hxx>
1 U9 d. n# q7 U& e1 ?* i6 a - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
1 j1 ^2 z4 s* k0 q. `9 g - #include <NXOpen/Features_StudioSplineBuilder.hxx>9 o" H9 `* Q# ^" H
- #include <NXOpen/Part.hxx>" H! {2 I& V# y+ \: n
- #include <NXOpen/ParTCollection.hxx>$ m5 N' q7 B! c2 {+ {
- #include <NXOpen/Point.hxx>
/ _$ u# C, @, S, ]! o, B7 A: C - #include <NXOpen/PointCollection.hxx>
5 s2 d+ U4 n: ?+ ?2 v - #include <NXOpen/NXString.hxx>9 \% _& P: d& P$ S" {
- #include <NXOpen/UI.hxx>
' q% v5 R; C8 ^$ u8 z - #include <NXOpen/Spline.hxx>
/ G2 i5 P' P' h) c* s5 \9 j - #include <NXOpen/NXObjectManager.hxx>
2 s5 Y+ P" ]$ y" S4 ~" c - ! H* `6 K4 ~4 P8 L) [
- using namespace NXOpen;+ h1 N( b) y5 Z; T- k- C1 U$ |
- using namespace std;8 Y5 d) j0 F- e' u8 M
- ; U2 P7 P# M9 U& t) L' S
- extern "C" DllExport int ufusr_ask_unload()3 g3 k! a( Y r% S; k W5 ], S
- {
3 c4 \. f0 p7 |8 V( T2 u4 J0 b - return (int)Session::LibraryUnloadOptionImmediately;- m& m$ @8 s; C) Z; q- S1 L
- }2 J8 I+ u& J, _4 ~: ?( O/ p7 i
- + U; r* N! A' s7 m- _% k; z$ l/ l
- static vector<Point *> selectPoints(NXString prompt)
( l" V) l) h$ m8 P( n+ |: j/ N - {
) |! F5 T, ?' l4 x7 R - UI *ui = UI::GetUI();" u' R1 A0 X. i6 G* G* o3 k
- Selection *sm = ui->SelectionManager();
9 T9 q5 Z# p# @6 k - std::vector<Selection::MaskTriple> mask(1);
$ V7 _ C" p; _2 B8 d- A8 C - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);4 s+ Y" C; F& l9 g/ `( e$ I
- std::vector<NXObject *> objects;
6 }) {% n R& P
, J! m7 `, r/ r7 Y$ K. C- sm->SelectObjects("Select Points", prompt,: W1 j( y# m0 \2 O
- Selection::SelectionScopeAnyInAssembly,- j$ `; y' E% R A9 V6 u
- Selection::SelectionActionClearAndEnableSpecific,
: n2 k9 W/ L, N: e, K - false, false, mask, objects);3 X( F' a5 q+ \) z* \
# k# a4 Y1 i- z: u- vector<Point *>selPoints(objects.size());
# S# I6 l8 U& J: D, q - for (unsigned int ii = 0; ii < objects.size(); ii++)$ s7 X8 T; Z i( b6 C# x# {, h5 ]. v
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);5 I+ ^5 r( K$ S2 m% Q* Z
- % U6 q5 B3 G; i3 Q0 N
- return selPoints;
) D4 g/ G# r0 |- Q3 } - }
/ c9 u. T& N+ K1 B% {
* t/ o! c3 f: y: \1 b- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints): S" X* Z, o9 p, o& ~0 n3 S) [+ m
- {
: \/ i5 ?, m9 c9 }) J# i - Session *theSession = Session::GetSession();
C; X0 G+ m0 s7 _1 C* v - Part *workPart(theSession->Parts()->Work());3 i: @# s1 J9 V/ j
' y2 B1 [( z5 p) H- Session::UndoMarkId markId1;: z3 D2 v& X- g$ K7 ^
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
5 y# K2 N$ @: X+ `: Y% P - "Studio Spline Thru Points");
) j! b" D! N' r5 B; C: v, j7 s/ k
- C8 K: k2 i* z$ J- l ?3 t- Features::StudioSpline *nullFeatures_StudioSpline(NULL);& K& ~ ]/ g# u3 O. ?/ l& |8 {
- / u2 [+ b: E( H* G6 |
- Features::StudioSplineBuilder *studioSplineBuilder1;0 Q$ p' t- J6 t
- studioSplineBuilder1 = workPart->Features()->! |. o( p) s) L# U' w* X) F8 H: P& f
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);% g% T# E& G+ `7 D2 O) D% ^* b
- studioSplineBuilder1->SetAssociative(true);
" N6 M! w. R4 M& B# D1 W - studioSplineBuilder1->
! _& z$ b! g" v, e `2 m' p - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 `; w6 R5 E) Y2 u
- studioSplineBuilder1->& R2 x, n$ W6 x# B# B+ r
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);( T s7 v# S0 f' X3 z( a; ^
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);) o- f' y" F6 m& A
- studioSplineBuilder1->SetPeriodic(false);
$ t M7 N( i- t# ]5 y9 i - studioSplineBuilder1->
4 _) t/ Z8 ]$ z- {% X6 w R7 K - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);0 ]% e$ h, n- ^
- std::vector<double> knots1(0);! l3 Q' N5 x7 @! E9 w i& a
- studioSplineBuilder1->SetKnots(knots1);
- _2 J2 \0 j5 o6 j; H$ D' A - std::vector<double> parameters1(0);
, M# p" x$ s2 N* I5 K, G$ a - studioSplineBuilder1->SetParameters(parameters1);
3 Z0 U: K5 Q/ B8 P4 _5 ^9 G* K - Direction *nullDirection(NULL); h0 W9 G; V" N) {( L. s% X
- Scalar *nullScalar(NULL);" c) W1 r" J1 [$ U* P' ^$ z# Z. q0 Z k
- Offset *nullOffset(NULL);3 V0 l* L. s5 z3 O. c% I4 b
- # j- E7 u8 O9 d$ d) _/ b2 c& F& W
- std::vector<Features::GeometricConstraintData *>
$ [. I1 ]$ q, K7 i, P0 I8 M - geometricConstraintData(thePoints.size());
+ i9 ` Q2 F' l# ]1 n, [' n - ) Y5 c2 D" h) u1 R1 W4 `
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
) J. y6 C% J: V; h - {2 D8 T* s9 w2 x6 \- K
- geometricConstraintData[ii] = studioSplineBuilder1->
5 o% G6 ?* H( ]- s6 u! q8 j2 v - ConstraintManager()->CreateGeometricConstraintData();
% B3 a2 H5 k/ R5 @: F% Q. t - geometricConstraintData[ii]->SetPoint(thePoints[ii]);+ O) J4 z. S; D" k
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 Q) o6 r% `* L7 Q
- Features::GeometricConstraintData::ParameterDirectionIso);
5 }) W" B/ X! r' M - geometricConstraintData[ii]->SetAutomaticConstraintType(
' x8 N8 b( `" ~, O9 G, E - Features::GeometricConstraintData::AutoConstraintTypeNone);, i5 c1 \0 X" y7 r
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ N4 I( H. |# z& v- v, o- s
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
' [0 ^3 }" C# X+ m( u - geometricConstraintData[ii]->SetCurvature(nullOffset);1 g! k, H2 y8 D8 r
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);# ?$ @& W$ d' W+ g& j* C/ m! |
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
/ H# `5 X! G$ _0 Q - }2 G% N# }% z5 ^
8 s: z8 {8 U ^7 x2 U4 N; b( m9 l- studioSplineBuilder1->ConstraintManager()->SetContents(
- U1 i; f. }7 m. G- @0 g- q - geometricConstraintData);+ `& K0 s/ j! S: `2 _" l) B) w
4 g* F+ ?. r" m- N- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();# p8 w- h9 p/ U8 A
- Spline *theSpline = studioSplineBuilder1->Curve();
* \% G: I) F3 [* `4 N# n
, ~: C* @7 W2 m- studioSplineBuilder1->Destroy();; u5 @- _2 o: h3 X. x) ^& I) {
2 m2 @" n6 Y ^8 u/ I. P- return theSpline;
3 M* n9 _) D, ?) k% d9 } - }5 w- S; D3 y [. [0 X# J `. g- k2 q5 z
1 Y) x) I5 s+ v! u# |9 c, ?8 |# }( Y- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): Z: v9 q: i8 F2 ?1 q" l3 |4 o8 J
- {3 @6 M; G5 p8 s2 r+ g* }
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
3 J W# W1 |6 F, g: j1 @/ B - if (!thePoints.size()) return;
: [/ Y$ _/ d6 g$ u: ^9 w
% C. x- I; j$ H# `, X& X3 A- Spline *theSpline = createStudioSplineThruPoints(thePoints);
0 F. _& C- ]/ h' D: k* n: v - / i2 w' `; ? R+ L& R: j
- if (theSpline)
% Y7 N6 [- p0 l$ t - {; E. l0 x" N) r, w0 U ~
- theSpline->Highlight();' F: h+ Z( V+ H1 P* ~4 h; t6 Z
- uc1601("Studio Spline Created Thru Points", TRUE);
3 y8 D: X6 }% Q1 M+ m3 C$ [( o* o - theSpline->Unhighlight();
; F, e0 c5 D: l e - }' k, [. V7 ^, g; J
- }
; v' V9 i, i3 ?! G- m
复制代码
2 H/ C4 T7 y4 b3 r5 z, u! c% v. X9 l5 m$ t Q% @! M4 S
h3 ~0 `0 D6 d- p& L8 s |
|