|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& v9 C: Z: g' o5 c
NX二次开发源码:通过选择点创建样条曲线- i8 q4 g2 F' f# x: x. P3 D
4 U& N2 P2 C! _# j& w9 X+ N6 X& ~& F7 N- ^9 `+ C o% s6 Y
( m( {, G/ c4 c" B1 F1 I/ A3 N- #include <uf_defs.h>
9 y' Z$ d- R" T0 J - #include <uf.h>& V. c4 e3 v6 T- X. M0 [
- #include <uf_modl.h>2 P% W5 v/ ?, w. P1 e, z1 p$ ?
- #include <uf_object_types.h>5 s) h6 f# \! c! |: Q7 w
- #include <uf_ui.h>( U f% E! m [6 {
- #include <uf_modl.h>
+ S/ _6 O+ k3 F0 L/ ? - #include <<em>NXOpen</em>/NXException.hxx>
, A2 y) w( F$ g' h - #include <<em>NXOpen</em>/Session.hxx>
( X8 {1 z, M4 K' P - #include <<em>NXOpen</em>/Selection.hxx>
9 {" z* J" s; @3 ~ - #include <<em>NXOpen</em>/Builder.hxx>
0 s s" [- n/ W+ @+ [ - #include <<em>NXOpen</em>/Features_Feature.hxx>7 ^: L, i3 G' [9 e. @7 }" J2 f
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
4 k& }3 C2 @! {, x/ [& |9 I# c - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>8 B0 q% R1 q7 U! a% z$ N
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>4 }, s' c2 P& h4 F
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
5 f ~$ G; r1 E: I - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
5 z# |7 c4 s+ z3 g/ ~. G' w! p - #include <<em>NXOpen</em>/Part.hxx>
9 m8 W. S+ G/ Z - #include <<em>NXOpen</em>/ParTCollection.hxx>
- O9 L: j `* y* E/ G. y3 ^ - #include <<em>NXOpen</em>/Point.hxx>
+ D Z) v) l& x: g8 J" U9 Q - #include <<em>NXOpen</em>/PointCollection.hxx>! c7 i; S! F0 o& N
- #include <<em>NXOpen</em>/NXString.hxx>, Y8 I# Q1 u2 l. D0 U
- #include <<em>NXOpen</em>/UI.hxx>! Z1 n3 N- `2 S3 J: ?1 n& x
- #include <<em>NXOpen</em>/Spline.hxx>
/ ?6 t" o/ n* `5 }, U - #include <<em>NXOpen</em>/NXObjectManager.hxx>& A) I4 _# n* R. L0 `# J
; d3 I9 y' x5 W) K- using namespace <em>NXOpen</em>;9 N9 L% O9 r" }# K5 a9 f9 U5 u
- using namespace std;9 N, Y+ Q5 q \# u0 }
- 9 n" ^, o* N. s) T g8 A7 L
- extern "<em>C</em>" DllExport int ufusr_ask_unload()) L) W5 o" U0 ^3 }9 d4 `
- {
; x. M& _ x% Y2 J/ P - return (int)Session::LibraryUnloadOptionImmediately;
5 X* s/ d' ~8 N% D - }0 \. Y& t6 M3 Q9 j% F2 M% q
- ; M4 ~ J+ [9 a" I2 r2 e) v$ n* m' d
- static vector<Point *> selectPoints(NXString prompt)3 ^$ u7 B; t- i$ p7 F: Z
- {' _" l% f4 A( P4 @( Q8 U
- UI *ui = UI::GetUI();
6 H. ~# M0 ]$ | - Selection *sm = ui->SelectionManager();5 t; Z8 t# p) \; i, }
- std::vector<Selection::MaskTriple> mask(1);/ \0 _6 j1 A+ R; J' y9 O6 M
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);! j: L$ ?& t9 z. ]% H) _$ f
- std::vector<NXObject *> objects;8 @5 L j9 ~: V7 ~3 _
- * @: O$ m% [0 E4 B/ `* d$ h
- sm->SelectObjects("Select Points", prompt,5 H) ^" d1 Y( N, Q! Z0 O5 I1 U+ t
- Selection::SelectionScopeAnyInAssembly,- ~$ U2 d8 M0 x; ~1 B5 Q( L
- Selection::SelectionActionClearAndEnableSpecific,) c- D2 B; ]! _
- false, false, mask, objects);
3 Z0 S/ N* A/ b+ z- F6 C
( t( u; V' V' m C5 ]- vector<Point *>selPoints(objects.size());0 R8 S- v) A: r4 K& R$ S
- for (unsigned int ii = 0; ii < objects.size(); ii++)
8 }! o, |5 o& k7 }( u" d/ z4 X* e - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
+ ]+ X; F6 I% y6 _( g! w0 d# ^2 w
- y5 e8 S& N2 R- return selPoints;
6 i( U) ] R3 N$ T5 [ - }
# W' W b% f( R& o5 ^) R - % J- B* Z2 t" O
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)/ Z- e: @ J' y0 _" C
- {$ W7 f; w5 j- U# r
- Session *theSession = Session::GetSession();6 g5 Q* O, l; Y# [( T. J( Y# p+ }
- Part *workPart(theSession->Parts()->Work());
9 A* Z% I' H, c& f
) u; y/ e* V- |! Q& U' T- Session::UndoMarkId markId1;
^! d7 C& b& C' p/ |! U: ^ - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
$ ]5 |' S3 y; S+ u - "Studio Spline Thru Points");
: h* n% d; M p& H9 l - 9 a8 ]2 e O% c& _( A+ K4 @/ _
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);' \( s2 X+ Y6 f9 U# c
- X* ]$ U+ A& R
- Features::StudioSplineBuilder *studioSplineBuilder1;& \( m: G8 Y% K8 \, V6 v% `) a
- studioSplineBuilder1 = workPart->Features()->! O5 Y2 P$ w* I
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);5 `$ N/ x6 H& ^5 d0 ^1 S' n
- studioSplineBuilder1->SetAssociative(true);
; u$ l' P. j* D - studioSplineBuilder1->3 t4 V; t4 F2 N. t- o! _7 u
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
9 w% C& m, \, P' q9 S - studioSplineBuilder1->5 A$ r- k, C9 a4 a. \6 O( v
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);! s- U2 M$ A6 C/ B( J) V8 q( u
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
% f( ?. U. n6 l4 R2 l# u% T - studioSplineBuilder1->SetPeriodic(false);! N @) {( c4 j/ m
- studioSplineBuilder1->
& v. ?! U, N' V' g" G - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 l$ H6 S2 ?, L% ^$ u! O
- std::vector<double> knots1(0);+ z& n. @, V8 a
- studioSplineBuilder1->SetKnots(knots1);, e2 b2 z+ K" ~# |0 F# {4 O
- std::vector<double> parameters1(0);1 ^9 v6 n) L. x% s. @
- studioSplineBuilder1->SetParameters(parameters1);8 d4 y7 m7 P5 w$ ^ H' E
- Direction *nullDirection(NULL);
( O' }+ O) [# U, b% }1 q# T - Scalar *nullScalar(NULL);
( V- |( o3 b: v/ i% Q8 B - Offset *nullOffset(NULL);8 C$ s5 C, P$ c7 v) ^! L7 U) v
- 6 Z0 _% q" f. F/ A! S2 X
- std::vector<Features::GeometricConstraintData *>
- T& |; d5 C( n - geometricConstraintData(thePoints.size());
0 E* |% f2 X* l$ P - ! D g' q4 R% T
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)# s% _1 S c$ J
- {. K* F) Q0 X2 E) W h
- geometricConstraintData[ii] = studioSplineBuilder1->
( g6 F; R& f7 n - ConstraintManager()->CreateGeometricConstraintData();
2 k4 D$ ? d8 D4 @# ^* A - geometricConstraintData[ii]->SetPoint(thePoints[ii]);2 j: ]- @ U3 T) C, V
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
7 D- u) t9 F+ P' M; j3 f- i/ }6 f - Features::GeometricConstraintData::ParameterDirectionIso);
! O9 w6 e) {. C5 b- {" o6 t - geometricConstraintData[ii]->SetAutomaticConstraintType(
# k- R" P2 A7 C+ |4 D9 A( d4 o8 c% m- e - Features::GeometricConstraintData::AutoConstraintTypeNone);4 P. M& O% a& ~6 L# |: i9 W
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);* d- V) K2 P7 g$ S4 G# f* O) A% B
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
) F$ B) H6 g# u% `2 c& @ - geometricConstraintData[ii]->SetCurvature(nullOffset);- a' N) c& {3 A! S/ i7 ~ X
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);# f2 [* H& o8 o* @: P
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
0 @: D2 q: Z" t8 C, N: m - }
/ F: f2 c# j6 g+ m
8 _8 q8 @+ l; I" l* D; H# y- studioSplineBuilder1->ConstraintManager()->SetContents( B" J) N9 Z# _" ~
- geometricConstraintData);5 O) O8 A& Z/ ]% c7 R% p
/ A) S( g3 p$ S3 |6 M2 j' x- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();' d$ D1 t4 R" Z/ v! N5 B o& H3 b6 ^& `
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
- K2 }0 c3 J" f9 R$ L) O+ I5 ^" c - " @- i* t) G* V4 d7 ?
- studioSplineBuilder1->Destroy();9 m$ `' [; R" d* ?; t$ b
) Q! I, s m; D9 O0 c- return theSpline;$ p5 Q# y9 d; ^
- }
+ w& D3 B3 o5 ?& M7 N$ v# S - ! B& `: T; C3 H- A% O& J
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
9 P3 A: S8 ?" ]$ ^1 | - {
. A( A+ G+ h( o - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" m, O% D( F$ T) D4 K9 W
- if (!thePoints.size()) return;* e. {' i% Z7 ^1 s# K3 {7 `/ w
6 D; q6 p$ J( q- Spline *theSpline = createStudioSplineThruPoints(thePoints);
. {9 W6 ^: v0 B! ]" R
/ c" |, X1 \8 C; R1 z- if (theSpline)
/ h: p }0 W3 D; R" Y5 S8 Z - {
/ s: {5 w, h' k! y" _ - theSpline->Highlight();+ h0 v8 {" b& e# w3 B: V
- uc1601("Studio Spline Created Thru Points", TRUE);' t, J/ p. B5 @6 f) k- S( f
- theSpline->Unhighlight();
6 L5 d5 u! D p* [. x7 y - }
- Z/ m7 \. l; G" Z - }, X0 {; _/ B% ^- d" d* \& C
- <p> </p>
复制代码 ( e; i* M2 E) @
|
|