|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
5 }8 j+ o2 E/ \; U2 r( E7 `" H- #include <uf_defs.h>6 y9 ]3 n; E0 y6 ?1 @
- #include <uf.h>; e* B$ l% K* i$ w# J8 ?
- #include <uf_modl.h>' E- [1 U5 m1 {2 U7 N+ p z
- #include <uf_object_types.h>' w0 N4 B- ]0 v2 Z* @: A$ T
- #include <uf_ui.h>) ?- T G3 D* N% f
- #include <uf_modl.h>
" {8 H2 Z/ X( v - #include <NXOpen/NXException.hxx>, o2 Q9 e) w4 y# Q& u2 v! f0 I: V
- #include <NXOpen/Session.hxx>, L! {$ ?" \8 d, R: ^4 w3 o6 p0 r
- #include <NXOpen/Selection.hxx>
W0 C# a( J5 k' e - #include <NXOpen/Builder.hxx>9 ^7 G, W F5 Y! Q- A
- #include <NXOpen/Features_Feature.hxx>
8 L, X* i4 P1 F3 O% i - #include <NXOpen/Features_FeatureBuilder.hxx>; p# e5 X r8 _. i/ U% |3 B! [, n
- #include <NXOpen/Features_FeatureCollection.hxx>
# K* {' a3 V' g. a4 ~9 S D0 U - #include <NXOpen/Features_GeometricConstraintData.hxx>
. I0 z# V( d# N - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>' G+ J+ Y8 d/ Z. k: L
- #include <NXOpen/Features_StudioSplineBuilder.hxx>. _9 B; {, V- b; a# k! Z; ~; K
- #include <NXOpen/Part.hxx>
5 t/ h4 w R; H) z% j4 H - #include <NXOpen/ParTCollection.hxx>3 U6 k/ d4 H# x: t8 u& S$ _/ J
- #include <NXOpen/Point.hxx>
% K/ r6 s! J8 s8 _ - #include <NXOpen/PointCollection.hxx>% u, o+ N! j9 P; F7 ?
- #include <NXOpen/NXString.hxx>
- A2 {6 M% a6 G j - #include <NXOpen/UI.hxx>; J# I$ Z8 j1 c
- #include <NXOpen/Spline.hxx>
9 H2 R+ v5 [9 v8 e. C+ B - #include <NXOpen/NXObjectManager.hxx>
0 G" D3 J0 K3 b
8 a% H" k4 _$ s* n0 b- using namespace NXOpen;5 j+ C* D# E( w# m: \& {
- using namespace std;
) v( a7 U/ B" O& x: f* ^& m! F3 [ - " M( r6 S2 t8 `4 O" A) B
- extern "C" DllExport int ufusr_ask_unload()9 M! z: ^, b y" f3 G3 |
- {
( N; c, m/ i' A. Y: w9 d" C9 e - return (int)Session::LibraryUnloadOptionImmediately;
& X! b* M" y4 t) a# u. S8 O - }
$ b% u" g; `- x6 ?* B5 Y7 G
; i: Q4 I. ]+ F p/ V8 t. b; Z0 ~- static vector<Point *> selectPoints(NXString prompt)
9 Z' J" _9 o8 a+ o7 }- [* p - {
q% l8 |) W% H2 K1 n - UI *ui = UI::GetUI();( l; ~9 E3 y/ o) R2 T1 O
- Selection *sm = ui->SelectionManager(); N6 k" `. g& F
- std::vector<Selection::MaskTriple> mask(1);
4 O; i" K( u0 ~9 m6 U - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* z7 c( v0 d8 c4 x+ f! w; g) U4 ?
- std::vector<NXObject *> objects;; b8 [' r7 s+ l$ ~. y
- 2 l7 s% d9 m! L2 E: i8 S5 r/ v
- sm->SelectObjects("Select Points", prompt,% _5 K% n( c- S/ h1 k* W1 F) P5 X
- Selection::SelectionScopeAnyInAssembly,$ E$ |: a! ?( t' K" W+ b5 S
- Selection::SelectionActionClearAndEnableSpecific,
# F+ r. i3 ], M; K" `9 a - false, false, mask, objects);
V, g* P" S$ [: s2 B5 v8 J' M
& z8 m! E$ r& V( M- vector<Point *>selPoints(objects.size());
$ v5 u, g2 \8 U5 ] - for (unsigned int ii = 0; ii < objects.size(); ii++)% _: h1 c0 @ j
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);" @* I1 q4 U! h% r2 V# E
) [- i2 f' X2 O1 |) G- return selPoints; T6 {% t. u2 m4 g- W# }: }; Y6 n
- }3 x3 Q! N0 \ m* v
2 `# b* [" m, ]! L' S- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
. y& V, C, N4 O5 A2 m8 Z - {
5 f" Z- W4 U2 J1 }. u' S% o: m# ? - Session *theSession = Session::GetSession();
- a7 o9 X3 H0 E7 t4 b& I - Part *workPart(theSession->Parts()->Work());
* x* T# E$ s; i$ k p* P4 O9 ] - 1 @3 `! B9 U0 ^$ K. ]+ [, G( d7 U' [
- Session::UndoMarkId markId1;* i/ ~& V( E% d; h4 Y" g$ T
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ A, ^: A2 r1 |( D
- "Studio Spline Thru Points");* X; C5 K& r, \3 A
. G$ [/ A" y8 v s) A3 O2 `, y- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
# b7 a1 o. r3 N/ k3 @# v6 h' k - ' d8 H H' q- K- R. ^' F" t t5 t
- Features::StudioSplineBuilder *studioSplineBuilder1;5 j- M: |% y _' _8 U# H
- studioSplineBuilder1 = workPart->Features()->
* y2 m8 W8 H K' P+ B3 U& z3 h - CreateStudioSplineBuilder(nullFeatures_StudioSpline);( O+ a5 f( j1 @' S$ }$ s
- studioSplineBuilder1->SetAssociative(true);
) W; N1 y- k9 c. _0 v! I - studioSplineBuilder1->9 h+ ^( z0 U" n+ T
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; j* R, c( X3 L
- studioSplineBuilder1->
: {+ c$ S% I( r0 Z; J$ k - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
; S( b# D4 N* h; t& q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 m! l. m' N6 ^ [0 s
- studioSplineBuilder1->SetPeriodic(false);: \0 D8 l" V7 `1 X2 ], U7 Y" u2 ^% b
- studioSplineBuilder1->' ?# E" b* T# A0 Y2 B0 @1 l
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
( j/ D% e7 K2 M - std::vector<double> knots1(0);
0 ^+ W6 ~( H# K% |/ ] - studioSplineBuilder1->SetKnots(knots1);
! C3 q" }7 {* ]) l - std::vector<double> parameters1(0);+ @* ^: O/ v/ q4 x8 \5 p4 V
- studioSplineBuilder1->SetParameters(parameters1);: l) F" \+ l; X* a: @8 Y' C j( q
- Direction *nullDirection(NULL);
j" r! N! w1 q7 x, P$ I- i - Scalar *nullScalar(NULL);. B3 Q: H1 s! S8 R2 U$ L& [
- Offset *nullOffset(NULL);
6 F3 {* I) v" A" H0 y, I - ) I1 w; ^$ S3 x0 A& q. a1 g
- std::vector<Features::GeometricConstraintData *>) Z3 q4 C! o. G$ m0 E# s- G
- geometricConstraintData(thePoints.size());6 Y, ]. c9 Z2 ?
- - W; A2 B2 S" A$ o* @
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
( _# t( B3 H1 z" X4 B - {/ O4 }, y& l: S9 \
- geometricConstraintData[ii] = studioSplineBuilder1->. Y, j0 [7 k; ^5 x! I- q8 Y
- ConstraintManager()->CreateGeometricConstraintData();
# y7 i- D& Z x. n, w - geometricConstraintData[ii]->SetPoint(thePoints[ii]);* P: {" M3 g# Z3 q% V- W
- geometricConstraintData[ii]->SetAutomaticConstraintDirection( j+ @3 _7 a( g- |4 w9 f
- Features::GeometricConstraintData::ParameterDirectionIso);) Z1 p* N8 W1 c4 k
- geometricConstraintData[ii]->SetAutomaticConstraintType(! C8 ^3 M, {6 P& o; S, {
- Features::GeometricConstraintData::AutoConstraintTypeNone);
; r1 [' L) I) A, R2 _1 g$ C( [$ o - geometricConstraintData[ii]->SetTangentDirection(nullDirection);" M, b% j; Y; o( A: {
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
% O" I5 l, h9 o& Q - geometricConstraintData[ii]->SetCurvature(nullOffset);
, c% F3 N m) L5 L5 X - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset); [2 W6 \/ |5 c) t4 s6 b: f$ n
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);1 z: r# u; k7 H! ^( z0 L7 q6 C# [6 H
- }
& ^$ k6 |/ T( f$ z2 {+ f( ?
3 k T; v1 R) i) [2 }$ @- studioSplineBuilder1->ConstraintManager()->SetContents(
! u2 K% J7 B: ^7 S - geometricConstraintData);
& A5 G- ^+ a- m/ v, D - 6 C; W' @; }' d, y6 r1 p$ y
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
6 Q( `5 {+ ^8 o - Spline *theSpline = studioSplineBuilder1->Curve();+ R' O4 ]. V" \
- 8 ]' C1 V; y; Z2 x' c P
- studioSplineBuilder1->Destroy();
: O4 D7 h- P$ \$ s# S n0 m - ; M' D c" h" [9 G8 X
- return theSpline;* K" {5 d$ U, c7 |$ O; Y6 T0 W1 b
- }; v+ h' m! L: `" j$ q, b
- 0 e1 F4 }- t6 O* r# A: N
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): K) W. c% h* e6 [
- {
7 ^- _% b' P) k% c5 J8 p - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
2 ]* ]9 ?/ v0 U" c$ p( n( Z9 [4 q - if (!thePoints.size()) return;
1 [8 o$ w9 Y/ g% _ - # B8 E8 v% e/ a6 V9 X+ }
- Spline *theSpline = createStudioSplineThruPoints(thePoints);$ d7 x" p' `; f0 ?( T5 m
% l% ]4 a" v z0 H9 u5 `- if (theSpline)
7 J+ D- Q1 u) p J0 ~ - {
7 N, c2 Q6 z; @, [0 |- o' l - theSpline->Highlight();8 W* w3 r7 J# L- T; D9 c( x* w
- uc1601("Studio Spline Created Thru Points", TRUE);" Y* ^# A4 Q: _% b- M" M" r
- theSpline->Unhighlight();5 {1 q) w' A, I' Z5 M* K" V
- }# [ B& ~- [5 g! _
- }
5 X H8 t% A) J& X
复制代码
$ s2 B$ o5 `, i! B3 V# e: X0 |2 W2 h& C- Z0 M+ X
. v9 J% {- i% W y& H9 w4 q2 b6 ` |
|