|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线 k7 V! T+ O9 B/ m/ |
- #include <uf_defs.h>
/ ]# v0 z+ m+ M. u" g# ~ - #include <uf.h>7 H) ~( m1 N! \3 a& l$ G5 q- |
- #include <uf_modl.h>- k/ p! Z/ {# k
- #include <uf_object_types.h>
0 N8 z4 z% ^2 K2 H0 k% Z% t" l - #include <uf_ui.h>
2 h/ s t9 r, p5 e - #include <uf_modl.h>
$ p O9 |5 j# n7 x4 q$ m; p$ ^+ A - #include <NXOpen/NXException.hxx>; T' v4 I2 z( ^3 Q6 a0 Y) Y$ f' x( g
- #include <NXOpen/Session.hxx>
9 L) x: s# n h3 W8 Y4 ? - #include <NXOpen/Selection.hxx>
* r$ A3 Z* l# v2 Z - #include <NXOpen/Builder.hxx>
. o. t, Z/ w) k( @& w! t- o - #include <NXOpen/Features_Feature.hxx>$ _$ z+ e: j/ z! b Y, a0 u7 [! o
- #include <NXOpen/Features_FeatureBuilder.hxx>. Q [1 D7 i# |5 j1 x- Z. k
- #include <NXOpen/Features_FeatureCollection.hxx>4 s8 U# [- K- R# ]0 Z5 p7 H
- #include <NXOpen/Features_GeometricConstraintData.hxx>' ^( F: a8 q; S' w4 @& Y- ^+ G
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>2 [6 T; V W$ H. E5 ~
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
}" O& F5 y7 R8 r) P5 n - #include <NXOpen/Part.hxx>
0 S9 l4 T; ^+ x9 R - #include <NXOpen/ParTCollection.hxx>
3 e8 @2 U" p0 J/ r& { - #include <NXOpen/Point.hxx>
0 j! ~0 I- [* a: S, w) b* _ - #include <NXOpen/PointCollection.hxx>
( n1 e& R8 H: J/ @4 K+ s+ A - #include <NXOpen/NXString.hxx>
6 j( M2 L5 ]5 P* m: U - #include <NXOpen/UI.hxx>- }) i( X! |7 g
- #include <NXOpen/Spline.hxx>( J2 q! m, }3 Z! Y3 n9 R3 {
- #include <NXOpen/NXObjectManager.hxx>
) E+ X) ~( j W1 ^; c9 ~( [ - " A: O5 Y, @/ x+ |- H
- using namespace NXOpen;; l9 t: G8 E, @) e( K! j3 x
- using namespace std;) v% Y& ], ^/ r( z0 V* I" v. |" d
; `- {7 {- M2 e; p# n" m+ A) P- extern "C" DllExport int ufusr_ask_unload()4 Q% v3 V* V+ ]4 @( F) @
- {
7 [7 i4 Q% e, E+ p( Q5 q# q - return (int)Session::LibraryUnloadOptionImmediately;
0 U2 h# {9 o+ ` - }
, E0 P2 T7 d2 F, t% d - ! Y# y$ `% d# f& @# C2 c% s: p
- static vector<Point *> selectPoints(NXString prompt)
' C" i* [2 b( ^$ k9 F% i - {
, J& u' X/ ?0 f2 U3 u* R) n" A - UI *ui = UI::GetUI();$ d0 P0 Q0 N% d
- Selection *sm = ui->SelectionManager();/ y: ^0 B% [: a9 i
- std::vector<Selection::MaskTriple> mask(1);
5 _* d" O/ k% o! g- M - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);4 E0 d' J) y, @3 a5 M% f
- std::vector<NXObject *> objects;& M3 @! y+ N N/ w
]- M0 B7 s4 k% @$ z! q- sm->SelectObjects("Select Points", prompt,
5 O5 w2 {6 f% V- g2 J+ Y, N - Selection::SelectionScopeAnyInAssembly,: D [; q, M9 {. b* [
- Selection::SelectionActionClearAndEnableSpecific,
E# n& `5 J8 ~& E3 p+ s) `( H - false, false, mask, objects);- m% V7 d9 ~7 D
- ! P7 q( f) A% _1 a% _2 @
- vector<Point *>selPoints(objects.size());# O, W* P- p4 F. \2 v; ^
- for (unsigned int ii = 0; ii < objects.size(); ii++)
: D( I4 R: J7 r8 z8 j. I$ g) c' c - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
. [, s8 E& n+ @% @0 M
) ?. C \. K- d) ?! j: Y- return selPoints;$ o& c+ D0 y% o& D
- }
; s. a' U! }* ~; n- { - 2 e) a8 z" {8 J! o- p
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
) Q; N0 R( t" r% S/ K - {. q. _+ ?( H+ G5 N/ s" n0 k
- Session *theSession = Session::GetSession();
6 S$ }+ }8 C5 B3 h: L3 @# K - Part *workPart(theSession->Parts()->Work());
' L; \6 J$ a/ Z5 ~1 T' q( S4 U' F
. l J, w/ e1 B; h( T1 y; \- Session::UndoMarkId markId1;! g4 M+ c: n" Q5 d2 K
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
, `: O3 P% F1 M) ]8 x+ J" U - "Studio Spline Thru Points");/ A7 A4 G& U$ E
4 ]: |( x" f2 l8 ~. ~8 z- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
6 D# S) u, y# f/ o3 h% S- y
- o h6 G1 d- {# b0 T- Features::StudioSplineBuilder *studioSplineBuilder1;
% ~" s7 o, o1 N7 ]0 m5 l; q - studioSplineBuilder1 = workPart->Features()->7 {) X* i+ S4 R! q% |: E9 v7 A; u
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);- M3 e+ _3 z1 x; Y$ D8 a: ~( C, N
- studioSplineBuilder1->SetAssociative(true);* I- c. _8 M. g& ?5 D! j( `* G8 F
- studioSplineBuilder1->
( b1 Y& k/ ~8 `" B y' f6 g# Q - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
: g* h: [* _, h3 |" D5 f - studioSplineBuilder1->
% L$ d, X- V7 H4 E+ D/ p0 F - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);" Y- ?+ f5 J' [& q( E' U0 k
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
- | {/ b6 s4 L5 n$ ^* k5 B0 O - studioSplineBuilder1->SetPeriodic(false);
4 d L! O2 @) r6 J2 O6 w - studioSplineBuilder1->! _# ^+ t: X; d
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
$ G# D% \2 Y' `2 D" b0 ? - std::vector<double> knots1(0);
" l; q# i: f0 J4 v0 r7 V7 U - studioSplineBuilder1->SetKnots(knots1);' D& k/ U; a; l: J. X" E! M
- std::vector<double> parameters1(0);4 E# b0 d, I* u$ T$ `( {
- studioSplineBuilder1->SetParameters(parameters1);7 I- ]. S8 a) n4 @: [
- Direction *nullDirection(NULL);
3 G; O: \8 k! ~+ d - Scalar *nullScalar(NULL);
7 w' K$ H( E% k$ P/ a, a6 L0 D4 O - Offset *nullOffset(NULL);4 A2 w9 A# }( m% N( G" X) N4 _
- 3 g2 P+ j }$ z7 |1 u1 \8 j
- std::vector<Features::GeometricConstraintData *>
/ U( {5 t9 a5 W# @8 G - geometricConstraintData(thePoints.size());
, S, K. m& X7 v, O! |( Q
/ f; N, F4 ^) _6 y- h- for (unsigned int ii = 0; ii < thePoints.size(); ii++)) U3 j& c! ^7 q
- {
1 L2 p8 A! M! U% u, _8 v - geometricConstraintData[ii] = studioSplineBuilder1->( z2 Y0 M4 B# @& _' l
- ConstraintManager()->CreateGeometricConstraintData();8 y! V6 s+ o# m( T- T, c
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);9 {4 |- i! A! M( b* p
- geometricConstraintData[ii]->SetAutomaticConstraintDirection( u; C& @ d n5 [
- Features::GeometricConstraintData::ParameterDirectionIso);! q, o! \ w* V# L1 _1 \; ^/ J' b
- geometricConstraintData[ii]->SetAutomaticConstraintType(/ Z0 Q, z6 w, T; O
- Features::GeometricConstraintData::AutoConstraintTypeNone);
# ~' t: {' Y7 L - geometricConstraintData[ii]->SetTangentDirection(nullDirection);4 G+ O& |; r& Z+ j2 \0 T) [
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
0 y1 m: q2 X" B& D4 \8 C! d9 [/ i - geometricConstraintData[ii]->SetCurvature(nullOffset);/ U2 n$ n6 W3 O \; L, }% @
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
' p! }8 V$ K" x1 W - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
* O( t6 V7 r6 H - }# s8 H& V! s/ b, T. b* A) m
- " S3 n5 c) N2 M# x
- studioSplineBuilder1->ConstraintManager()->SetContents(+ E) \! B7 ?& N' P8 Z; }2 T
- geometricConstraintData);
. d, {1 c) _% A1 G2 @* U! a - 0 p C0 H: o. Z" O( |9 a6 d. f
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();# @5 F) I# u3 |: q+ c
- Spline *theSpline = studioSplineBuilder1->Curve();# s7 Z8 w" \. A$ V% m& i3 f" H' m
- 6 f! P4 T2 |; z; S" {6 J9 Z
- studioSplineBuilder1->Destroy();
# }' {+ L9 K$ ` - ! h, y8 J6 L e* h0 o3 W+ t# o
- return theSpline;8 w3 u8 _3 D4 C. E+ }1 d0 J, a- R
- }9 j5 H0 c9 F4 i5 `2 r' E+ o
$ P$ R8 Y1 e) A" [+ \: R) @. f a- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)6 i# {. ^0 O0 b
- {9 z; n! I: Q/ i, ~8 M8 _
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
y! f8 b3 }) J* @& V: t$ O5 s" x6 i - if (!thePoints.size()) return;
# G- A; @8 z# s- T6 k, Q- P
4 O" X- R7 r" k4 D Q, D- Spline *theSpline = createStudioSplineThruPoints(thePoints);) B, y" O# j U u: ^
- 7 f" K* S( ^. I5 X5 X: f( k
- if (theSpline); U3 Y4 y6 z/ _/ c
- {) q0 j/ r4 y; w7 V, g4 H+ q
- theSpline->Highlight();3 Q, B( b; ?) J
- uc1601("Studio Spline Created Thru Points", TRUE);
( Q) s, s% O& h8 l x - theSpline->Unhighlight();4 V* G" J! i9 {; |9 J/ U/ z. v- S6 A
- }9 h% l3 p7 [* T6 C4 z) X5 t2 e& D6 t
- }
& Y; R1 Y9 i2 J( T' Z. V* o; S
复制代码
1 O5 H' ? P* p$ P+ o$ q
% p( _0 ~# D$ W3 o2 r2 }* I, B0 Y: |% G& Q' I1 H, S& |$ K
|
|