|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
8 o+ j* S- ^+ \8 Z4 ^$ P- #include <uf_defs.h>4 D" }1 V7 ]+ [# A. V" {* ?
- #include <uf.h>
2 N; E9 {5 m! I8 Q( Y - #include <uf_modl.h>
3 }2 C. v; G" X$ @) G - #include <uf_object_types.h>
" l) q" H. _4 _0 } - #include <uf_ui.h>! c" \1 {5 T1 B
- #include <uf_modl.h>. k) c) L7 g, I) |8 Z
- #include <NXOpen/NXException.hxx>
, n& B j0 `8 ?$ l$ h0 ] - #include <NXOpen/Session.hxx>
2 V6 l$ I7 t& B1 X- S3 D4 z5 z - #include <NXOpen/Selection.hxx>
H8 s+ Q! h v - #include <NXOpen/Builder.hxx>
# }8 B# |2 Q2 C0 c- y - #include <NXOpen/Features_Feature.hxx>
" w3 e" W! F5 i/ h# n9 i - #include <NXOpen/Features_FeatureBuilder.hxx>
7 b5 k; Z! K8 h- P: K1 ? - #include <NXOpen/Features_FeatureCollection.hxx>
, f7 O; I* v9 u8 C' X9 F - #include <NXOpen/Features_GeometricConstraintData.hxx>9 U( Z7 p0 N* A7 \6 \9 g7 @; t& N
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>+ k! c' t( J: i( O: A& s
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
1 V: L) _- E2 L! r - #include <NXOpen/Part.hxx>
0 J. [) W0 l; W* l3 y0 T+ L - #include <NXOpen/ParTCollection.hxx>7 N8 c8 b$ N) v
- #include <NXOpen/Point.hxx>
6 s1 N& `9 ?' ^, C* o9 h - #include <NXOpen/PointCollection.hxx>
. v& v7 H' S, t, K - #include <NXOpen/NXString.hxx>( [3 q+ ~" y m* z) x
- #include <NXOpen/UI.hxx>
* {- ^- C" @4 ~ - #include <NXOpen/Spline.hxx>& [6 `+ {/ b! ~" U! D
- #include <NXOpen/NXObjectManager.hxx>
* J \) N8 R& g" s( k3 C: T$ i
/ |) G0 @7 N% ~5 C" u- using namespace NXOpen;: Q, {& k6 \$ M) M
- using namespace std;
: z! g% r8 }/ H# v- y5 F1 }$ a - : Q2 @% \! V' s+ `0 E H
- extern "C" DllExport int ufusr_ask_unload()& C9 S% p3 ~) y. l# j1 e T! s# [
- {- l9 D: E& E* Q: z$ n
- return (int)Session::LibraryUnloadOptionImmediately;
' Y, A0 [5 _! B1 z8 u/ ~, Y - }
" [$ H4 K+ O; v E - 6 v, O" U% E; E4 S5 s' ^" J8 u
- static vector<Point *> selectPoints(NXString prompt)9 D, _ f8 S0 {7 ^% m& s
- {9 t* \ q6 C1 s2 M5 ] G+ {
- UI *ui = UI::GetUI();7 s: s. y$ W( x
- Selection *sm = ui->SelectionManager();
& Y1 c# V$ Y/ Q, A - std::vector<Selection::MaskTriple> mask(1);
; t9 N# V0 p+ L R# _( W0 q% F& D - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" V1 q# M& ` B" I! u; b- u
- std::vector<NXObject *> objects;2 c j6 X7 h& d) S' E/ v7 u3 M
- 4 h' L" M" z) F) J% @
- sm->SelectObjects("Select Points", prompt," V! J+ H* f$ _0 i* r
- Selection::SelectionScopeAnyInAssembly,5 E+ `5 j, ]& u; a. R' y. f+ G
- Selection::SelectionActionClearAndEnableSpecific,
3 x' f5 [/ S% n7 q! L8 B# H - false, false, mask, objects);: i! A' B5 {& H5 }9 o
8 K$ m9 i7 _& s |- vector<Point *>selPoints(objects.size());
* g( R1 K) a" I0 U0 y( y# n7 u, U- @ - for (unsigned int ii = 0; ii < objects.size(); ii++); S; I) z# X& q, N8 {% B
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
5 t! c% R) \, [/ z0 d) F( p - $ l1 p' @3 e: z* s7 l& U r
- return selPoints;7 m8 t) |) l# Z; e+ A
- }9 }; A. ~6 h C+ m2 \2 o
- , M( K' i' ~3 a* w" z
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
9 W1 R. `+ z, V* e8 G - {
1 z. y4 x) e; o9 i3 V - Session *theSession = Session::GetSession();7 d. _, E3 S# Y2 {
- Part *workPart(theSession->Parts()->Work());
2 J, V6 v4 P" m" ], x - & b6 D' C8 L( | M" f7 W
- Session::UndoMarkId markId1; s; Y9 v% b" x" R6 u6 j+ o; u2 W
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& w/ Y4 I& i* o1 f) I; r% ?$ D
- "Studio Spline Thru Points");3 a' X7 c3 Y) w0 k4 i8 L4 ]
3 k% A) [1 a1 f, G- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
- z* M* h3 n n h( E7 O6 R9 ], G- w
{0 C& b1 C; s# D- Features::StudioSplineBuilder *studioSplineBuilder1;; e! F( X) r' J5 P, Q) L
- studioSplineBuilder1 = workPart->Features()->
; S. s* W1 n8 m9 o$ @& ? - CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 C, b t3 J. S# k! m
- studioSplineBuilder1->SetAssociative(true);! `6 @7 Z" R! ^# ^
- studioSplineBuilder1->; a9 |* b, u1 W. \/ O6 R& X& t8 y
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);) T% S& E3 E% S) \4 l# W8 N& _! W# }. P
- studioSplineBuilder1->
* Y4 d& j2 }/ g" P+ y3 J5 i/ @" d4 | - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
! p$ d N2 l9 P T) `/ N! [ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; M9 G# |& C+ B- ]
- studioSplineBuilder1->SetPeriodic(false);" P. x: J0 X2 J( G1 i- q
- studioSplineBuilder1->
8 y @7 y7 P% ^/ K" \; o& o - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);7 N! p$ [) g# c" u, l
- std::vector<double> knots1(0);
5 N- p' ]4 h) }+ s' O; G! T - studioSplineBuilder1->SetKnots(knots1);3 }8 U( w8 H5 [. P: `) s$ A: ^
- std::vector<double> parameters1(0);: K- o' q0 \3 `" p
- studioSplineBuilder1->SetParameters(parameters1);0 N/ `8 K/ K1 O8 s6 V
- Direction *nullDirection(NULL);4 t8 b+ \, ], _; Y/ g
- Scalar *nullScalar(NULL);
' l& Q# R$ i( S# Y: a% ~ - Offset *nullOffset(NULL);
% g1 b. }7 @, b1 p" }" ?( c2 K4 w1 y - & Y. m: L; @+ y$ E; q
- std::vector<Features::GeometricConstraintData *>, [" B P7 l. k( v; X& f7 y
- geometricConstraintData(thePoints.size());
( j% r- Y( d) D8 ~ J8 v - 4 W8 H7 n# T# o6 _4 n9 `
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)! o& D/ r7 k3 ~5 y# @! X+ N
- {
" | [9 `& I+ @+ j: p ^5 w; C - geometricConstraintData[ii] = studioSplineBuilder1->
% Q9 s/ I! n% R - ConstraintManager()->CreateGeometricConstraintData();
0 k/ t4 w% n) X- `& x - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
( X/ }6 d! _$ G' Y2 d3 d f - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
7 W) a4 V! O. \( f) V - Features::GeometricConstraintData::ParameterDirectionIso);
! {+ N" |9 Y9 C: m - geometricConstraintData[ii]->SetAutomaticConstraintType($ z4 A& m5 V2 S/ u
- Features::GeometricConstraintData::AutoConstraintTypeNone);
$ d3 w2 v3 _+ p0 n - geometricConstraintData[ii]->SetTangentDirection(nullDirection); S! `/ P" {$ }
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);; N$ Q9 R- I+ d
- geometricConstraintData[ii]->SetCurvature(nullOffset);) Q! {" w* i" \- [- h& q' {' O
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
2 g. t6 q6 i' _7 F9 _/ z9 u - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);9 H3 ^' M* Z: o1 U; T
- }% V5 Z& K7 S. e
- % T' y& z0 _$ I1 b2 X2 E+ i' Y' C. O
- studioSplineBuilder1->ConstraintManager()->SetContents(2 ?/ h _2 I2 I7 e U
- geometricConstraintData);5 r1 S* J' g$ T! }
) V+ W* P7 g I y+ O2 E; k- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ T. M9 _: H/ M2 |" c
- Spline *theSpline = studioSplineBuilder1->Curve();
4 X8 A1 j4 ?( e: J
! A; s- p! a0 t* R0 S- studioSplineBuilder1->Destroy();
; S1 w1 n% M2 b0 y* y2 _ - ; l+ d$ J$ I4 ~( r$ z, X. \8 c
- return theSpline;# M) k3 r, {! B' y( Q
- }" w7 E* P- j6 E* W. g( L/ _
; }" Z4 C7 f0 C/ ^2 Z1 `1 B- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
: Q6 t3 f' q1 P _. H' j; ` - {/ E: b$ A: y! k1 O4 y H0 G
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& T& G1 Q) |" n) t
- if (!thePoints.size()) return;
. B& G0 q6 {2 L/ d+ `7 Q p
4 P$ H( K) Z) g3 @- Spline *theSpline = createStudioSplineThruPoints(thePoints);
! y7 s5 N- d. l4 d7 I9 u
, {# I0 W( L6 ]8 {- if (theSpline)
3 R. l- p5 x* `: v - {
- k4 N& e- A* U7 | - theSpline->Highlight();+ B; D. P& A2 X; k& K# ]
- uc1601("Studio Spline Created Thru Points", TRUE);2 D" c& ]7 U$ _% l, u- e. ]( u
- theSpline->Unhighlight();
: l# ]; D; U" y - }+ I% @. y% P% F4 Y% G
- }' a) x: k( N% ?) G; x9 f+ t2 R. |- P
复制代码 1 h7 |' P" B5 `2 j1 h
8 q1 E" h! O% _$ x3 n2 E$ B i l3 I
|
|