|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
; N2 R. A V( F- #include <uf_defs.h>
" ]+ V" ]0 Z- M - #include <uf.h>( ^- A' R5 d [/ ~2 n* F- o+ L
- #include <uf_modl.h>
S* `, V0 f8 \: ` - #include <uf_object_types.h>, I, M5 I$ V; y
- #include <uf_ui.h>7 _1 \4 S. O; r2 b
- #include <uf_modl.h>
, l% e. l% |- z5 ]- L! L - #include <NXOpen/NXException.hxx>: J D Y) ]. f5 Y
- #include <NXOpen/Session.hxx>
2 T8 G( g$ A% b$ o - #include <NXOpen/Selection.hxx>
( Z* e# |% M k% g5 ? - #include <NXOpen/Builder.hxx>- z. X6 ^: q( a; u( Q4 h
- #include <NXOpen/Features_Feature.hxx>
' _1 M/ {8 B9 C - #include <NXOpen/Features_FeatureBuilder.hxx>- x0 E; ?! v0 n8 ~( h: J$ X' a* {8 q
- #include <NXOpen/Features_FeatureCollection.hxx>
# q1 e9 s5 V, a7 g8 I5 L - #include <NXOpen/Features_GeometricConstraintData.hxx>
8 \6 `3 v! X! ?' ~' { - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
. t% P1 {7 R1 t* D% m- Q; d$ A/ z! o - #include <NXOpen/Features_StudioSplineBuilder.hxx>
; k' W! d' o" c - #include <NXOpen/Part.hxx>
7 B! g6 ?) Y7 q9 e' H - #include <NXOpen/ParTCollection.hxx>' n- v2 Y" f0 M6 M* f3 V
- #include <NXOpen/Point.hxx>- P* b8 R/ ~# N* c, r' z
- #include <NXOpen/PointCollection.hxx>4 N4 D6 R* d( G* }( ~8 u; z
- #include <NXOpen/NXString.hxx>
6 T) i& I/ V& T) `% j5 Q' E$ t$ d - #include <NXOpen/UI.hxx>5 s% t' z$ y) n, l
- #include <NXOpen/Spline.hxx>
. _- Q0 K8 F9 ` - #include <NXOpen/NXObjectManager.hxx>
! p( v$ v0 D" A6 i- o( n5 i2 R, [ - ( c$ W. f- H2 {+ H: M/ G9 g: X
- using namespace NXOpen;
; ~% S/ L5 H1 C+ F - using namespace std;
* l+ F* }& P8 X; x' m& s& O/ Y$ v
* c8 z3 Q# `1 R6 ]- extern "C" DllExport int ufusr_ask_unload()1 e6 A! |( I* o
- {* J* h( X% F. }2 b4 M4 l, d
- return (int)Session::LibraryUnloadOptionImmediately;
) a# j4 J# V' E6 L X8 j - }1 ^7 N5 S' O4 S$ c1 }& W' u
- 7 Y% B( I/ } Q8 E2 Y% \ z* ~% f
- static vector<Point *> selectPoints(NXString prompt)9 Z+ w6 \' v5 Y5 p& ~
- {$ t, } l$ X+ f" g& R
- UI *ui = UI::GetUI();
) P; Q% h. a9 u) v - Selection *sm = ui->SelectionManager();4 U! B# l5 i# w0 v( f% ~8 |) L4 _$ d
- std::vector<Selection::MaskTriple> mask(1);
6 M D7 A) A! ]& l' m - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);0 ]! ~1 T4 [+ X, W# C, c
- std::vector<NXObject *> objects;
# a/ f: |5 l0 ?4 k1 J
1 j# g5 o% N. k- sm->SelectObjects("Select Points", prompt,
6 ?( r% a2 k6 S) s! `8 ?& L' I - Selection::SelectionScopeAnyInAssembly,
! G9 r# y' k" w2 } - Selection::SelectionActionClearAndEnableSpecific,
5 n. D1 ? V% |1 p7 L9 Z3 n - false, false, mask, objects);
8 `4 H2 C& @9 h6 H' I: B
: _! U3 n, q+ p& Y% r- vector<Point *>selPoints(objects.size());7 b6 z6 H. a+ e9 r$ Q2 p
- for (unsigned int ii = 0; ii < objects.size(); ii++)( q1 l* j+ f# r8 [
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
* e2 L1 P4 s, {* u$ u: H
- }9 k: O8 c) S) w0 @- return selPoints;
3 K+ b% y3 |/ F! a( o3 J. ^ - }6 e2 X* H. X% i) ?
0 b" V; _) r$ ]- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
3 W* O6 Y. W/ O) m6 o( \$ R; z - {, C. w8 z9 {3 Y8 A6 w
- Session *theSession = Session::GetSession();
$ r& w4 z# G: M) q" m5 _9 ] - Part *workPart(theSession->Parts()->Work());. _) S1 f0 S9 Z/ g8 u$ ^
- 2 g0 E/ d" O7 n& F7 E8 t7 P
- Session::UndoMarkId markId1;7 G5 U% m& @& F
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
, l& M {2 R B, G Q - "Studio Spline Thru Points");( D2 x: g2 v& u8 x# W$ f
- 5 F* n" W4 y$ ^/ ]0 R" F; ~! R
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);6 L, @( y# t, U' \( y4 V
- * ]0 V, K' H- x# _$ q/ u
- Features::StudioSplineBuilder *studioSplineBuilder1;
3 e8 }# \8 Z& e6 r2 I - studioSplineBuilder1 = workPart->Features()->
# p& \; a+ C; R1 W5 D% \% k) P - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
( X$ v& X# c* A" s3 l" p* B - studioSplineBuilder1->SetAssociative(true);
, K" b) m* |3 h7 Y - studioSplineBuilder1->
1 g" G* a& }* `/ S2 ^ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 n5 ]" u8 s0 i
- studioSplineBuilder1->6 [: |/ {7 Y$ i* D
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
( q# |2 H) ~6 w3 w# q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" e: l# J5 X3 e+ I; c, q
- studioSplineBuilder1->SetPeriodic(false);
# ~ y, K/ |, P: w* y# ? - studioSplineBuilder1->$ g+ U2 J0 L1 K
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);" V. w% F. N6 v
- std::vector<double> knots1(0);
/ d/ `5 E' [8 H4 i% I - studioSplineBuilder1->SetKnots(knots1);& Q" u8 S# G B/ }! Q' m
- std::vector<double> parameters1(0);$ S0 z l( ~$ H4 N! x
- studioSplineBuilder1->SetParameters(parameters1);& k" v' Y& @: p0 M% P8 I4 r* Q
- Direction *nullDirection(NULL);
; T% ]$ o( R/ C% W* t' j7 }2 m o - Scalar *nullScalar(NULL);( c" E5 _& h( v( [, i
- Offset *nullOffset(NULL);
5 i0 j, q! G; |. `# y) _2 V' Y
4 F2 Q i `* T3 \6 m: y, q/ E, X- std::vector<Features::GeometricConstraintData *>' }# V K; W% N7 P5 r! a9 X
- geometricConstraintData(thePoints.size());
% ?* _6 s4 ~! b- ~( Z - ) H; O7 u. L. x: m% a$ H7 g. L1 u
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)4 U) Q' `/ ]! Y# B; V& H% d# L! B
- {
' ]/ |0 h8 F6 N8 s% A - geometricConstraintData[ii] = studioSplineBuilder1->
% b# i$ A8 `4 m x7 p% p/ h# f - ConstraintManager()->CreateGeometricConstraintData();
! Q' n; S( ^: I) M/ q - geometricConstraintData[ii]->SetPoint(thePoints[ii]);. i" v" t" d% E0 C" ~( }- P) W( n
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
! w. m% n/ L+ L - Features::GeometricConstraintData::ParameterDirectionIso);
6 z7 n) [( k% H% Q - geometricConstraintData[ii]->SetAutomaticConstraintType(
7 B6 k% _" l! u' ?: Q+ D - Features::GeometricConstraintData::AutoConstraintTypeNone);- ~( _. [* n4 S
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ ?# O( Q4 ^8 T7 i. |
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);0 n. X8 j: N& O0 y9 p8 W9 p
- geometricConstraintData[ii]->SetCurvature(nullOffset);
, I6 s1 w% x/ `$ w2 { - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
( d. g' X) ?1 p: W- n$ } - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
& ] i& C, X( U) h- l - }
0 A" c. k d) e
; ^3 v0 h! e2 Q* q3 P( Z- studioSplineBuilder1->ConstraintManager()->SetContents(0 Y( i; [) p1 t4 v) T
- geometricConstraintData);7 z# f3 b! y/ s0 x
; @: p6 L7 o5 R4 k+ Q- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
$ Z) b t" u' }+ p# j" j$ j3 k0 J - Spline *theSpline = studioSplineBuilder1->Curve();
/ c( u$ i- s, O) ^' S* n: t+ D! z - 0 S7 u( k- k0 W) z
- studioSplineBuilder1->Destroy();
/ \; N3 t$ ?" ?5 o; I y8 O4 v1 b; u - : Q+ z( m" N, d& |1 S. Z
- return theSpline; W: J( a& j3 L$ E
- }
5 r5 y* d$ O7 Q; P - 2 q. M" ]6 K" @. |5 B$ f% M- \
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len). w; A& o+ I. f7 M4 g8 b) k
- {" x7 e `7 `- j5 W6 m
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
4 ?% B7 o- ` t% e% ` G - if (!thePoints.size()) return;0 n. X$ \% s$ i* S, ?, ~0 b
8 | d* [( Y0 O8 l- n1 v- Spline *theSpline = createStudioSplineThruPoints(thePoints);
4 {7 l2 F% \2 O) N
$ l9 Y7 H! P9 r; e4 p0 t- if (theSpline)
; o% e6 u$ }( G7 K0 j; a" t7 k - {
8 K5 P( I0 V! J# o - theSpline->Highlight();
5 p8 K* J; c% K0 s; S$ z' I H8 h - uc1601("Studio Spline Created Thru Points", TRUE);
4 q7 j8 }/ Q H, I+ v - theSpline->Unhighlight();+ U2 H. \# q' J
- }: o9 k2 l2 o# s" I& o; p2 U, u3 w
- }
7 k0 [- r0 H# O3 r8 p- Z: h! b( K
复制代码
) X4 O( P& W) K+ D2 c6 B2 N( Q! T$ |6 B2 \
, N' C2 {/ n' y' A
|
|