|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线$ n$ v7 H4 U8 ?# a7 }
- #include <uf_defs.h>5 V0 F2 i- q! x+ L0 O1 T+ f
- #include <uf.h>
. b8 _& S8 O+ I. D+ t+ p7 N( @" b - #include <uf_modl.h>
5 C- X- Q7 K) O+ e' e7 I1 E - #include <uf_object_types.h>, L# x( m. D/ f: I- A1 o
- #include <uf_ui.h>! p6 x6 L+ { a0 n" \9 g% A
- #include <uf_modl.h>
- a0 \; ~6 m: h& l: L" P9 I6 a - #include <NXOpen/NXException.hxx>
, a! X- `% z* \! u+ a6 G" \ - #include <NXOpen/Session.hxx>0 T8 l$ n; l( J5 ]( P5 i
- #include <NXOpen/Selection.hxx>" J$ F6 U" Z, d5 |8 E) f/ K
- #include <NXOpen/Builder.hxx>
! Q" K; z& u. V3 h - #include <NXOpen/Features_Feature.hxx>
* K, h7 o. D: F, J7 s- q - #include <NXOpen/Features_FeatureBuilder.hxx>5 K' w' F E( a# r& R5 Y+ L
- #include <NXOpen/Features_FeatureCollection.hxx>
% W: y% F1 d& {4 F; O" l: c/ U - #include <NXOpen/Features_GeometricConstraintData.hxx>
) |" `2 @5 H% N- q6 t1 I# e1 B - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
/ C0 m/ q6 |' ]" V' b7 B" j - #include <NXOpen/Features_StudioSplineBuilder.hxx># X% X# s% {& Z- h: G
- #include <NXOpen/Part.hxx>
9 V- l# d( }# L5 N. C$ ` - #include <NXOpen/ParTCollection.hxx>
`# j& p) l4 J - #include <NXOpen/Point.hxx>7 k8 w! K& d/ V- w" w( w
- #include <NXOpen/PointCollection.hxx>
' y$ E5 M" V7 l9 n7 k; s. m/ A - #include <NXOpen/NXString.hxx>) D( E- T7 R. D8 r. W
- #include <NXOpen/UI.hxx>3 o( A) r, e4 K- _( @
- #include <NXOpen/Spline.hxx>( B8 U/ p( i8 [ S# H+ W- r; ~
- #include <NXOpen/NXObjectManager.hxx>
( \! \* t- \5 B, K6 F, {
6 q8 n( F) V7 F, `8 a3 g- k" H2 J0 |- using namespace NXOpen;
. z' e `3 n! o8 {3 V5 r7 ~ - using namespace std;
- |% o4 G" z+ ^% _) i$ N! Y, X S9 Z0 W
# P) n d# M, g3 D8 k% o- extern "C" DllExport int ufusr_ask_unload()! c7 w7 ]9 t* T2 _& z: }, Z. u
- {
3 ~9 _5 [2 X5 l7 E5 G - return (int)Session::LibraryUnloadOptionImmediately;
6 i" n$ m9 y0 S9 [% ? - }
# l) T$ e: O' K! v& ]; M - ; i2 O' a/ h9 t8 k; t# f. l( J3 m
- static vector<Point *> selectPoints(NXString prompt)
% \$ S R& x! t - {
5 E# A& \ R3 s' T - UI *ui = UI::GetUI();) x5 U7 d7 m5 v! f
- Selection *sm = ui->SelectionManager();5 R* ^8 M4 P& j6 B
- std::vector<Selection::MaskTriple> mask(1);
# _0 f" }5 T0 _, j8 I - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);. O/ O; H* h% t8 z. u0 U( W$ Q9 J5 i
- std::vector<NXObject *> objects;' y& }# g2 S s5 L* N2 B1 t( q- E
- 5 c. P# y0 g/ Q" [& k4 f
- sm->SelectObjects("Select Points", prompt,
0 \0 k( l8 {! y% v& r, ?8 o - Selection::SelectionScopeAnyInAssembly,4 o/ Q8 o, r# T0 k! {- U
- Selection::SelectionActionClearAndEnableSpecific,0 o/ W$ {# w% s
- false, false, mask, objects);
& g! K( M+ n- T$ Z+ `* }7 o# t - - f+ N4 v7 o9 U. C) \
- vector<Point *>selPoints(objects.size());
! _, W, ^5 V% H4 O7 S8 H - for (unsigned int ii = 0; ii < objects.size(); ii++)
" x6 W8 d# z) t' _% P - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% \; ], S# \ Q% y& u
' I' d4 i% c! H1 h9 @0 I- return selPoints;, t- _, X/ C/ ]/ ~9 c4 q7 U
- }3 q) x# _) q$ V1 g& k% b' H
- 0 H* z+ J6 E) j
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
% Y, O5 a5 S3 U7 X- i' f - {
. Y/ k W. i7 A4 s9 ] - Session *theSession = Session::GetSession();& c- N. `: @) F* s' M9 Y3 E
- Part *workPart(theSession->Parts()->Work());* l8 }1 _+ n8 O4 Z4 {" a
$ a u* P5 C- f) o. H' J3 T- Session::UndoMarkId markId1;3 c& P: ? h9 V% `$ X# @3 X- E+ \
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
; {3 c$ B* W0 k8 i0 g - "Studio Spline Thru Points");0 v/ N, l/ w& C$ W L- H1 R) D, g
; }+ u$ z8 w+ o, r5 U- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
1 L; b* ]8 i7 W0 j4 F3 M! n - 7 l8 H, a" b s) z2 A4 |6 w6 E1 h
- Features::StudioSplineBuilder *studioSplineBuilder1;
! _3 A' v6 r) [3 [ p - studioSplineBuilder1 = workPart->Features()->
' e- g* m# z. \0 m8 g! I k - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
5 p2 W c# |$ u - studioSplineBuilder1->SetAssociative(true);
' ~" f, ]/ G- g" f( }! [ - studioSplineBuilder1->
3 T$ L. E* f; n& ^$ L7 i - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
" v( S9 s8 w7 ]/ O; C% f - studioSplineBuilder1->
9 ^! j: e. z" S' A1 w - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
$ ~, p. C& }1 ^# @) S9 j: \ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
6 e" W( F) r" F - studioSplineBuilder1->SetPeriodic(false);
4 h0 L+ D6 J* ~5 S) f - studioSplineBuilder1->
2 M7 `; M/ m* U) ]2 T- P% w) q - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);, S: K9 @+ X& [6 h& Q! ]/ A
- std::vector<double> knots1(0);. c8 Y# Y+ n9 x6 k
- studioSplineBuilder1->SetKnots(knots1);
8 [0 H+ S; `8 V9 g6 Q9 } - std::vector<double> parameters1(0);
# g1 F% @+ W5 \" z" l - studioSplineBuilder1->SetParameters(parameters1);
; H- i5 C( Y. T - Direction *nullDirection(NULL);: s" `6 S( f! C" J4 A: f
- Scalar *nullScalar(NULL);
$ u1 x; U3 n. O* i' Y" d, k) [- F4 b - Offset *nullOffset(NULL);/ P g3 |6 J3 F2 C R" `6 p
6 C$ R6 A% E' t" v! ]- std::vector<Features::GeometricConstraintData *>" v" |9 W5 { {' K* J# T K, C
- geometricConstraintData(thePoints.size());
6 g0 W# J. A6 R7 o& Z - l% \; i- r1 n5 }7 [* h
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
$ w7 z+ D5 g! V4 c( } - {
2 R. ?! t9 N; i4 _ - geometricConstraintData[ii] = studioSplineBuilder1->
8 F( i- l, d, n6 Q+ S' I# H) N% T - ConstraintManager()->CreateGeometricConstraintData();7 o3 ~+ j# p# C$ D) k
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);, \3 C, q" e' A4 g- t
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(+ T. T, m& J" f. n
- Features::GeometricConstraintData::ParameterDirectionIso);
' t q/ {' P! _; W# Y5 a - geometricConstraintData[ii]->SetAutomaticConstraintType(
0 O8 R$ @; I0 X( C3 d: N. r - Features::GeometricConstraintData::AutoConstraintTypeNone);' ]. e6 M' \6 \. |) k8 A
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
; I$ u5 n0 P& I1 E; | - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
4 |" i! Z" }8 M: o0 r$ N2 j - geometricConstraintData[ii]->SetCurvature(nullOffset);( H1 _8 n$ z3 |
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ K1 m9 `. D% L. l8 w% k) c* B! U
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);1 b# ` D" u5 |2 O
- }
7 h9 E9 Q& Q7 k
* g Y" u. l0 R- Y# Z. p- studioSplineBuilder1->ConstraintManager()->SetContents(
& K- H" ?+ k- x# E - geometricConstraintData);- Q! l. q I0 k4 m& a
6 {7 |) H7 F9 b& W- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
0 T6 v3 H6 z, e' Y - Spline *theSpline = studioSplineBuilder1->Curve();
. {) o/ a: g- C- |
$ D; H _& [* o" ]! J5 N- studioSplineBuilder1->Destroy();% z" z, ^. {* N; S1 ]& J5 @# q" C
- 9 O" l/ t& \8 u( p8 F" y) }# t- [
- return theSpline;/ [7 |5 W) i7 Z6 D+ M
- }
$ a+ F( U& G; B" }9 j
7 s2 z9 t, k6 l+ o( i7 p- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)) h+ O( @( r, ?6 o' X4 k; T0 n
- {# I3 x+ S0 g# m1 d% s/ ^6 ` L
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");. H$ T7 D, U, X' k0 a
- if (!thePoints.size()) return;, a- U, c9 p+ f7 \$ c
$ {( a4 v6 z6 j, F* x# G/ F- Spline *theSpline = createStudioSplineThruPoints(thePoints);
# d/ K4 L8 n$ L$ Q! C- _ r& @ F
9 |' B5 N, s9 G$ W+ p- if (theSpline)) c, _$ m4 C0 }- e" P5 U
- {' w. q7 `; Y8 s: P* _
- theSpline->Highlight();
$ s8 A) }5 Z8 k( [* w - uc1601("Studio Spline Created Thru Points", TRUE);) E+ i! M( h4 ^ K0 L9 ~6 Q' u
- theSpline->Unhighlight();% t1 u% H$ e3 e
- }( g% e# @" x- d0 x& k: u+ x: K# y) V
- } t2 F: F) }7 Z, x
复制代码 : H1 P+ U/ G4 ?% i. A3 |$ m6 ?9 F. a
: `6 F; ?3 E( B$ \9 T' a- y; |1 t8 J8 U' G% a
|
|