|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线! u' i; c) \- O" i, v$ j0 U
- #include <uf_defs.h>
* n/ e2 B+ r& N& B: k# D - #include <uf.h>: U- ]/ ] D$ s- Q* b& F6 F
- #include <uf_modl.h>' O) \5 p. L6 v* v& {, R
- #include <uf_object_types.h>4 V V+ ` N$ ?6 c4 I
- #include <uf_ui.h>
$ f# K2 Q, z7 b4 G% \ y9 }. u* _ - #include <uf_modl.h>; I: n0 Z7 X0 N% O
- #include <NXOpen/NXException.hxx>
5 D3 }- ^; P3 V. S7 a8 M. f8 ~ - #include <NXOpen/Session.hxx>
" Q! E/ N3 s" `# _% t7 A! p& J - #include <NXOpen/Selection.hxx>
$ L3 E3 ^ |: ] - #include <NXOpen/Builder.hxx>" l& i3 ^) r- k
- #include <NXOpen/Features_Feature.hxx>
; \( J( g2 P" F4 a. H) |$ x( o( n - #include <NXOpen/Features_FeatureBuilder.hxx>8 ~$ z o, {7 P) B; D6 T
- #include <NXOpen/Features_FeatureCollection.hxx>
% S e9 m0 b' ^1 D9 t - #include <NXOpen/Features_GeometricConstraintData.hxx>( f+ e' r, q( y
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
: v. \# p. e: u& q b, U# h) p - #include <NXOpen/Features_StudioSplineBuilder.hxx>$ O. v7 |6 p/ c5 K! P6 I
- #include <NXOpen/Part.hxx>
7 B. b D7 P9 H, @ - #include <NXOpen/ParTCollection.hxx>" q* y B2 y$ r$ N% d
- #include <NXOpen/Point.hxx>2 a" i% M( g' T) c" A' F; o) E
- #include <NXOpen/PointCollection.hxx>
; p3 n1 ?2 u* X. w! K - #include <NXOpen/NXString.hxx>; R: ?, f, t& g* m8 V
- #include <NXOpen/UI.hxx>5 x8 d* A D, {! G2 w" s. a
- #include <NXOpen/Spline.hxx>) c2 H# d- K( x
- #include <NXOpen/NXObjectManager.hxx>
" p; X6 @; D8 D9 A - % K, c) S% ^" o2 J9 D7 a
- using namespace NXOpen;
& x. e( F0 ?. b - using namespace std;
8 O0 o+ _$ S0 _ c# \
2 O& Y: d( n$ T- extern "C" DllExport int ufusr_ask_unload()
/ a7 w% Y" C7 h3 K# b - {# F: S3 r( y: ~
- return (int)Session::LibraryUnloadOptionImmediately;- P+ Z7 T5 P) I" R; u
- }6 o0 c- _4 t. ]5 `! _% u, ~4 {
- 0 j( h" {. Y4 Y
- static vector<Point *> selectPoints(NXString prompt)8 `8 x# n* u% \4 b/ C: p# S
- {
6 B& V3 h$ i0 t2 Q3 m) I0 H - UI *ui = UI::GetUI();1 d+ \ ^3 I" d3 t* f
- Selection *sm = ui->SelectionManager();
+ R' s' h7 B/ b7 g - std::vector<Selection::MaskTriple> mask(1);& b+ x* F; _# x& O! ^, l$ ^
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
. U; g" M6 A' s J - std::vector<NXObject *> objects;
- U! I) V" j2 R4 U" o$ R
$ Q0 @& `( j. g2 G- sm->SelectObjects("Select Points", prompt,# [- G" N8 R' N$ b e
- Selection::SelectionScopeAnyInAssembly,
' ?' |0 l" F' C - Selection::SelectionActionClearAndEnableSpecific,$ a) b) @0 ~2 S& h
- false, false, mask, objects);
- r2 R- l( }0 g8 }
& y& W" n3 M. A4 Q6 z9 N- vector<Point *>selPoints(objects.size());
! a9 V' L9 b% L( B- s; t - for (unsigned int ii = 0; ii < objects.size(); ii++)
! L5 r+ }7 N8 g8 o - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 p, B$ G5 G# I7 C
0 N( B5 I* B( i1 K& }- return selPoints;$ y: P0 b l, u2 {& W6 T
- }0 C7 s4 c3 C+ s% [: b
- + \- @$ g/ h4 f2 Y2 A( V, D% r4 s
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints), f7 i0 T8 _: x' K p7 b
- {
/ A3 p* J3 h7 r* M1 \0 w - Session *theSession = Session::GetSession();: X) O, t2 P4 E
- Part *workPart(theSession->Parts()->Work());
^3 y: W* N+ |: ^" n. A
1 k5 u; J% G$ ?) T: s! m- Session::UndoMarkId markId1;9 B7 q) V" i4 B- \* a- H/ P( c
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ Q1 _1 K0 ^2 G& h
- "Studio Spline Thru Points");
4 w J+ u. b; d, O$ F - 8 t4 r- \9 k/ d2 Z2 e
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);. _$ ]. a/ y. v7 h! F2 |& @
1 J+ R f+ J6 P; x( ?- Features::StudioSplineBuilder *studioSplineBuilder1;
' e6 E/ F6 V7 }, S1 H6 O, [# q4 o - studioSplineBuilder1 = workPart->Features()->4 O# i9 c! D e/ {' W
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
# P ^' }: U- U* H' ?+ k - studioSplineBuilder1->SetAssociative(true);
. ]8 K, G) \2 u - studioSplineBuilder1->
; o/ N) n" d! w - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 Y. I" g h3 W ^1 ?6 O
- studioSplineBuilder1->3 A7 I* C" l6 @, R
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);7 t3 B1 q S1 w8 ^$ A5 @' K
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
" h8 B% @& }6 x9 P; P- X - studioSplineBuilder1->SetPeriodic(false);6 g0 u+ g/ C% M4 I: n
- studioSplineBuilder1->
' m% `& Q4 i; C( u2 {' d - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ ~2 Y1 a f7 n
- std::vector<double> knots1(0);! u' q7 A# O+ A% n$ b1 e
- studioSplineBuilder1->SetKnots(knots1);
% o) J. b8 z! e/ d4 m8 ?8 G - std::vector<double> parameters1(0);
! k. z- w7 z6 @ d: s- I& y' ? - studioSplineBuilder1->SetParameters(parameters1);
$ z. r' w5 Y( ~/ b - Direction *nullDirection(NULL);7 a& q& ?+ r8 B# i6 [$ F
- Scalar *nullScalar(NULL);6 N: Y. _- X4 S. N* S4 y
- Offset *nullOffset(NULL);! N2 s9 g0 c; V5 T5 e- G( ]0 C
- ! j8 @- v7 m) O/ \( h5 {
- std::vector<Features::GeometricConstraintData *>% M1 Y* t2 t& C$ O3 h
- geometricConstraintData(thePoints.size()); a; E: e0 Q" o% x& J* c
) |& |2 C8 `' f0 D3 s2 x- for (unsigned int ii = 0; ii < thePoints.size(); ii++)- K# q& N! L% B3 t {
- {
+ V9 X, k9 k C% y! K u' \ - geometricConstraintData[ii] = studioSplineBuilder1-> F: h S1 D0 W Y
- ConstraintManager()->CreateGeometricConstraintData();& e% ~& H5 c6 V
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
& A# s; d9 P- N3 X+ i' [& t" f, y - geometricConstraintData[ii]->SetAutomaticConstraintDirection(, z0 w5 h& I, k( x
- Features::GeometricConstraintData::ParameterDirectionIso);4 e" c. T3 |3 l+ d i, w
- geometricConstraintData[ii]->SetAutomaticConstraintType(
( O1 I8 a3 C! u/ x4 s9 M - Features::GeometricConstraintData::AutoConstraintTypeNone);5 h Y8 A0 d+ h& [+ L
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
- H: I- L: V3 R8 L" X - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);# U5 _& M9 ?4 q- \0 |" Q9 R
- geometricConstraintData[ii]->SetCurvature(nullOffset);
Q" B- p, s" ^% @% r - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);7 Q% _4 s, h5 z0 U3 Y: D
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);% c7 P5 m2 b3 H
- }
5 c( @# u) }. y' R$ @2 l! E1 _
* L+ k1 Z6 L6 ~8 a- |- E) p* s- studioSplineBuilder1->ConstraintManager()->SetContents(
: H! c" M) t9 M( C - geometricConstraintData);' `5 E9 h, R/ j, k9 ~% z
- ) J$ i) _0 c8 L
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 p+ i/ t( R% y. A6 n) H
- Spline *theSpline = studioSplineBuilder1->Curve();
$ `% G% E# ?9 t) r" X8 k
- A+ Q! V' d2 t1 L6 \6 t- studioSplineBuilder1->Destroy();' L6 o/ Z1 g+ ~+ j) f
. L/ W ~. f4 n7 C9 e: W0 x- return theSpline;8 U7 t( o3 F7 t0 | i7 s$ [+ [
- }6 a4 ?- A6 C v4 Z7 z
- 9 {" a# x8 p3 \
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)5 H7 |3 B# r$ j; j: d
- {( C7 C6 _6 B5 V* D; R
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
& Y8 w3 k0 e; L: S p4 B4 F - if (!thePoints.size()) return;: i& D8 H6 g, W: s- m
3 L$ A) h( |) o# O5 c8 P$ h- Spline *theSpline = createStudioSplineThruPoints(thePoints);
- f9 T n8 L% u& ]
/ [; V- R a1 B" n- if (theSpline)
7 V- a; ]; [+ H9 |; u# X - {0 S" E" O" t4 M
- theSpline->Highlight();, t+ H& k. T5 S1 f
- uc1601("Studio Spline Created Thru Points", TRUE);! W6 f( u5 ]% }# s
- theSpline->Unhighlight();1 `# X1 H. [5 n
- }
+ _5 G: D' u. \6 j! V - }
# f/ [: D# L; R( {$ k( j% m
复制代码
% X, R6 c* H' d
# W: r/ U i. C8 z9 a: @5 |2 `' E0 k. g. t
|
|