|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线, `$ ~. o* D' a( I: O
- #include <uf_defs.h>3 o% w2 J/ [# \* v7 ^
- #include <uf.h>
# I0 ]# z# Y1 E7 M. } - #include <uf_modl.h>
4 y; o4 v- X6 l# {# u$ F - #include <uf_object_types.h>
5 e d6 N- [) O7 ` - #include <uf_ui.h>
. U, r+ G5 Q9 S8 X$ H - #include <uf_modl.h>+ B2 t! W$ {6 |- c% C2 E7 @
- #include <NXOpen/NXException.hxx>* o! c2 N( V; F2 }* H2 F* c7 g7 f( b
- #include <NXOpen/Session.hxx>) Z! n6 ]; c8 F1 a
- #include <NXOpen/Selection.hxx>
% z$ J7 D M, K" R1 ?/ O( ~ - #include <NXOpen/Builder.hxx>
9 F- L- A) T: g. B* S; } - #include <NXOpen/Features_Feature.hxx>
1 E$ O0 W0 e' s- d0 p0 I - #include <NXOpen/Features_FeatureBuilder.hxx>
5 ?* h6 ^5 o3 l - #include <NXOpen/Features_FeatureCollection.hxx>1 r2 Z8 h p4 s/ }7 h0 v4 }
- #include <NXOpen/Features_GeometricConstraintData.hxx>2 [0 j# S( O) ^4 i6 p
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
- m3 |- p6 G, w' j) ?2 h% Z# b5 k - #include <NXOpen/Features_StudioSplineBuilder.hxx>
0 d5 m+ c! e1 f2 v$ b& F - #include <NXOpen/Part.hxx>$ @8 i8 K3 x& d9 u
- #include <NXOpen/ParTCollection.hxx>
$ Z E+ Z8 U% t' G2 j/ }% y/ Y - #include <NXOpen/Point.hxx>
* d6 P* ^) _) @/ n# @0 ]( z0 C - #include <NXOpen/PointCollection.hxx>4 ]7 m5 \: n% C1 V8 J2 T2 p
- #include <NXOpen/NXString.hxx>
9 [" b$ R* E$ r9 d! g6 N - #include <NXOpen/UI.hxx>9 e3 Y3 V8 r. `+ G
- #include <NXOpen/Spline.hxx>
, C7 {0 \2 |- g9 \ - #include <NXOpen/NXObjectManager.hxx>
" J* O- R2 { t$ b0 E6 [ - 9 ^ ]$ H1 Z( q( ]
- using namespace NXOpen;
) G; ~6 v) J5 R0 A2 T0 G7 I# M - using namespace std;8 k7 Y9 c7 r! I {( v
- * G# G. h2 E, l, |; G9 _5 U. G! x
- extern "C" DllExport int ufusr_ask_unload()
* w2 D8 K4 ?' s' m - {! c5 Z$ Z. G7 |7 T/ q1 T# P5 K( k
- return (int)Session::LibraryUnloadOptionImmediately;) i+ D* M" N" O/ K6 {1 J
- }
$ q0 {. \) R0 m. ~! y8 W) R - # E1 b9 a2 T( ^% u9 G/ j: j
- static vector<Point *> selectPoints(NXString prompt)
7 ~4 M8 A& {/ ]% N - {
$ B8 u2 z3 G& k6 y - UI *ui = UI::GetUI();* ? t& s. i# b
- Selection *sm = ui->SelectionManager();
" p0 K3 e4 \* ]2 r - std::vector<Selection::MaskTriple> mask(1);
. b- H7 K1 k: W( | - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ t' d8 }0 ~% Y. o, r
- std::vector<NXObject *> objects;
4 L, e" s9 p g0 }5 \ - - X( S# Y+ G( i
- sm->SelectObjects("Select Points", prompt,
/ m/ [6 B6 G# r" q5 L5 l - Selection::SelectionScopeAnyInAssembly,! L$ \7 V" O' M2 D8 N h
- Selection::SelectionActionClearAndEnableSpecific,
2 T" ^0 ^% |4 W3 T - false, false, mask, objects);
; @, Y* a8 y2 l0 n! f4 r) h - 1 n. `. @% I" k3 `! M8 _6 c
- vector<Point *>selPoints(objects.size());
S: b! E, K0 @! H - for (unsigned int ii = 0; ii < objects.size(); ii++)8 ~$ g' n8 P' |7 D) M7 M; e
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);: b3 C" J" U5 i: g8 r
- 1 s9 ` ~9 ?- X4 w3 z$ F9 y) Y: K
- return selPoints;; C# A; d; [! Q. }# `
- }0 q4 H" B, t$ r' y6 R. U( ?
- ) M4 w: B3 Z: b4 G
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
5 T% O& b' a2 a: L - {
8 P% D' u/ Q% o+ n, e - Session *theSession = Session::GetSession();) a, F& w) s4 {! {& Y/ }
- Part *workPart(theSession->Parts()->Work());
b8 t/ h* W+ c+ g' v' [4 ^0 `# Q D
8 U3 M! K) E: A5 r; N9 E5 T: G# l- Session::UndoMarkId markId1;1 q g! ?1 t; Z- w- I. T2 ?
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,% G- y' B: U1 l4 C
- "Studio Spline Thru Points");9 f) M" i5 L" ^6 f
1 x* K3 w4 F( T% A# L- Features::StudioSpline *nullFeatures_StudioSpline(NULL);/ v m% e q5 ^* B
3 c% P C2 |0 l* [- Features::StudioSplineBuilder *studioSplineBuilder1;/ n' ?( }% \3 [ e; P
- studioSplineBuilder1 = workPart->Features()->
& Z/ U7 h+ V& d- G, X3 A" K6 B" Q - CreateStudioSplineBuilder(nullFeatures_StudioSpline);8 n$ T* E9 W# y* b* k
- studioSplineBuilder1->SetAssociative(true);% B# c/ d2 F h4 K6 G# a9 i7 _: \8 x
- studioSplineBuilder1->
4 u6 h+ Z7 v. s9 C! F: B# ] - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
\5 N2 Q; O- {" k8 Y& w/ p, G - studioSplineBuilder1->" C: A, K. z. ~3 w |' H( C9 B
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);5 s3 O- ]( d2 T2 k7 Y& @& U6 ?
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);4 l Y, b+ r) u6 M
- studioSplineBuilder1->SetPeriodic(false);
/ u/ n/ Z* B- ? - studioSplineBuilder1->: t' |/ O( n, @1 Y' G
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
) s! f( k/ T3 s t8 j - std::vector<double> knots1(0);+ H" _8 Y% H5 v0 g8 d% ^
- studioSplineBuilder1->SetKnots(knots1);
. v2 R6 b% F! c9 z: Y - std::vector<double> parameters1(0);
: {% T+ O% y# d0 }" i - studioSplineBuilder1->SetParameters(parameters1);: f3 v1 @; }. m6 F, O; H0 l% Q
- Direction *nullDirection(NULL);
$ ~) G: E+ `3 F3 M - Scalar *nullScalar(NULL);% W9 m7 x1 |2 p* s$ ?8 i
- Offset *nullOffset(NULL);
- m) p! V& R* M$ o
# h6 R* {# P3 J6 G- std::vector<Features::GeometricConstraintData *>2 w& n' z B, U$ F1 h# \ L
- geometricConstraintData(thePoints.size());# T3 [! R6 m& P( c
- 4 M7 [' |; Z2 w1 y' U
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
+ q6 X7 ]1 |4 Y" W6 n/ Q" u - {
, f7 Y# A d8 u/ x, y9 R: O - geometricConstraintData[ii] = studioSplineBuilder1->
h: [' r- B6 P0 k7 G o - ConstraintManager()->CreateGeometricConstraintData();1 B0 l: p1 A. d; l2 l
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
- s: O2 D- t: f - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
6 r( X' C) i1 Q$ I, I1 ]9 C - Features::GeometricConstraintData::ParameterDirectionIso);4 L$ w% r5 j6 |/ Q% ~" g' i
- geometricConstraintData[ii]->SetAutomaticConstraintType(
8 v! S w7 i! |6 ` g4 b) S; d - Features::GeometricConstraintData::AutoConstraintTypeNone);
8 T' |; E, f$ |8 j - geometricConstraintData[ii]->SetTangentDirection(nullDirection);3 C" Q0 M2 a5 n3 M9 U
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);% u. r5 j6 [/ l* f) L! M. K1 n
- geometricConstraintData[ii]->SetCurvature(nullOffset);
! J/ v9 i b y - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
% { a5 I1 d/ F - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);. p) b7 k7 }7 ^; \! O: S L
- }8 a; o4 Q- \. D. [" U+ y
- + g& M. N/ q; M7 Y; Z+ ]& f
- studioSplineBuilder1->ConstraintManager()->SetContents(
/ f( B; q9 D' W9 o - geometricConstraintData);# v. r- l9 D1 ]) Y
- ( \8 z& |2 C1 d( b- {9 o) J
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
. |3 h$ u( _0 ~# i5 b - Spline *theSpline = studioSplineBuilder1->Curve();: `, @2 w5 F' ^7 ?: F
& E8 k2 a5 g9 d P/ j- studioSplineBuilder1->Destroy();' n& R- M0 L$ p" I( Q" y
- 5 U( I7 n% ]$ ^) L( r
- return theSpline;6 I7 z1 S2 a$ f5 M# p$ T4 {, f" E
- }
/ d$ V( S1 |, [- P6 R - 7 }: ^& p5 [3 d$ A
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
8 l7 D t. r7 T5 ^ - {7 \& F8 `6 g) b' x& J K6 Q
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& m# U1 r$ }% [9 ^. x" O
- if (!thePoints.size()) return;% W @6 O& k1 Z7 G& w' D0 A$ t
- $ V$ S" ]: C5 E
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
. K( j( L( t0 n3 M5 k ^
$ A0 J& }5 ]7 n' t- if (theSpline)& y, W' t/ |9 R2 e* ]
- {
$ E: t6 k& }: X# h, N7 e s4 r - theSpline->Highlight();
* C7 z1 K+ O/ z5 f7 D( a - uc1601("Studio Spline Created Thru Points", TRUE);
& J$ L3 {8 K; A% | - theSpline->Unhighlight();
" C! N" h4 V U" z, u4 u6 ^: B - }
4 j# d& Q1 `( e4 C - }
* t: b7 X) ^( y! V" X0 {
复制代码 9 F' P7 o5 Y1 r' |" n
' Y) f5 H8 J, |
5 [$ P# O) P& m% Z5 { |
|