|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
7 \& Y4 X3 ?9 f8 E9 I+ u- #include <uf_defs.h>
5 Z8 v6 Y+ p. E/ Y3 b* y1 S - #include <uf.h>
4 n( r5 D3 M+ Y: P9 v% y$ G - #include <uf_modl.h>
# G7 e2 \7 w7 j8 A - #include <uf_object_types.h>
7 Q1 Q, w9 t+ c4 A6 d8 } - #include <uf_ui.h>
" U, U7 a2 [& ?: M0 q - #include <uf_modl.h>
; F* z1 r9 H9 y& V. j' r, u - #include <NXOpen/NXException.hxx>1 u) r- ~4 a. @0 V: J
- #include <NXOpen/Session.hxx>
$ `, J. ?! P' K; o. _ - #include <NXOpen/Selection.hxx>
- D5 T' `6 T" X. a. v* O, E& i - #include <NXOpen/Builder.hxx>& V5 w, p+ i w5 {7 A( _
- #include <NXOpen/Features_Feature.hxx>1 j' J4 R' B5 W& Y5 Q" H! U5 ^
- #include <NXOpen/Features_FeatureBuilder.hxx>* }0 e" ~* z2 a. N: L
- #include <NXOpen/Features_FeatureCollection.hxx>
/ }) z. C9 P7 Q - #include <NXOpen/Features_GeometricConstraintData.hxx># t& y1 d' C% S/ I' j. X
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>5 ]# d, k1 |2 W0 H
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
# x$ o* p, d" x. y. ? - #include <NXOpen/Part.hxx>
2 T: ^3 u. A% F- H; F% s - #include <NXOpen/ParTCollection.hxx>
4 A! |1 R7 t* r) t, O* K4 R - #include <NXOpen/Point.hxx>7 E$ j& |& P- C ?3 P
- #include <NXOpen/PointCollection.hxx>6 Y0 b% Y$ e# t1 g0 f) W! a" T
- #include <NXOpen/NXString.hxx>
6 K, H; }* Q2 Y; `; q: c. c - #include <NXOpen/UI.hxx>; p) `: a! u* l
- #include <NXOpen/Spline.hxx>
9 e; q2 E8 M3 i( L - #include <NXOpen/NXObjectManager.hxx>+ W& N5 h- r) U' v7 Z" `7 u
- - d0 n) a, N2 m0 @) q, ?
- using namespace NXOpen;( u- `+ I$ X9 P! c# b; }
- using namespace std;+ M8 {8 o l d' k
- % x, O4 J/ l. r
- extern "C" DllExport int ufusr_ask_unload()
$ C3 |$ G1 y: \( q( i - {
( F* r( o3 A* [3 P/ t - return (int)Session::LibraryUnloadOptionImmediately;3 [* G1 K T- d
- }. ]# o3 M, o9 B; r( d8 W
2 z9 O( R: |& t2 _ K2 X- static vector<Point *> selectPoints(NXString prompt)
: f ?& X' O3 ?8 s - {
6 c; }# t3 x6 h* p" b" K4 e; E - UI *ui = UI::GetUI();5 m# j+ s- f. \+ x2 N. U2 P l
- Selection *sm = ui->SelectionManager();
9 p( W. o; ~: o! L$ n4 \ - std::vector<Selection::MaskTriple> mask(1);; {" [2 z2 `5 p+ ^8 ]4 d' P
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);) x3 o( M8 y' t9 ]( J" ]# X
- std::vector<NXObject *> objects;) e [: J# ^$ O
7 U5 R7 c% O5 ^, g- sm->SelectObjects("Select Points", prompt,
3 Z4 `) Y# q( t- a4 M: C - Selection::SelectionScopeAnyInAssembly,
8 d+ z7 a% ^6 \9 z: x5 v' B - Selection::SelectionActionClearAndEnableSpecific,, @3 c \6 D* b) R* Z" P
- false, false, mask, objects);# U$ W$ n8 ~4 o; f6 Y7 W
- " u9 l7 x) B" a4 x# G
- vector<Point *>selPoints(objects.size());0 S8 f* U8 |" F, ]! C
- for (unsigned int ii = 0; ii < objects.size(); ii++)
3 W8 X+ R+ g( d - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
, t3 @7 @) n; p: D) ]
+ `4 V8 [9 g! f& j' }- return selPoints;/ [) W9 X' j5 O
- }, r' \! R) P7 Q0 @$ X( u
! e- ~+ T: o& _/ Y( g- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). i4 F* j/ S2 [* L, J
- {. T. ~4 x6 C; a) A! X" p" c
- Session *theSession = Session::GetSession();2 K! z& T2 R) h J5 \7 P: c
- Part *workPart(theSession->Parts()->Work());0 P* n4 k" C6 r2 g$ a
6 B, b6 D8 Q3 q$ v- Session::UndoMarkId markId1;: b } S8 b# B. a/ y
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
' j( P3 H1 ~% V( ~+ ~: C - "Studio Spline Thru Points");2 |5 I' r- i3 S" `
- ; B8 |% R# c1 M' C0 p- G
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
) T' p* }+ [2 P/ k; b' V8 T: O
- h4 P% n, Y" g7 J1 @8 D- V5 ~+ l/ h- Features::StudioSplineBuilder *studioSplineBuilder1;
9 B/ b& u% Z W+ g - studioSplineBuilder1 = workPart->Features()->8 l2 m r% A B$ b3 d9 w6 M. R# E
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
0 A j& j9 z+ @( c \. h2 x# O% [: r - studioSplineBuilder1->SetAssociative(true);
( [# U) Z8 j k+ c - studioSplineBuilder1->
# C- u1 {6 _2 W; B5 F& E - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
, K4 L5 K! D- a. J; D - studioSplineBuilder1->
4 J- x: C0 d. R9 O - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);8 j3 @; E- {0 ^6 z+ |7 x$ }
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
2 a5 k2 N; d6 ?6 q5 s; L( z - studioSplineBuilder1->SetPeriodic(false);
+ u( `/ M0 P9 Q - studioSplineBuilder1->
+ c' O% \# m! N+ ?& Y/ U - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
: w6 \' m8 I5 O( X# Z+ r5 e6 a! t - std::vector<double> knots1(0);
0 p& P. k! z* i8 N. m - studioSplineBuilder1->SetKnots(knots1);
" {; b+ u# Y$ R& H# U$ ^2 M1 V - std::vector<double> parameters1(0);: F$ O3 }9 q3 s$ V( I
- studioSplineBuilder1->SetParameters(parameters1);" d# a J$ P/ e7 u; H
- Direction *nullDirection(NULL);9 i4 \ _) x* J" P# ^$ i' Z
- Scalar *nullScalar(NULL);
! F# b2 L% t5 M- K - Offset *nullOffset(NULL);
+ F+ Z/ X" V1 z; f' @+ l7 g# j4 I - 3 @% \% E% f K t$ i' h" c
- std::vector<Features::GeometricConstraintData *>; N# P* O$ r$ u+ F, T. r9 J$ _0 X
- geometricConstraintData(thePoints.size());
" x7 A. P, J4 E: F - ( U) E$ e0 G7 R( G8 E' \8 c7 t
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
, i$ A" V" Y' Y* O* E - {
9 @) L8 ] f# b% i3 N - geometricConstraintData[ii] = studioSplineBuilder1->- S+ E3 z |: C- c, c
- ConstraintManager()->CreateGeometricConstraintData();
: _5 W3 X* \. V5 ~ - geometricConstraintData[ii]->SetPoint(thePoints[ii]);/ a! b2 s8 w% q' v1 i5 k* {# ?) S
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(* ~/ n5 b/ @' y) p, E+ Q
- Features::GeometricConstraintData::ParameterDirectionIso);
. }6 H$ u" K, K/ M( y4 o# ^ - geometricConstraintData[ii]->SetAutomaticConstraintType(
7 m. {9 U: ^' e) @' u0 E4 { - Features::GeometricConstraintData::AutoConstraintTypeNone);/ P- P6 w, C$ J* {; B1 `
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
( ?- D3 S. j% r7 O - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ x2 i2 y+ g% }# o) Y W' P
- geometricConstraintData[ii]->SetCurvature(nullOffset);
/ U) r+ X7 Z1 ?4 T - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);7 j8 \9 J# W. r& M, @1 v i, a
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
" Z W" s7 g4 [ - }
8 X& Q4 u8 U) Y1 W4 O - ! x' z: y; w$ b) Q
- studioSplineBuilder1->ConstraintManager()->SetContents(
% Y T" }6 t. X6 A - geometricConstraintData);3 N* M0 d/ ]$ Z1 O
- " b% X. Z2 o$ S3 n+ i4 H0 r/ r
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();3 F' b& W( N9 n0 B; V
- Spline *theSpline = studioSplineBuilder1->Curve();3 |: ^3 O3 {+ h6 ] j
, o1 [, J5 o) W$ c( n5 `- studioSplineBuilder1->Destroy();
e7 f4 Q- U0 i: I& ] - , _9 G% z$ P0 L# l
- return theSpline;
6 W; s' c: {. h' y) W# v' A1 ` - }7 w" C$ H* I! X/ H8 [
4 c$ {0 k9 c/ p( ?3 O" D* i0 T- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
- G2 N. G9 W' h1 V - {6 w" p' R2 R4 F; D4 u% `4 s
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
* s4 r5 ~. H4 I - if (!thePoints.size()) return;% ?) q' [! Y+ O+ W
- + n7 r& U" c3 {
- Spline *theSpline = createStudioSplineThruPoints(thePoints);3 W) s2 E* j# a, a
- ) ~ a4 J x) c# [/ B& D3 u
- if (theSpline)
9 E4 ~7 J$ N4 }- F8 ] - {
5 \7 a: g3 X7 d" m - theSpline->Highlight();
8 Z q* [$ X+ c5 u: f- n3 D' U( ~0 K - uc1601("Studio Spline Created Thru Points", TRUE);
( P8 ^/ \+ g8 y6 K7 g+ h& b1 ]1 C. Q - theSpline->Unhighlight(); Q# w! {- K, M T7 F4 ^
- }! b6 U. H/ G, g8 A; Q
- }
* v1 c. T8 \7 Y
复制代码
$ j9 w. |* Y/ p( l
4 E# V, @1 ~ ~1 i% V$ \, v) L! g6 q& c* B# z
|
|