|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线4 A: P) n, M6 M) c+ _9 [3 P1 ^
- #include <uf_defs.h>+ P4 ~ l0 j1 I' {) B |
- #include <uf.h>/ K4 |3 S- k- V& U" q" P
- #include <uf_modl.h>1 e# f5 t6 h' }0 i4 j: Y
- #include <uf_object_types.h>" A: n2 t: U; V0 M. g4 D
- #include <uf_ui.h>
, ], }' E3 E% ~) ` - #include <uf_modl.h>
" {8 B b" k: |; [ - #include <NXOpen/NXException.hxx>
* R% e4 ?$ |' R4 _% j' w' e - #include <NXOpen/Session.hxx>
5 \+ ~ r5 ?/ N: b5 r6 c - #include <NXOpen/Selection.hxx>* b2 {/ D; P3 w D
- #include <NXOpen/Builder.hxx>% ? G- b9 A2 f, R! l
- #include <NXOpen/Features_Feature.hxx>
$ P2 x1 s9 v3 T6 ^' E# O: v - #include <NXOpen/Features_FeatureBuilder.hxx>/ u. B) q' Y2 y) T. `
- #include <NXOpen/Features_FeatureCollection.hxx>( ?2 M0 M8 o6 ?, h# o
- #include <NXOpen/Features_GeometricConstraintData.hxx>
% W! e! _: x1 L$ K3 x' O5 V) W - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
( K% h- h; p) C" p - #include <NXOpen/Features_StudioSplineBuilder.hxx>
3 U, H1 d9 D0 c5 U/ ` - #include <NXOpen/Part.hxx>4 k3 ~& r9 G! K( m
- #include <NXOpen/ParTCollection.hxx>
8 Q) B" f, G5 t6 s( u - #include <NXOpen/Point.hxx>
( v# W% k! n# h6 T/ ?9 [ - #include <NXOpen/PointCollection.hxx>
! t) i% \, g+ T3 M! Q - #include <NXOpen/NXString.hxx>
# o9 h& o# k& J6 _+ V, c" x5 e _ - #include <NXOpen/UI.hxx>
9 [* D7 S- r1 `! c; W - #include <NXOpen/Spline.hxx>
& ?9 B$ i' h: @" P, n* @: M! q0 h - #include <NXOpen/NXObjectManager.hxx>. z: \" e7 `) _$ S. g6 [
4 j# g( z6 R8 { t2 @. w- using namespace NXOpen;2 B& W! Q( {+ o. ~3 D4 \" O
- using namespace std;
2 {( w u o+ F9 f+ u
% o, f H4 g- ^" p- extern "C" DllExport int ufusr_ask_unload()
2 R0 p0 T; |. Q - {
$ U, x* a2 N! T0 k; v - return (int)Session::LibraryUnloadOptionImmediately;. {: w2 l& W) }$ A
- }% N5 p( T5 C( p0 b% r4 R; d, W1 l2 ]
- 1 n! e: Y7 B1 z$ p- d
- static vector<Point *> selectPoints(NXString prompt)' a* |4 J2 {7 M
- {. G5 _& R3 C' [
- UI *ui = UI::GetUI();
. t# f: I5 @2 S' n& | - Selection *sm = ui->SelectionManager();4 F, a/ ?( O9 a W
- std::vector<Selection::MaskTriple> mask(1);
, b& a1 C8 x( @/ D1 T. o1 ^; u - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* Y2 K. Y K4 [8 G" s
- std::vector<NXObject *> objects;% T1 E+ D- c7 I( c% I% t% X$ v
- , q! z( H; @0 @6 m0 E% x
- sm->SelectObjects("Select Points", prompt,
( s7 p" y. J0 g; y [ - Selection::SelectionScopeAnyInAssembly,8 T. W! ]: s5 P* ^: t- n
- Selection::SelectionActionClearAndEnableSpecific,- P% T' ^* p8 x1 W
- false, false, mask, objects);
* C3 a) {/ z- W) e; h - 9 y4 u* {$ o6 q; C- ?8 f& p6 u
- vector<Point *>selPoints(objects.size());9 f( S1 }% `6 ?& u. g
- for (unsigned int ii = 0; ii < objects.size(); ii++)
! e1 G# N6 S! m: r# j8 F - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
, m/ S- f( l( i8 k5 }6 y/ s
3 P* C# k1 a5 ~- Z% _/ L. v" `" @- return selPoints;
0 e* s( c I4 n2 } ^ - }4 n2 K# [4 `7 }2 k2 J9 Q+ ^
7 l! W: A3 f% l4 U- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
1 X0 k* X0 N7 l/ X - {
1 {2 U1 t: W% g( [1 ? - Session *theSession = Session::GetSession();+ _$ ^9 f: E8 ]5 @+ `. g9 H
- Part *workPart(theSession->Parts()->Work());2 X! W$ a- N- {9 d0 o
- 2 i$ g: |: n9 F- @& y6 H
- Session::UndoMarkId markId1;
7 n K7 s8 ^; P1 X0 w0 l4 Q - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
% ? ]/ E6 }, M% h6 `5 y5 ^7 I - "Studio Spline Thru Points");
- k% _7 l: d n& u- p" i* r( w) q
. h7 Y; ]* @0 R7 u5 K, u% W- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
& ]8 L& k: s- v7 t$ K' }
- I8 p8 O1 D0 Z/ }3 g; A- Features::StudioSplineBuilder *studioSplineBuilder1;
2 B2 \9 t" q# N/ V1 _& p* Z - studioSplineBuilder1 = workPart->Features()->
' ^- @9 z4 Z' v) f% E% x - CreateStudioSplineBuilder(nullFeatures_StudioSpline);( K' L7 o: n! G- q1 }; m
- studioSplineBuilder1->SetAssociative(true);- [2 k9 s) |. f+ A
- studioSplineBuilder1->
0 j! _+ m/ g* R* m k) Y c - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
! S6 k/ ?8 m! s* K! W* v - studioSplineBuilder1->
, M7 X+ u4 k% K1 T0 c: P# r; w7 x# S - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# x, O" V X `& S: w* v
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);+ O8 u+ z. Q# a1 q
- studioSplineBuilder1->SetPeriodic(false);
+ \1 m) V% \7 ~1 h - studioSplineBuilder1->! f, V: S" Q/ N; R' y
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
- }1 U- l) Y$ ]) x( B0 N - std::vector<double> knots1(0);
% ]2 H. d6 s9 |: z - studioSplineBuilder1->SetKnots(knots1);
' }6 W. a! |8 H2 ? - std::vector<double> parameters1(0);0 s2 f9 }5 Z+ N5 F: Z
- studioSplineBuilder1->SetParameters(parameters1);
@' T$ j0 M( O+ A U$ r9 t7 d, M6 ?& u - Direction *nullDirection(NULL);
2 e t9 E9 Y5 N- t" t - Scalar *nullScalar(NULL);
( }& q+ d' E( \- ? - Offset *nullOffset(NULL);
" O+ G% W( i [, J: n% o
; y2 G O5 D! M% d+ o) |- std::vector<Features::GeometricConstraintData *>
9 T2 [3 V# R& A( h4 \ - geometricConstraintData(thePoints.size());
( M9 K" ?% O+ J: m0 `4 W& w* M$ `
0 ~9 r: Y! w' O0 |- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
2 {' u% q* B/ }! ^ N0 E* C - {
- Q' k3 E' n: Y& h6 J: {5 ^ u - geometricConstraintData[ii] = studioSplineBuilder1->- w# I8 V4 n& ~( W: }
- ConstraintManager()->CreateGeometricConstraintData();* Z) \- ]( s p; Z. g$ I- q
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 c* J8 U" l: b0 t( m
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
1 z' [, u4 ]' ?) U0 ?, C - Features::GeometricConstraintData::ParameterDirectionIso);; L' J' g1 k) G0 E! f T
- geometricConstraintData[ii]->SetAutomaticConstraintType(/ S! p- c' i8 l+ M: c
- Features::GeometricConstraintData::AutoConstraintTypeNone);
3 e. C! B4 n5 E - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
9 V1 I/ w( V5 h& f1 R. f - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
8 y" [5 {( F, z, ]1 {& ?/ e - geometricConstraintData[ii]->SetCurvature(nullOffset);7 w/ C/ J8 } u: S% N
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
( W0 ~: b ]9 I5 y& K - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);* L# b. {' ^/ H% T+ t; ~7 n
- }
- _$ M) U$ i: |" s1 i- r4 M
# h2 S1 g& A @/ [9 X4 o- studioSplineBuilder1->ConstraintManager()->SetContents(
g( d; K, F( q) `2 } - geometricConstraintData);# c* M) R* E5 }
) l3 t2 u/ ^4 L8 ^# [- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 }4 e7 ^; i$ m% W
- Spline *theSpline = studioSplineBuilder1->Curve();" R m8 l+ D, o1 F' z; `
- 2 s: W- ^, \& I7 T; N0 U8 e
- studioSplineBuilder1->Destroy();+ {! w4 i% r% M0 ?$ U
- # x/ H! _, M6 t/ B& Y+ E9 T
- return theSpline;
& T2 e3 x# ]- l$ {3 I - }
, d( q) G% D) ]8 g6 g
& X' g. b8 s, R- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
$ ]5 Z' K0 P) I# d - {
7 T5 T9 w- Y- ~$ V6 G0 [ - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
$ a; W. O d) s9 n8 e' ]% I - if (!thePoints.size()) return;
+ V. d' y% X. F) A - " c+ N3 V9 b: h
- Spline *theSpline = createStudioSplineThruPoints(thePoints);) H2 q' X8 S4 o7 {5 O
* i3 {& P: Z4 B5 M" q- if (theSpline)
9 L) Q$ {# L: R# w - {
; j+ r- H# i. P( ?$ _6 C - theSpline->Highlight();3 @6 o7 c5 {& o9 ]4 J
- uc1601("Studio Spline Created Thru Points", TRUE);- l; p& R1 z" k
- theSpline->Unhighlight();
) Q3 \8 E0 W4 L5 a& ~" B1 Y! s - }: F7 j( A4 s. A( H2 f
- }/ i: T2 B$ C0 l" F2 Q8 ]% i& T
复制代码
: p$ I( V8 s7 Y0 {
4 P; O1 ?; i" }9 m+ r+ T8 f6 H' z) ^4 v. r6 K7 Z: Q* C! D
|
|