|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
% S7 Y5 Y$ b: T; n5 }) _; G4 R8 HNX二次开发源码:通过选择点创建样条曲线
+ k j% \) O3 q
9 D, p/ {7 o8 {( O+ _' G: A; Q! s6 h/ k& o0 a5 K. J
- $ x0 D. c' l! v" r. W
- #include <uf_defs.h>' q7 X- Q4 t0 }1 }( u# @3 H3 M2 ~
- #include <uf.h>: \) c7 x7 z, M* `/ ~0 n
- #include <uf_modl.h>
; Z/ `, k; e( Z, Y6 |2 h& O - #include <uf_object_types.h>" l# ?3 a6 c1 r
- #include <uf_ui.h>
7 T, Y! E9 [5 v0 \. [4 e8 b5 m - #include <uf_modl.h>
* J. {( e. v& o$ V% _) z - #include <<em>NXOpen</em>/NXException.hxx>
! q& ?0 s" ^1 B1 r# G' E - #include <<em>NXOpen</em>/Session.hxx>8 t0 _: U' w# n
- #include <<em>NXOpen</em>/Selection.hxx>, I6 c0 C5 q+ T- m) g, R% ?
- #include <<em>NXOpen</em>/Builder.hxx>
, e8 }$ V2 b5 ?6 q) y - #include <<em>NXOpen</em>/Features_Feature.hxx>
! Z2 j3 g, G8 Y8 ~6 O; f - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>$ I4 c) O O f3 C0 G
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>; S( p9 _% r4 ]# O" e1 R
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
2 D& X3 A6 K% U& ^# j2 C1 l - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>+ b# t8 a. ~ ~' J. E: P, h6 g
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
; ~3 K1 @$ b5 t u& p0 ~ - #include <<em>NXOpen</em>/Part.hxx>& H/ s, D" a+ d- ?5 [: S; f
- #include <<em>NXOpen</em>/ParTCollection.hxx>
) ~ P% D8 \0 M* K - #include <<em>NXOpen</em>/Point.hxx>
7 L5 V( I! R. I' i3 H; Q* T - #include <<em>NXOpen</em>/PointCollection.hxx> B! S1 S; U6 d* Z; K; h7 h
- #include <<em>NXOpen</em>/NXString.hxx>
: l6 r7 }0 n) P2 X# X1 w5 T m+ l; s - #include <<em>NXOpen</em>/UI.hxx>% b6 Y& K0 J- j" C) B/ ]$ n
- #include <<em>NXOpen</em>/Spline.hxx>
) D, U: z' }. H& f8 n - #include <<em>NXOpen</em>/NXObjectManager.hxx>$ i6 {% d( P: Y$ a! E9 Z
8 i0 Y5 r- x$ f1 }- using namespace <em>NXOpen</em>;
+ p8 x% `/ S. j' [ - using namespace std;
! h6 `5 C$ O8 V t0 M$ U6 o - + d2 \# p) L: ^, v) ~# j
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
2 H- x I) b' G: e' Z7 S - {
' a0 Q$ W& N% s6 n% o - return (int)Session::LibraryUnloadOptionImmediately;
4 G& Z. _' D+ o0 h; ^ - }" h" X1 s+ r: W! f) x, B
- " b; |( Q6 q* B
- static vector<Point *> selectPoints(NXString prompt)0 L8 N7 i+ D# l& `& a+ Z& P( Y; k
- {
+ M) m" o" p+ X9 c2 ], I/ g, d - UI *ui = UI::GetUI(); C, g2 _7 x4 \1 s9 {0 ^
- Selection *sm = ui->SelectionManager();
) {0 n6 X5 Y9 N) F. s1 e - std::vector<Selection::MaskTriple> mask(1);( h2 g; P* d! j# p r
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
E |# G0 `( d/ J3 ~/ L9 O8 j0 G - std::vector<NXObject *> objects;* l ^0 S" s5 {; C8 K8 i. D" h
: O/ ~# _' ~% W9 t- sm->SelectObjects("Select Points", prompt,1 b) z. I! v/ Q) G F
- Selection::SelectionScopeAnyInAssembly,$ L8 C3 x+ ~# K) U0 r) u& ?* m% w
- Selection::SelectionActionClearAndEnableSpecific,
1 |; O: a# J! n, W$ K1 Y" ] - false, false, mask, objects);' j! e+ N% r! R' u* N
- 5 D! o A% o q8 U0 n \- ^5 ?
- vector<Point *>selPoints(objects.size());) L. k' u' k2 ?
- for (unsigned int ii = 0; ii < objects.size(); ii++)3 d" d7 h# J+ B3 u
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
- O3 Z+ X. w4 K* ~7 B - J$ [* {9 g" B3 K
- return selPoints;# R: p' U; V- e6 l. C& d
- }
$ X0 z. y+ Y& Q5 y - / p( s) C& e% k0 q2 q( }! r
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints); s2 p3 }' G8 k5 e' c
- {& R* Q& a7 i% ?, i! Y( |0 r& q D
- Session *theSession = Session::GetSession();
; L2 x, i y6 c. y" M - Part *workPart(theSession->Parts()->Work());1 D% Y2 `+ J6 {' y
- 0 N* w9 J* p9 |4 I; a& @
- Session::UndoMarkId markId1;0 D# e0 D7 n3 Q# H1 n" z1 A# I
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
0 N2 e- p' ?% N# T - "Studio Spline Thru Points");
, t2 Z& o, @0 r - . P9 o$ p. }6 M) T) J
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);! W2 Z9 X0 D( B$ }) l7 R4 D1 ]7 j& m
- ' s' b$ B9 \5 E A- L- Y
- Features::StudioSplineBuilder *studioSplineBuilder1;) l9 u" T& H* ]/ r3 ]6 P8 t7 H
- studioSplineBuilder1 = workPart->Features()->, S; A* U. _0 n' q4 ]0 T
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);& p' Q* \" f2 o% A& K
- studioSplineBuilder1->SetAssociative(true);
. }6 t E( R8 {8 F3 {$ K7 b) L$ i - studioSplineBuilder1->; g3 Y! E+ C1 N6 o
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
' k. ~, L: x; y0 s0 ^2 q - studioSplineBuilder1->
5 W: b) B4 l' e* ?7 s" m& V. x - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
+ ?: A' ]5 `6 w. ]5 x+ e! K, g - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);' y: s% I7 Y0 J5 @3 u' s
- studioSplineBuilder1->SetPeriodic(false);
2 l* D' I! ~& V; x+ u/ `* m( R: I - studioSplineBuilder1->
) k9 y' e0 Y; {9 c+ k - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
2 u c/ |9 G( N5 J - std::vector<double> knots1(0);5 h- b$ |7 i( D( G: h! u6 {2 u7 {
- studioSplineBuilder1->SetKnots(knots1);$ j' p" y/ x" S9 C! `0 h& F5 T
- std::vector<double> parameters1(0);
, b: {0 I0 n9 i+ ~. y! ]" y - studioSplineBuilder1->SetParameters(parameters1);
) S5 j, C* r/ a - Direction *nullDirection(NULL);0 M" X G& L, i" _
- Scalar *nullScalar(NULL);( A- f. X4 T% U4 l
- Offset *nullOffset(NULL);
) a5 W& q: i$ K6 R" \; j - ' d9 B; D) ^$ X
- std::vector<Features::GeometricConstraintData *>$ h* M& Y+ \9 K1 @% a. Q
- geometricConstraintData(thePoints.size()); J( T( k! F: g# G8 |( W2 M- o/ u
- 4 D3 i3 q' R7 ^ z# L; _' A4 d& h( J
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ H+ [, R7 A( [
- {1 ?3 A7 {' t+ e" Z# B. P
- geometricConstraintData[ii] = studioSplineBuilder1->
3 P6 W0 C; W9 l& F0 y& g - ConstraintManager()->CreateGeometricConstraintData();
% e0 J/ k# s1 c - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
4 z0 g8 y% E7 Q+ Q* I% n - geometricConstraintData[ii]->SetAutomaticConstraintDirection(6 O5 O3 l0 A4 d+ @ ?
- Features::GeometricConstraintData::ParameterDirectionIso);% N3 U# n6 v' [- g! L/ `
- geometricConstraintData[ii]->SetAutomaticConstraintType(" w) {: K" C0 f
- Features::GeometricConstraintData::AutoConstraintTypeNone);" M! q) S3 S% B+ {0 p4 z
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);* G* ?" @8 j& f" l' p/ P
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);) s# Y6 Y2 \3 t/ c% ~8 v) |
- geometricConstraintData[ii]->SetCurvature(nullOffset);* \; v, p' G6 o
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
( [/ T+ C. I8 j6 g2 K5 d0 J - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);. I% Z$ w% k* P8 }6 i; i
- }! @9 p" K! }/ Q
0 f, x0 O3 E# b; Q7 X) I5 h7 n- studioSplineBuilder1->ConstraintManager()->SetContents(' S1 ~% U2 U, v. f/ V
- geometricConstraintData);8 U5 V" G2 U# U( o
- 4 ]: Z& Q1 ~2 t2 n% |8 ?8 X
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
9 \) e: w+ a1 R: G - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();. o" ~+ m* m1 x
1 J4 P& }0 L. {/ w- studioSplineBuilder1->Destroy();0 |) o: x% F1 E. x) s$ b$ z
- 7 a) @- q r5 r
- return theSpline;, ^ l: U9 K% e( b4 Q5 ~/ A! t! c
- }) j- A, N2 y, j8 j
6 d3 E" D0 C# g& n( h$ y- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
4 U5 z# Z) @- B# o' |* N: h - {
7 M8 w6 q1 d4 G+ p' g: F. R - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");4 p; h2 B* Z% y! f9 w
- if (!thePoints.size()) return;* u2 a( X# k3 `; S& E2 s
2 [) ~0 L2 t Q! f! t- Spline *theSpline = createStudioSplineThruPoints(thePoints);
/ j) p; u6 y& D - 4 M7 X/ s3 A0 T$ E; V$ [
- if (theSpline). Z' z8 v p& w4 i/ B) H
- {) r6 w u R3 r) P- y
- theSpline->Highlight();* F1 [/ x8 o8 Y l8 r1 F" K+ ?
- uc1601("Studio Spline Created Thru Points", TRUE);
# s4 m6 y" Q& {5 X0 z( M - theSpline->Unhighlight();
) q# ]5 j' {) ~+ d7 @ - }- i5 H* V/ b$ @
- }3 F6 t9 N: X3 x( L, G
- <p> </p>
复制代码
+ [8 N5 a @' t- C f5 a! c |
|