|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
' ~2 A8 N# x; _3 z- \4 @' o- #include <uf_defs.h>
* M2 {* _: L( U5 n2 u; B - #include <uf.h>3 d9 t. t5 g v6 N& T6 a g; i
- #include <uf_modl.h># A) k( O" p+ Y8 K( m: \
- #include <uf_object_types.h>
- U- O1 {) h& ~( n: Z - #include <uf_ui.h>
8 i7 ]# O; m0 G) W0 X* q - #include <uf_modl.h>
7 B: W9 R$ I: o7 Q" p - #include <NXOpen/NXException.hxx>
* M8 |4 w: H2 R1 B6 U - #include <NXOpen/Session.hxx>
8 F+ u9 j v) n/ y3 p - #include <NXOpen/Selection.hxx>4 P" m" ~1 k& S$ E* @7 u
- #include <NXOpen/Builder.hxx>
* ~/ L6 ^. C0 I: m3 E - #include <NXOpen/Features_Feature.hxx>* O0 d6 d$ S- z; h) I
- #include <NXOpen/Features_FeatureBuilder.hxx>% h. m% F/ s% v5 L/ ]
- #include <NXOpen/Features_FeatureCollection.hxx>& A5 K. L) H! A& r& c3 t7 M$ I
- #include <NXOpen/Features_GeometricConstraintData.hxx>
1 X5 C1 R" a' \( c( \ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
! t( Z8 E9 k1 u1 ?. z- h! ^ - #include <NXOpen/Features_StudioSplineBuilder.hxx>5 @, v- d/ I' D" [4 C
- #include <NXOpen/Part.hxx>7 |- C. C0 R- s
- #include <NXOpen/ParTCollection.hxx>
) L, ?$ J+ S: H6 _. G0 Q5 [* B+ |. ` - #include <NXOpen/Point.hxx>
; T B# D1 `7 y& ~% I3 F9 T8 d/ r9 m - #include <NXOpen/PointCollection.hxx>
]; V8 M1 U' T( O6 J9 f. G6 Y1 B - #include <NXOpen/NXString.hxx>
3 V$ [, a5 }" J" [6 t2 b* N - #include <NXOpen/UI.hxx>! ?5 r* y+ x# J7 k: g7 [5 r
- #include <NXOpen/Spline.hxx>+ H9 q- x4 ^8 {8 g# u; `
- #include <NXOpen/NXObjectManager.hxx>+ ?" t& Y. Y3 w* N3 t
( Z7 k3 f" I4 m% _- using namespace NXOpen;
: S; }2 n9 ]* j* T+ P y! g - using namespace std;/ Q r9 U C* c- \1 L
* q. o1 P; h$ O3 ?2 ?- extern "C" DllExport int ufusr_ask_unload()
0 b' b9 _+ K0 g) |) s. O - {
5 d1 D" n" l* t* n! X* }6 M' p - return (int)Session::LibraryUnloadOptionImmediately;
: F/ J% _8 ]1 M% X; Y1 x1 `' f - }
0 X+ m4 e" _) n: }8 ]. J' O - - }2 p2 y! D4 C4 P0 P$ }, b
- static vector<Point *> selectPoints(NXString prompt)$ h" I, _4 } `- \2 n/ T
- {' u* |7 ~0 O6 e$ M! q
- UI *ui = UI::GetUI();
- p2 c% i- X( b: u - Selection *sm = ui->SelectionManager();
0 c) t% u# \9 t6 Q6 G0 a- K) W0 A& J5 g - std::vector<Selection::MaskTriple> mask(1);/ @4 f2 t# T. I0 ~
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
4 n( u$ A, T8 x4 D) ~ - std::vector<NXObject *> objects;0 |1 r* q& s* ~
7 j9 q5 ^5 o- B- sm->SelectObjects("Select Points", prompt,4 L4 H) q; w* ?# y t, O0 d
- Selection::SelectionScopeAnyInAssembly,
' h3 C7 m& c i; H, G - Selection::SelectionActionClearAndEnableSpecific,- B9 G0 i- M1 E, R7 Z
- false, false, mask, objects);7 G' S1 `* Z5 Z* G+ ]* @% S" |
$ Z4 a6 {2 ^9 i& R* o+ Z/ S2 ^- vector<Point *>selPoints(objects.size());
8 `7 E9 F% o0 \ - for (unsigned int ii = 0; ii < objects.size(); ii++)
# S; f2 r: T3 p. a5 N& l% { - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ S3 r) g) b; C& G0 r0 b
/ j) n: J$ V# G5 x- return selPoints;
. Q9 O- D! f% g* b' E9 C - }& _' [) }$ K) F& O7 B
; I/ d% o: c4 W# R9 d- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
7 n& _( a5 h, F0 d1 J9 \; `3 U - {* k3 ?- w" d0 L, |
- Session *theSession = Session::GetSession();
1 ~; g; w; n* h- ~# y6 p7 ? - Part *workPart(theSession->Parts()->Work());4 k* a3 {4 {8 a2 v) x
# I/ B( H" Q* L! Q% A- Session::UndoMarkId markId1;6 W7 G- K- I" r; | l5 o, b
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,2 a) X$ S' G- b* |6 \1 o3 s
- "Studio Spline Thru Points");
' h* R. [ w5 ]( n- f4 x
5 ?5 Y4 c4 e* f% n- Features::StudioSpline *nullFeatures_StudioSpline(NULL);: Z3 a3 k" @1 J3 P2 p% P: `
- 6 H# l# a+ ^3 R) H. F# U
- Features::StudioSplineBuilder *studioSplineBuilder1;
7 M* w) V6 C9 U+ e, b - studioSplineBuilder1 = workPart->Features()->) i4 u8 \5 ~( j/ l0 J
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
% u# x9 I+ U; v: y - studioSplineBuilder1->SetAssociative(true);1 {3 e0 } |3 D0 q' J
- studioSplineBuilder1->
* q, H! B6 ^3 m0 q. c - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
9 O8 g1 r: ^8 c& X( P6 H - studioSplineBuilder1->
' z$ {+ @9 n6 [8 ?% w - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
, N! K+ f$ _ D1 N V& @ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
" L/ j. @; T: }4 Y, G. D4 v - studioSplineBuilder1->SetPeriodic(false);/ M$ f, L H6 ]3 Q l
- studioSplineBuilder1->
. b2 a! o/ Q+ n$ K) J+ j6 o# s - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 q: Y# E5 z: `' j4 q
- std::vector<double> knots1(0);
! W1 {! b! y4 h `! v7 ~, C7 J - studioSplineBuilder1->SetKnots(knots1);
; a ^+ F3 {9 @: {; l3 M" T, T - std::vector<double> parameters1(0);
. C: v' M/ O" K# u- B - studioSplineBuilder1->SetParameters(parameters1);
( K* {% N2 U0 h w) Z, _& ]5 z - Direction *nullDirection(NULL);
U- U z7 {0 u8 Q: M& J: s/ {, ]) t - Scalar *nullScalar(NULL);
. {, \ U% D0 W9 t$ N - Offset *nullOffset(NULL);
' \% j. l# p2 S. K - 1 B" P7 B8 D2 L) H* g5 H! H
- std::vector<Features::GeometricConstraintData *>0 q& k" R# Q- N% T2 e# t/ z/ b
- geometricConstraintData(thePoints.size());/ I9 `& j6 s t1 ]$ q9 k
- * L' ^3 Y; v: {1 e. }
- for (unsigned int ii = 0; ii < thePoints.size(); ii++), h# i' M9 P- n: X. Q$ j% Z# G
- {' N6 L! s+ m; U. r/ v
- geometricConstraintData[ii] = studioSplineBuilder1->; E+ B9 h! F/ d6 b* u
- ConstraintManager()->CreateGeometricConstraintData();- _4 o8 H. \( c; r$ R& |/ e
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);% I0 j: F8 `: G+ t3 s
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(! S; ~! I7 ]. O8 B) G$ u1 W
- Features::GeometricConstraintData::ParameterDirectionIso);5 Y1 M Q8 m" s+ A/ |
- geometricConstraintData[ii]->SetAutomaticConstraintType(
: S! w! U) G6 o" c. V* O - Features::GeometricConstraintData::AutoConstraintTypeNone);+ t. R; V" X$ n- ` l8 o
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
+ S4 C( B, M; l - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);2 A% G: m8 `# b) P, c" _# t
- geometricConstraintData[ii]->SetCurvature(nullOffset);7 a7 u$ K# ?) C8 A* X4 }) J l
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
( a! R5 x7 e _4 W - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
1 z, e* S* C6 Y. U' ? - }
) J; [: p, q" ?$ ~- A
4 I9 ~& V: r9 M9 b9 W- studioSplineBuilder1->ConstraintManager()->SetContents(
. r) O. e6 B6 i8 g$ U6 f8 y0 R; j+ n - geometricConstraintData);/ @5 H: e( T( q" c1 a X; Q- E0 n
/ V, T3 p8 m# B X* V; ^5 W- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();# l# u! @& l! \- G& x, {1 ~* m
- Spline *theSpline = studioSplineBuilder1->Curve();
8 i0 F5 W1 e$ W. k: q5 [
/ M7 P$ p* c/ a1 ?$ N: e- studioSplineBuilder1->Destroy();$ A% W4 {- N5 d' V
: b& ?, o6 A* F7 d% k* g- return theSpline;! }2 L9 D) w+ p* W/ P
- }, x7 Y) W2 W. l1 c; D$ t' H( `0 l$ c" Q
- 8 w. H3 n8 ]/ i) L
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len) p& `/ r6 i c0 z$ S1 I
- {
0 s& Q- G) C, T; i; ]: R; ^ - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 h3 \+ K: w- q$ V% \1 j
- if (!thePoints.size()) return;
. M% w& O( z* ` e( ^
- I, F9 ~8 [3 T* B- Spline *theSpline = createStudioSplineThruPoints(thePoints);# l9 g9 u; z$ _4 ^7 l
- 9 U/ e0 d: p3 M. L5 k/ ?+ w
- if (theSpline)+ C9 p/ z; k' ^$ K" |8 C
- {
0 G0 G# r3 a7 m% c - theSpline->Highlight(); a; P$ y; z+ Z5 `7 ]; o$ [3 b
- uc1601("Studio Spline Created Thru Points", TRUE);
' l+ o6 k' P+ g - theSpline->Unhighlight();$ [1 h. j$ y/ _8 ]2 b
- }
9 W8 y; r8 v9 J& \3 f; `$ d - }5 h8 l' X6 V) r: [
复制代码
4 p8 Q. h- v# e+ f: P' F; M/ K9 W- i2 W" {$ P! t( U
/ \* }0 q: ?' `5 q) ` |
|