|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: b8 X- Y1 |& v$ p' `/ LNX二次开发源码:通过选择点创建样条曲线5 \# N! Q0 f' U$ |. O
8 I) H! R" q7 F6 \
3 q5 o! e: v% v3 n
6 E0 T, Y9 S% I& ~- #include <uf_defs.h>9 L& S( Y4 \+ ?7 C4 b8 i! ?
- #include <uf.h>- k8 _0 T3 Y% d8 h
- #include <uf_modl.h>
9 L ?+ \3 l' b" } - #include <uf_object_types.h>1 p$ j- R8 t5 v3 h1 |
- #include <uf_ui.h>
) R' y @9 ?! \6 y! d7 l - #include <uf_modl.h>* F( C' B* _! c3 {: K. p; Q
- #include <<em>NXOpen</em>/NXException.hxx> |6 O/ C _. q9 N6 n( V0 f+ U' I" m# J
- #include <<em>NXOpen</em>/Session.hxx>
! s( |; u8 Q2 H0 H" I: { - #include <<em>NXOpen</em>/Selection.hxx>
& z0 I/ C* O4 L/ O" A( ~% @ - #include <<em>NXOpen</em>/Builder.hxx>
( V' {+ A( k8 h/ v# ]+ f4 e - #include <<em>NXOpen</em>/Features_Feature.hxx>
; E% o9 X9 X/ t0 m- _9 D2 c" i! w* ^ - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>* `! x V/ v: T" g' X s
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>0 Y" q" _( B- q0 m8 G" q& K2 |7 U
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
) n) A- E: j$ J" [) h - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>9 y b) R& t% B
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>7 @3 Q e; ~4 e
- #include <<em>NXOpen</em>/Part.hxx>
* t! T) ^& c* \. } - #include <<em>NXOpen</em>/ParTCollection.hxx>
/ X9 @3 } s- U* p) v - #include <<em>NXOpen</em>/Point.hxx>
$ H7 W9 z- m6 X" V- H. d' U; ]( N - #include <<em>NXOpen</em>/PointCollection.hxx> E/ E+ R0 f2 s9 x' K) \3 B
- #include <<em>NXOpen</em>/NXString.hxx>
6 }% N9 O1 g/ G0 C& e - #include <<em>NXOpen</em>/UI.hxx>
4 [6 S) v2 d( a; D& R3 s7 u - #include <<em>NXOpen</em>/Spline.hxx>
( _. s' i; O) T8 ~ M - #include <<em>NXOpen</em>/NXObjectManager.hxx>7 K7 k& x5 y- D
; l2 o4 ?# d: t' p2 j- using namespace <em>NXOpen</em>;
' ]( Y( G3 Y( v1 }: u8 l$ J - using namespace std;6 e0 q% u' Z8 E8 x; U
- ' W/ s0 m% P# E; [3 f- S0 E. x+ |/ {
- extern "<em>C</em>" DllExport int ufusr_ask_unload()) x' [# [" f/ _' N6 B9 Q1 }$ X
- {
$ L$ J) `! e" Q; C - return (int)Session::LibraryUnloadOptionImmediately;; U$ S. G4 l' Z, M7 l
- }
2 g5 }: O) ~5 m o- D
# m _- ?3 X8 j/ T, Q2 T; @- static vector<Point *> selectPoints(NXString prompt)
: N4 z- v3 Z, v, L2 Y y& K9 R - {: H7 j; c. I$ S6 P
- UI *ui = UI::GetUI();
, u; q1 c9 U# v7 X4 o! n9 m0 S - Selection *sm = ui->SelectionManager();
9 P/ D$ D% v3 F; |: S% g* ] - std::vector<Selection::MaskTriple> mask(1);
" p$ t, @& E1 Y* S - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ X a% A3 c. g+ @! F- j" ?
- std::vector<NXObject *> objects;; M( n3 P% T9 f% _$ n/ \
* D: V' t' x+ C4 P% O- sm->SelectObjects("Select Points", prompt,
; R+ x: y" {0 j9 [" @4 j - Selection::SelectionScopeAnyInAssembly,
& h, `# v, w6 A: P - Selection::SelectionActionClearAndEnableSpecific,0 N" n% R7 y l" h- U; z9 L# H: R5 N
- false, false, mask, objects);' J. ^* m3 Y4 h7 o; B2 m
0 ^7 p5 | S% d- vector<Point *>selPoints(objects.size());( s+ ]9 g8 |1 M) ~- u
- for (unsigned int ii = 0; ii < objects.size(); ii++)6 s& w% d7 b! l0 P1 X& F( L
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
" j) w# T, a# B( e# K6 U
/ N+ Y6 ]$ F, H X# O$ o- e- return selPoints;0 }7 }3 v/ D. R# |; j) t
- }' [2 k0 A4 k+ A
0 Y+ d( D) Q& e4 {' Q) _( @- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
: k* U& @& p8 u. N* I R5 p - {
1 Q" ^9 C( p" h - Session *theSession = Session::GetSession();, ~" ~) s4 q# }2 ^6 T" R5 g
- Part *workPart(theSession->Parts()->Work());
$ [, m5 F, V" q - - R% C- b+ N% t9 {; O4 w/ M. \+ R
- Session::UndoMarkId markId1;* ?% h& i* u& e% ?" K
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,/ ?) V3 p# o; J5 m
- "Studio Spline Thru Points");
# x# a4 m0 F/ w- B% i0 ?
- A, [( P3 w5 p7 ]7 M: t- Features::StudioSpline *nullFeatures_StudioSpline(NULL);/ V; ?: y' B, ]
- . M. t9 k. L5 C# w2 k! j7 n) [
- Features::StudioSplineBuilder *studioSplineBuilder1;
, F, U: L( W- a6 N+ y - studioSplineBuilder1 = workPart->Features()->! M8 { a& q7 T; D
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
4 U+ t5 U" x" F - studioSplineBuilder1->SetAssociative(true);; V v! |. ^5 @6 G+ a6 w
- studioSplineBuilder1->
7 O8 C( R9 \2 r% s( v" \ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 ^& O* d. Q% X& @7 G
- studioSplineBuilder1->
5 [0 X# y* Q- e- H# O4 L - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
- ^% \8 G% h& u - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
, \: ~: g0 W, v3 Y - studioSplineBuilder1->SetPeriodic(false);
) e/ g; L) r& e9 M - studioSplineBuilder1->3 E4 M1 `6 ~+ j9 c/ ~2 O, z( O5 ~
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ b' b4 v6 h5 Z; U
- std::vector<double> knots1(0);
0 K, n4 q' A. D) D: F - studioSplineBuilder1->SetKnots(knots1);
" U0 L; |( N' F; I/ M* }# G - std::vector<double> parameters1(0);
- |+ z" b- x }% `. }4 { - studioSplineBuilder1->SetParameters(parameters1);6 a7 j$ U& T' I/ o
- Direction *nullDirection(NULL);9 u9 I0 {0 q0 d! C3 S! O" P) n. r
- Scalar *nullScalar(NULL);( K; ~+ p; p- m0 U# n* P$ V
- Offset *nullOffset(NULL);# Z) |# a5 ~" h
7 x: q7 U! G6 q: _; E: u, q- std::vector<Features::GeometricConstraintData *>
- [0 J {( i2 O+ p# g - geometricConstraintData(thePoints.size());
D' R. X# g7 I* T- { P
' n) v% f3 o* E1 W* a& G; r- for (unsigned int ii = 0; ii < thePoints.size(); ii++)2 [7 _0 I8 y# m9 l4 C3 F
- {
; M- ^" R& t5 F - geometricConstraintData[ii] = studioSplineBuilder1->% q7 a) v: ?* n2 q8 P, }# O/ O
- ConstraintManager()->CreateGeometricConstraintData();) [ y& j3 ?8 y8 L1 @
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 h1 Z |$ x: \* _) M
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(. Y! m" W2 X4 {7 `! ^/ N
- Features::GeometricConstraintData::ParameterDirectionIso);
; F. U, ?# `. e+ u4 N( B - geometricConstraintData[ii]->SetAutomaticConstraintType(
7 K8 v1 ^* e& t! {& l - Features::GeometricConstraintData::AutoConstraintTypeNone);
1 U% B( K+ N8 S4 p& `. E) } - geometricConstraintData[ii]->SetTangentDirection(nullDirection);% O$ {1 q ]" _* W' Z5 n" Y
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
1 q" e/ l6 W; @+ T, y - geometricConstraintData[ii]->SetCurvature(nullOffset);( i( U$ {2 H% m9 ]# A( C
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
! M: ?" v3 s- Z) P) o9 {+ r5 j - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
; T* J M g/ P. h% h( K - }
7 }8 h6 M. W+ ~$ c& A P* A5 O/ S; N. ]
* D- y, H# \! O- _6 m. R- h/ `- studioSplineBuilder1->ConstraintManager()->SetContents(# M* ?* v x6 u. |, Q
- geometricConstraintData);
. D* i8 @) u3 b' h4 E( P! J - 0 i$ m7 ?& ]1 R$ ~, X
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
; i9 m8 C) ^6 ~; { - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();& V- S' a# v, x, H$ p
- ( z9 [3 @: O- { G
- studioSplineBuilder1->Destroy();
# ]9 h2 O- o) A1 f: Q
2 r* g) ^- N$ w- ~5 k+ v B/ |, s. F- return theSpline;/ d: B+ R" T1 s& f2 x: b
- }0 \1 x0 z' D9 {2 ^$ m, ?$ j
' [# B3 c" W& U" _- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)0 a3 G! Z* ^0 ?) K) K
- {
% U! \' R# }, q* x# c& S - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
- P% u3 F. v% s3 J, k: b0 v# f7 ^ G& F - if (!thePoints.size()) return;. ~* I9 |! j' q7 t
( G+ q# k9 g- } D- Spline *theSpline = createStudioSplineThruPoints(thePoints);" W: Y/ r. C- V
1 Z& I. i: Z, \+ H9 n- if (theSpline)
, A+ m6 K& T m1 _- | @( o - {
4 B8 u) B+ a5 g' @; m' d - theSpline->Highlight();
, |0 m! Y% ?% H. N - uc1601("Studio Spline Created Thru Points", TRUE);
- ?( n4 f8 [4 ^ - theSpline->Unhighlight();! a& @1 z. r- k+ C
- }" D" W& A, K- H1 K8 |) n) V4 q
- }
+ k" F4 @" f1 F( n. l* X& j/ Z5 P - <p> </p>
复制代码
$ ?) I: p' Z" \. w |
|