|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
7 Z. Q+ C1 f) l( q+ O, e. a7 tNX二次开发源码:通过选择点创建样条曲线* r$ c0 l8 G+ F3 X
2 C" e- p8 u& K$ E6 |
! T4 \5 X8 N; f l! P- % u) e/ g: o7 X, g) K! e* y) J: f
- #include <uf_defs.h>
* K$ s& c2 k9 m) `% q - #include <uf.h>( }/ l& |% W, }. [4 ~
- #include <uf_modl.h>
0 l- S- f& M$ c0 K# m j$ U - #include <uf_object_types.h>* G, c: W" `$ x+ e+ y3 I
- #include <uf_ui.h>
* F( q1 F4 s8 D2 r - #include <uf_modl.h>
7 r+ T }: m+ m9 I - #include <<em>NXOpen</em>/NXException.hxx>
. ]; _: I+ e8 G - #include <<em>NXOpen</em>/Session.hxx>
( {" U( U: G7 p5 a8 N& f, s) m3 g0 d - #include <<em>NXOpen</em>/Selection.hxx>
; x; g& X: u9 r+ ]8 { - #include <<em>NXOpen</em>/Builder.hxx>; p. Q: G% o( O# W8 X; B: y6 P
- #include <<em>NXOpen</em>/Features_Feature.hxx>
+ H# v; M' T) [$ }7 J# ? - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>4 C% h. R c! }7 ^
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>3 j+ I2 R. R" ^
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
( g* k1 W1 a# O - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>, P9 }: R9 r3 L
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
8 P2 [( J0 t% S' ?: p4 U$ i T - #include <<em>NXOpen</em>/Part.hxx>
, g5 ] t- m: | - #include <<em>NXOpen</em>/ParTCollection.hxx>
6 p5 [8 b+ T5 u6 n9 q* N$ F# Z$ W - #include <<em>NXOpen</em>/Point.hxx> c: g6 m9 t: W- i
- #include <<em>NXOpen</em>/PointCollection.hxx>
# A3 d5 H' I7 R7 j$ Q8 m - #include <<em>NXOpen</em>/NXString.hxx>! a9 Z+ Q% i; R0 ?# T5 E( k( `
- #include <<em>NXOpen</em>/UI.hxx># `* S/ h4 q: B" b; }8 G3 J) A, n
- #include <<em>NXOpen</em>/Spline.hxx>3 X5 N& o, }3 [ C* A% u) X
- #include <<em>NXOpen</em>/NXObjectManager.hxx>) ~: a4 p8 u- q$ H2 W |% A% M
- ' `5 Y0 c2 I2 ^ f' `. a
- using namespace <em>NXOpen</em>;
/ C6 _1 ~3 f+ m: C8 L( c. o - using namespace std;7 W9 S |. _, ?5 h7 ]5 v. I& i3 C
, U4 h7 V# E C+ t. H4 v4 X2 W3 A' S- extern "<em>C</em>" DllExport int ufusr_ask_unload()* s( G( s5 w8 b" S3 j
- {
) ^5 V, p8 X. z; k% P/ i& B1 L4 m6 y - return (int)Session::LibraryUnloadOptionImmediately;* `, T+ W0 o( m4 E$ u
- }
! v4 b3 ~' @7 T/ A1 | - / W5 X3 `( X# A+ Z( h
- static vector<Point *> selectPoints(NXString prompt)% r; B7 A v" I# k# L$ ~
- {
( }: F5 M$ U* h8 H+ U" R0 V4 P - UI *ui = UI::GetUI();( q+ ?" o8 s3 }
- Selection *sm = ui->SelectionManager();
( `* ^5 z" k* G! `+ ? - std::vector<Selection::MaskTriple> mask(1);
; c- p1 D# V x! Y9 j. z: |. @ - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);) ^2 N- K) Q0 K8 n( \. S
- std::vector<NXObject *> objects;, G( @! E) f9 y/ o, u S
- / s1 h: [0 c9 x9 d4 H; G: @1 o
- sm->SelectObjects("Select Points", prompt,% M, Y* E$ G% ]- h$ X7 V6 D
- Selection::SelectionScopeAnyInAssembly,
) A+ J5 p, {* {+ Y: w' X - Selection::SelectionActionClearAndEnableSpecific,- x) I r. J- {3 ^: W
- false, false, mask, objects);
D( h' a* j) H# Z, Z2 J& P - 9 Z6 X- X# I6 G5 B
- vector<Point *>selPoints(objects.size());$ d$ S) ^2 q4 {
- for (unsigned int ii = 0; ii < objects.size(); ii++)5 P& c3 ^! t5 s; V8 f6 g
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
" @& R9 r* p9 S# ?6 E
) q1 `1 m" p; @6 y, B- return selPoints;/ F7 W+ a1 x; F! i* M6 t
- }# k# F. a5 ]8 T+ @' \0 m( n
- + j6 i4 B- ^) W/ B
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
9 g, H9 c' u7 ` - {
; G. t, T* C5 e3 d% O+ ` - Session *theSession = Session::GetSession();6 A& Q6 F* O- w4 ~% Q/ T
- Part *workPart(theSession->Parts()->Work());
) _- \/ p E+ ~$ j# {6 ?8 V y" |4 C' O
0 g" C [ H+ |) t, h+ M) \; s+ S* x) p- Session::UndoMarkId markId1;
, B: {3 O. i: y$ j2 ] - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
5 F! l- b6 T& N" |) M. f: b6 { - "Studio Spline Thru Points");2 P: Q# T: f" f
, O* R+ e& J, f. H$ K! i; C: I6 o- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
1 c& P# ]4 x6 `2 U- {" s) A
) V6 H4 f s [1 a- Features::StudioSplineBuilder *studioSplineBuilder1;
4 G+ W5 }* c+ K# u/ @ - studioSplineBuilder1 = workPart->Features()->$ w8 X, M; u1 F ?) g
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
6 R, j4 }# U5 o( |! w7 D Q+ n2 F - studioSplineBuilder1->SetAssociative(true);
# G+ n. |) I9 S' Z1 |( {& [ - studioSplineBuilder1->7 d7 j* Q9 y8 F/ ]7 o
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);6 `/ V W$ K2 d& C& Y
- studioSplineBuilder1->
$ @" e* Z; Q R2 {2 m8 l - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
) [0 c* Z( h9 g) |) U4 g9 m - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);6 I/ k9 R2 t, H4 X( y+ Q
- studioSplineBuilder1->SetPeriodic(false);
. p/ Z% n* z: G - studioSplineBuilder1->$ G2 R: M. T: t& ~8 K: z* n' c- g5 z
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
7 B# v" {/ u% [" e& O1 B# K - std::vector<double> knots1(0);% i ?2 F& ^+ S7 W+ a
- studioSplineBuilder1->SetKnots(knots1);
* Q# }$ x( n# k( D. _ - std::vector<double> parameters1(0);( m, w( o6 ]( p( N- Z8 M$ C
- studioSplineBuilder1->SetParameters(parameters1);
8 R1 Y7 R( u0 D5 ~ K* e1 a- e - Direction *nullDirection(NULL);- O7 c) ^0 a; N& N6 z" F' ^: T
- Scalar *nullScalar(NULL);
7 p: v; o$ r* B8 k - Offset *nullOffset(NULL);( p/ i: O# d- J; A; @0 z
, f: h6 O' B) |3 u/ r6 t' ?- std::vector<Features::GeometricConstraintData *>
5 @+ @) F; Z5 b6 Y - geometricConstraintData(thePoints.size());. P5 E7 K9 e$ k
- ; j) d, A) Y! ~) R6 q% M' v5 x& @
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ N a& ]+ |- D8 l/ G2 ~7 {* [
- {
; _. K$ O4 j' ~& s3 X) e+ }$ e - geometricConstraintData[ii] = studioSplineBuilder1-> f- x- R! l# b8 S$ ^% c+ h/ @
- ConstraintManager()->CreateGeometricConstraintData();' [. t `5 R! t& q. }$ g
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);" U$ Q, Q- c* q- y5 `: T. K
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
! c* }. u/ Q# \ - Features::GeometricConstraintData::ParameterDirectionIso);
, W* b9 T) P( f, @, u5 C - geometricConstraintData[ii]->SetAutomaticConstraintType($ Y* B, }4 |! i
- Features::GeometricConstraintData::AutoConstraintTypeNone);& Z6 f: t) x$ c6 l6 S
- geometricConstraintData[ii]->SetTangentDirection(nullDirection); ~ n2 A! P4 x2 i ^9 R) K V- N
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
% f, a# Y8 s( G+ u - geometricConstraintData[ii]->SetCurvature(nullOffset);
! [" ?7 Y6 [- N8 E% P, e {) E' c& p - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);1 |- o* Y% s! H& C
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
" @# @5 ~! M7 K8 Q% S' J3 L+ e - }
, Z' M2 g+ U# ?- P7 S. U
" P. R0 E* p; }2 e- studioSplineBuilder1->ConstraintManager()->SetContents(
: y5 a+ e+ z' F4 o - geometricConstraintData);
. i# S( z$ Q1 v' k
3 n" w$ Q- B. @! O- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
. y) E. S( C: L: P8 G9 M - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();* F. ?$ f8 L6 o) c: f
1 W S R* h& m% F8 L- studioSplineBuilder1->Destroy();
9 S0 `# ], @! E0 M& P( T
! Z! X1 o+ U( m: x# c5 ^' J- return theSpline;# k7 z9 [9 c& l5 t. G& g
- }
. b$ E# N! I2 |4 d) n: G, V - 6 C* H7 t& F4 d. q3 z5 ?% v) t
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)# c O! F+ ~; K0 I) e; p2 z9 Z
- {
0 o, g' K3 V, w3 G - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");7 y/ y. I) ?2 M
- if (!thePoints.size()) return;
, }9 \" P* V3 [; x" L1 ` - / P0 k }& Z' V7 `( A& Q: G' a
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
% K5 k; T( F6 I( R - + W# O! P' H, ]$ L* f- h( ]
- if (theSpline), l2 y0 ?3 ^6 F4 M- H" f
- {# A& h: }0 p3 V2 X! q7 t
- theSpline->Highlight();" c+ I' z" w% z& A, ^. k
- uc1601("Studio Spline Created Thru Points", TRUE);1 [" @ C% H" G, [9 g0 h
- theSpline->Unhighlight();" r; e4 X8 [$ d5 [& f
- }
* Z0 ~% x0 O8 p& {2 P. ]7 Z* | - }1 i9 U; D; v' g
- <p> </p>
复制代码 ) J- t) z. k t$ Y- H! F
|
|