|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
0 B0 J4 ~- M7 B7 D8 cNX二次开发源码:通过选择点创建样条曲线$ x6 S8 L* Y0 k1 r* c" Z6 v
& e5 h8 I! B1 T7 b7 W4 Y" ~
" ^' P3 g; I/ a* c) M7 D+ u
8 x5 z' M8 z/ E/ P0 m3 o- #include <uf_defs.h>
" B6 B! g0 A p - #include <uf.h>' Q% S+ f6 ~) q( F4 r5 r! s
- #include <uf_modl.h>" g# {/ D& G3 M
- #include <uf_object_types.h>$ g0 H/ _: k- k
- #include <uf_ui.h>: C7 L$ {2 Z3 b1 Q
- #include <uf_modl.h>& e0 p% T5 d/ {
- #include <<em>NXOpen</em>/NXException.hxx>
7 C) m6 N: Z7 P - #include <<em>NXOpen</em>/Session.hxx>9 S% Q! \# R3 c9 y9 R
- #include <<em>NXOpen</em>/Selection.hxx>
/ r4 f& x! K; M \ - #include <<em>NXOpen</em>/Builder.hxx>
. |0 C! b* K9 } - #include <<em>NXOpen</em>/Features_Feature.hxx>; t9 h, `: ?1 t$ l! o! K
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
4 I. ?- _+ a2 }# v - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
# t4 Q9 J6 c: P$ O" X, l/ K- \ - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
4 q& z* }. \/ q7 x5 m( { - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>2 y5 g8 A6 A# @4 q( X4 }
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>2 B0 {( ^( J- q. H
- #include <<em>NXOpen</em>/Part.hxx>
* ?* b' |4 O/ w" H, J6 F: _ - #include <<em>NXOpen</em>/ParTCollection.hxx>
# A4 W3 {& S* p0 S4 a - #include <<em>NXOpen</em>/Point.hxx>" u2 t( e8 }: h/ e% A$ y* y. E
- #include <<em>NXOpen</em>/PointCollection.hxx>
: k) Q/ D. V% S; i ] - #include <<em>NXOpen</em>/NXString.hxx>0 @0 \+ ?! G, l9 {7 Q
- #include <<em>NXOpen</em>/UI.hxx>$ [5 p' T. d4 I, O- A" F
- #include <<em>NXOpen</em>/Spline.hxx>
% m& t) d* f1 W* `& c8 D - #include <<em>NXOpen</em>/NXObjectManager.hxx>
+ y1 d0 ?4 u& M% C! N
" t+ ^' D2 m( f f) o! G6 D- using namespace <em>NXOpen</em>;
" o. |3 j& n) r! z. A, \ - using namespace std;. F0 t2 W/ u" ^. f" x% H
g% |' k9 s6 o2 z$ L' O( P- extern "<em>C</em>" DllExport int ufusr_ask_unload()
1 K& H2 s# }$ n) ^! k' Y5 z1 B - {
) U+ V7 {& S, I9 ~0 b0 Z - return (int)Session::LibraryUnloadOptionImmediately;4 i: I9 F# p% B7 {3 Z) L* x+ c6 H, E
- }3 N/ E5 ]8 h6 u. B* n: D
- ( M8 a4 Z; ^9 G0 l6 p! k* Z9 L+ ^
- static vector<Point *> selectPoints(NXString prompt). ~) s" x [# }2 B% a0 p# [
- {
( k# r2 P" k/ A8 {0 G6 a; b) B - UI *ui = UI::GetUI();/ ^& u& f1 B6 D# R0 e6 X: `
- Selection *sm = ui->SelectionManager();, R6 {$ Z& ?" P/ X) C2 H, N; y6 I
- std::vector<Selection::MaskTriple> mask(1);
0 r+ L. I7 T J( G! B - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);# J0 Z1 @/ O* a6 h1 n1 F: r
- std::vector<NXObject *> objects;3 Z4 F' F4 y. E3 `
: k+ f% ]6 P* y, ^7 @! T- sm->SelectObjects("Select Points", prompt,
* o9 b/ z3 m; W; v - Selection::SelectionScopeAnyInAssembly,
3 o+ Y+ E; g7 }' a# @ - Selection::SelectionActionClearAndEnableSpecific,: i; w) k6 F6 f- B5 X" O- ?
- false, false, mask, objects);
( P S4 a$ N. P9 L$ g( A! O - 8 P) n( [: k5 O9 r, Q* [6 G
- vector<Point *>selPoints(objects.size());6 l |1 ?, Q2 g7 t/ q( p
- for (unsigned int ii = 0; ii < objects.size(); ii++)0 M0 X, }9 e0 {1 u' A/ `& O
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
( H4 ]+ i0 I% y, x% i - ; @" A. N* ^% `
- return selPoints;/ D: ^ T9 S: D6 x' O5 Q) V! j' r
- }& j" g5 ]- J6 U7 L
6 n; M) D, P8 ?- O6 ]- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
5 l& U N3 H) J - {( t2 p: s, g4 d. A; Q8 b1 Q
- Session *theSession = Session::GetSession();* M; {/ N9 [% {) b' h1 q
- Part *workPart(theSession->Parts()->Work());
$ ]1 T# X' P' i0 D" f
( O1 q4 X8 a6 R& S% m3 g- Session::UndoMarkId markId1;6 p: Y* u6 ^8 n6 z F- r$ W* ~
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
2 |$ q* E+ [: q; m1 B - "Studio Spline Thru Points");. |/ w: `3 l: N4 e3 F
3 t# ~7 ?' z) M4 L- Features::StudioSpline *nullFeatures_StudioSpline(NULL);9 [3 |. |) ^* f+ [! d% T3 Y
2 I# g: j% c# b" C" @. J, h( t- Features::StudioSplineBuilder *studioSplineBuilder1;
! e- t, h* b4 h - studioSplineBuilder1 = workPart->Features()->, f$ U( }( a* k/ y1 n6 `4 p
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);, |% ~4 ~/ M1 x q
- studioSplineBuilder1->SetAssociative(true);* i7 P9 z' ]& T+ i/ R5 M7 A- B) g
- studioSplineBuilder1->
6 M4 O& r0 L; H: V5 [ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);$ b( b/ l7 M1 m
- studioSplineBuilder1->
1 @- I, v4 A0 C; q - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 F0 a1 ~ L$ ~! k/ _
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
3 f; K c8 Y7 q! Y% z - studioSplineBuilder1->SetPeriodic(false);
' t+ K: g! T3 b& O - studioSplineBuilder1->
. b {8 A) M+ [! M - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
. _( G7 R! o+ m - std::vector<double> knots1(0);
6 T5 M: E6 ~0 D - studioSplineBuilder1->SetKnots(knots1);3 k% K( R: o$ S* t! n* S
- std::vector<double> parameters1(0);
. M5 X7 I3 u* y; E5 z0 f* Q - studioSplineBuilder1->SetParameters(parameters1);0 w+ ?; D% U: o# Z
- Direction *nullDirection(NULL);) M' a. \+ V$ e5 ^" T) \
- Scalar *nullScalar(NULL);
- o& G! w; X6 s! `1 N - Offset *nullOffset(NULL);
& a. F! [5 {5 T7 ~; I8 d& [
- q9 y [4 J; O1 n/ m9 K; e$ z- std::vector<Features::GeometricConstraintData *>, f( Y6 v. |$ u" H
- geometricConstraintData(thePoints.size());9 j- X" m0 p, T. [7 S/ p2 x: w
- ?6 H, w) @) v$ _# J0 d1 g: [4 ]& c- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 f* e& P: s$ F; T8 A
- {
+ Z& Y9 I- R. W7 k( c4 ~- h - geometricConstraintData[ii] = studioSplineBuilder1->
" }# m" E9 d9 r: k - ConstraintManager()->CreateGeometricConstraintData();* x+ i0 A4 _ {9 S: v7 P1 Q' o
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
( R4 y( a. q9 r7 [) Y - geometricConstraintData[ii]->SetAutomaticConstraintDirection(- d. |. W7 g# ^+ ?; Y4 |% F4 _
- Features::GeometricConstraintData::ParameterDirectionIso);% ^$ a/ g$ k5 |: r7 O
- geometricConstraintData[ii]->SetAutomaticConstraintType(
$ Q4 K4 h0 }2 o4 Z# l/ W - Features::GeometricConstraintData::AutoConstraintTypeNone);# M# L0 C/ U. {+ g
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);5 A8 H& [! W4 @. s( d
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
3 J" \/ l6 q# ]- S3 x7 A! \7 I - geometricConstraintData[ii]->SetCurvature(nullOffset);5 R H) Y" r/ t! L$ [6 n( c
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
9 q& f$ p6 h- ^5 R - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false); F6 I) e4 Z7 R% k7 {
- }
. n. {4 D# _# a3 `+ m2 @ - # Y9 {$ l# U" [0 d s! M
- studioSplineBuilder1->ConstraintManager()->SetContents(
$ ?0 M; y% h) T6 B' B$ T; f - geometricConstraintData);
1 i1 V! O7 b P7 b# s$ A
( s7 c" [# [$ u5 j- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
6 T, g, z R( W* J: C - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();6 F E' B7 w; C+ {
- $ r4 g; r L+ ^, j; ?1 Q
- studioSplineBuilder1->Destroy();' L7 V6 Q: E& N8 u& @! i0 f
- 2 W3 ^7 _7 n+ B8 b+ @
- return theSpline;4 v0 R6 n: {9 ~4 T2 y; Y
- }4 f9 z) r& Z/ x/ l+ J- k4 @
9 K$ {2 ~0 N9 m( F9 @- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
1 W# k" m! m1 a - {
% q8 `8 {7 c* I7 o! e8 o4 W+ w3 ~ - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
2 V; r9 _* `" Z. `! p# s - if (!thePoints.size()) return;" ]2 }) k9 D$ c7 }! a8 t
! o, D7 e P: X3 }5 [) L" F9 R6 J- Spline *theSpline = createStudioSplineThruPoints(thePoints);
' ~5 E6 G( [ L( B+ ? - 2 R: `: m5 g; H0 h6 \' i8 d2 v
- if (theSpline)* G. X0 o" e2 _, e# x/ D
- {
! l6 M$ x8 ?" P9 [! s/ P F' R6 C - theSpline->Highlight();
& _: l1 \2 ?2 H k2 ? - uc1601("Studio Spline Created Thru Points", TRUE);1 y; v T! n: m; t1 k
- theSpline->Unhighlight();: t% W E7 M& d2 v$ b
- }5 u. z# w* z+ v& b
- }4 @0 M) O9 Q' s
- <p> </p>
复制代码
0 {, a$ x' R) m, W) c2 P1 E0 x! o) U- ?' u |
|