|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
1 u9 u& Y2 e5 Y4 D+ [% T- #include <uf_defs.h>8 k$ P5 c$ \) ~& {
- #include <uf.h>
2 x) {4 Z+ D; m# O - #include <uf_modl.h>
4 X6 H8 W/ n1 _8 O - #include <uf_object_types.h>8 a; u8 a+ h) R+ t
- #include <uf_ui.h>
+ i% z& A4 c* J+ \4 g" ~ - #include <uf_modl.h>
/ ]" E, p: g' m [9 g - #include <NXOpen/NXException.hxx>& k; I& P; i$ |. q6 V) J* F0 ]0 _
- #include <NXOpen/Session.hxx>: V3 O( C2 ~ ?& k7 X
- #include <NXOpen/Selection.hxx> ^" ?& i" Y4 O' x2 Z
- #include <NXOpen/Builder.hxx>
+ ~# a* d7 u& J9 L5 I - #include <NXOpen/Features_Feature.hxx>
6 {1 {" A+ X3 T* m, O: u. c2 e6 U, K; t - #include <NXOpen/Features_FeatureBuilder.hxx>
) H1 U: p: K0 O7 h - #include <NXOpen/Features_FeatureCollection.hxx>
% }2 G0 }) {) Y4 v* W, t - #include <NXOpen/Features_GeometricConstraintData.hxx>9 w% r5 w8 R' L) p) \
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- @5 Q2 b0 k( u
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
) m& u4 `7 A) B M2 s: o - #include <NXOpen/Part.hxx>
6 ^- H# y5 e$ t3 N9 h, K5 r# J) ` - #include <NXOpen/ParTCollection.hxx>+ M: M; B! N& [$ U3 _6 U4 F! q
- #include <NXOpen/Point.hxx>4 `" Q4 l. n: `$ t
- #include <NXOpen/PointCollection.hxx>
) X- ^8 j$ u+ C7 R# X p - #include <NXOpen/NXString.hxx>8 Q; `. D+ H' } {0 Q( r8 M$ Y2 o- c
- #include <NXOpen/UI.hxx>5 F2 W* u0 B" |$ T
- #include <NXOpen/Spline.hxx>) L' V, g A& u
- #include <NXOpen/NXObjectManager.hxx>
0 m+ P# L" @' J
% z7 \1 ~# z' M8 N- using namespace NXOpen;
3 {" u8 k% O" h+ i8 [% J7 N - using namespace std;
, \6 _5 q( [! t! _ - 9 ]0 Q0 U0 w: {" g8 H# R8 S
- extern "C" DllExport int ufusr_ask_unload()
9 |& m E$ K6 `& W+ D - {$ H, z5 W) \5 k4 U6 g0 R
- return (int)Session::LibraryUnloadOptionImmediately;
% a& Y" R, C3 i" ~, P( O - }
3 m& ~+ x# [, N% R4 R! v* B
1 L5 x7 i6 B b7 n! h2 u- static vector<Point *> selectPoints(NXString prompt)( Q5 x# S3 o$ z1 H* \
- {
/ b3 l3 b) J `; q3 Y' p6 t4 E7 A - UI *ui = UI::GetUI();6 {7 q' M8 k- F& D+ N2 T+ _: V
- Selection *sm = ui->SelectionManager();
! D4 Y" v* y, ]0 d9 P - std::vector<Selection::MaskTriple> mask(1);3 ^# h) w0 N0 d
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
4 \: G" A3 ]; s3 F: u4 C - std::vector<NXObject *> objects;
) g* ^' e6 L* y# h8 A, `$ R$ l" O$ r
- d5 ]% x' E3 T- sm->SelectObjects("Select Points", prompt,& K% k1 {; V; v! V7 b
- Selection::SelectionScopeAnyInAssembly,5 O& v6 j: u' C0 a {
- Selection::SelectionActionClearAndEnableSpecific," c- ^% [* |# F% y4 c$ A$ `
- false, false, mask, objects);& _4 ?9 O' H6 C+ S' X4 f
- ' d0 q' A1 t7 @+ O2 U6 S
- vector<Point *>selPoints(objects.size());& B. j# H$ Z& Z) K7 f
- for (unsigned int ii = 0; ii < objects.size(); ii++)
) }( u9 u2 G3 [+ {3 K' c - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
: ~4 D7 X6 [' D. L4 E# @2 O( r) y! ~8 B
. a$ o# z5 @" C, G$ `9 Q- D- return selPoints;
3 t# s! q$ c2 N& ^ - }3 t! q& }& J8 X' E8 y8 i
$ r/ z5 H2 ^, q- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 K( `& p$ Y4 Q: g Z: B
- {$ g+ x! {1 |" A6 C+ {" x0 v
- Session *theSession = Session::GetSession();
0 ^5 H, }4 U" ^' Y - Part *workPart(theSession->Parts()->Work());& Q1 \6 ?- p; a- ~3 w O* j; H6 E
- # ?" Z2 t, j- i2 I+ d
- Session::UndoMarkId markId1;
% L4 Z; P1 P$ [ - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible," I( O! q/ E2 z+ r' C
- "Studio Spline Thru Points");
$ E. `2 H' c0 t) m3 @5 V) i
; W- M% A, I) ~- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
" @) p# D+ m5 o8 j" _( \ - - \ |* O& v1 z4 N+ C! m/ ?8 m& b4 T
- Features::StudioSplineBuilder *studioSplineBuilder1;6 }) Y. D" Q+ M: [
- studioSplineBuilder1 = workPart->Features()->
- O$ y. G4 R6 B* E3 e2 a - CreateStudioSplineBuilder(nullFeatures_StudioSpline);" G0 K2 ^- ~( Z$ |* ~1 B: E& n+ a
- studioSplineBuilder1->SetAssociative(true);+ Y. J9 `$ ?; E8 m
- studioSplineBuilder1->
. z T+ u8 w6 s5 v g! E - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
0 x! J( m* q! w) x d) x - studioSplineBuilder1->4 U0 q2 m$ A4 z% G7 f
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
" ~/ Q J b: C: w- e - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( F2 h$ T/ D/ c& ^% ~( H/ C1 H5 c8 |
- studioSplineBuilder1->SetPeriodic(false);/ ^2 h& b6 A) E! V
- studioSplineBuilder1->/ \' W7 S0 p7 s( C
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ P! {7 F4 x; A! _/ v! Z, a) F
- std::vector<double> knots1(0);
; ]" H {9 x D# N- ^# S. @1 m - studioSplineBuilder1->SetKnots(knots1);" Y( m+ e# D; D* W9 W, ~
- std::vector<double> parameters1(0);
, c* `: r& I, K, s. t9 { - studioSplineBuilder1->SetParameters(parameters1);3 j" x, v- L4 }* E* ^! i& h
- Direction *nullDirection(NULL);
u! \: b$ D* B$ n - Scalar *nullScalar(NULL);
' x9 X2 s' R n- b2 N n! e1 c - Offset *nullOffset(NULL);
6 z x9 |2 ^$ R
9 Z' g) r+ f/ r, V! R- std::vector<Features::GeometricConstraintData *>5 [5 U( A! r& Q
- geometricConstraintData(thePoints.size());0 x! V, L: D: U8 W2 d7 j" I
. E( m/ {' b' Y4 E- B4 D D z! w$ z- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
8 C* _+ i/ B, r0 F& ` - {
% `( p! N4 V' A4 ]1 g( o6 N' l - geometricConstraintData[ii] = studioSplineBuilder1->
/ c+ m3 V$ F3 O& W - ConstraintManager()->CreateGeometricConstraintData();
( j' G5 p, l* ]% H, }* X - geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 E$ a2 b7 z& s$ P0 s
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
. j# d# `( S A( [3 ? - Features::GeometricConstraintData::ParameterDirectionIso);* o, ]! Q1 z5 J% N: g
- geometricConstraintData[ii]->SetAutomaticConstraintType(( e) P* Y# `" }* `
- Features::GeometricConstraintData::AutoConstraintTypeNone);
3 r8 ? ^, M2 [9 e+ z/ g - geometricConstraintData[ii]->SetTangentDirection(nullDirection); b# n d, Y# Z5 T0 m; ]
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
6 ~' E0 v1 k; j) t - geometricConstraintData[ii]->SetCurvature(nullOffset);
1 k: F Q; ^$ k/ M2 U* N - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
6 r# J- Q( |8 z, g) c; B - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 u% k% B! @% U$ i4 V3 F
- }, i2 P0 N% m3 G4 Y5 ]7 _ j) }. J6 f
3 K# j1 t. m6 b& o- studioSplineBuilder1->ConstraintManager()->SetContents(
0 R" t& `. d1 Z8 ^, F( B+ t - geometricConstraintData);2 z! W O. V3 L' A. q4 Q; x( o
C+ H) u1 ~5 s& K& E- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();5 X# }* {( ^& x1 v
- Spline *theSpline = studioSplineBuilder1->Curve();
; F2 ^: g e2 U& B3 @; X4 k/ H - + z/ Q7 l0 V; R+ Q$ \1 I! O
- studioSplineBuilder1->Destroy();' V% p6 C3 L* [, g+ K2 q4 }
8 y+ u. y$ N5 v+ U) a' k' @9 f/ H- return theSpline; X3 d0 K% e5 u6 M! s6 \
- }# A k+ C/ u$ p2 f6 k9 e% g5 c6 V
- 0 k( B7 X4 _5 T1 x# S
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
1 U b2 Y8 Z, ?6 Y; O6 q/ m0 q - {8 D5 ]7 y" V* |: B, r8 Z; ]
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
- c' k3 O4 ^6 k) I2 C! w/ C - if (!thePoints.size()) return;
2 Z% @& D$ f0 S+ R2 _
; r0 s W! d+ [- Spline *theSpline = createStudioSplineThruPoints(thePoints);; Y+ H- B5 p( n% U
0 f7 a" n' Y9 [7 }, U- if (theSpline)0 m# U$ }" y; y; F
- {
: v) J7 C) y$ f& {# N+ P - theSpline->Highlight();
& c) i7 ?0 _4 O - uc1601("Studio Spline Created Thru Points", TRUE);
9 W2 _; u0 R9 A3 D - theSpline->Unhighlight();
4 e2 C7 N' ^& ]$ y: {0 w( b - }7 L8 `2 m; p6 ?6 o3 `" h4 M
- } o! U$ J5 h; C# `8 x$ g
复制代码 0 g/ k! m, n5 I" X6 |2 C
- i" T, U- L0 [; \$ k( E1 L- x7 q& s4 M/ G( ]% V4 n+ S
|
|