|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
; e% k5 N& i0 Q: g- #include <uf_defs.h>
. \! e; V. @2 } - #include <uf.h>9 N8 \1 x6 H q9 C# A+ d3 e
- #include <uf_modl.h>( Z# v$ y! t! b/ {- Z
- #include <uf_object_types.h>7 J* [) c, {! v0 Q- _$ u6 j
- #include <uf_ui.h>: Z, [+ R0 }/ \6 K' k
- #include <uf_modl.h>( Y; l' A+ J/ g* D6 V) p! E
- #include <NXOpen/NXException.hxx>
% i2 A: a# U0 P5 v0 R - #include <NXOpen/Session.hxx>
& Y! c. N; e* T+ A, f) D9 L( Q - #include <NXOpen/Selection.hxx>' c/ b5 l7 s7 G& l4 s
- #include <NXOpen/Builder.hxx>
" c6 ~7 E' e& T4 ]) z - #include <NXOpen/Features_Feature.hxx>
5 A2 K: F' a' ]1 V. \5 R - #include <NXOpen/Features_FeatureBuilder.hxx>
7 r5 F; D+ U2 v5 M! e - #include <NXOpen/Features_FeatureCollection.hxx>
, \3 n* U$ v5 U& L - #include <NXOpen/Features_GeometricConstraintData.hxx>
7 W( O& R6 @- A' C1 J; ~. ? - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
9 J; Z1 s c, Z - #include <NXOpen/Features_StudioSplineBuilder.hxx>, p. n. C9 s8 w0 W+ q" A+ r
- #include <NXOpen/Part.hxx>
! v( s$ ^4 ^/ Z, m, d8 f8 M - #include <NXOpen/ParTCollection.hxx>
' z# K1 Y; w6 r: O - #include <NXOpen/Point.hxx>
+ q) q& w* \( L - #include <NXOpen/PointCollection.hxx>
7 G6 _7 _) {& Y - #include <NXOpen/NXString.hxx>& f s. F6 f( ?2 A' f S& A! S
- #include <NXOpen/UI.hxx>% r$ F1 k% }0 o- k% l" r) C2 S6 m- F
- #include <NXOpen/Spline.hxx>! ~& S6 c( u& J! W1 e8 y
- #include <NXOpen/NXObjectManager.hxx>4 e; u1 G7 b6 @4 A7 D6 P9 t* t V
- ! Z, S/ U: h* G# j9 z% z
- using namespace NXOpen;
% _6 B0 }' v! F; |( _% { - using namespace std;
7 u1 v6 R5 }! d2 W0 M7 i
* F; p4 P$ r" ~: L8 {: P0 W$ u9 h- extern "C" DllExport int ufusr_ask_unload()
0 Y0 Z6 }# s; e+ r8 K" P$ p - {3 g6 G3 b! \. K I6 K" W) I
- return (int)Session::LibraryUnloadOptionImmediately;
3 z6 B; [0 \' K* {4 {' R8 y - }
. T& A5 T/ p2 f" V" w - 1 Z; t& n- ^/ m$ k
- static vector<Point *> selectPoints(NXString prompt)" a0 y2 q: s$ F( |* t" F2 r
- {
: r5 d3 E; u( I. K' P5 p; o - UI *ui = UI::GetUI();& j# s' k4 ^4 v9 k5 A9 V
- Selection *sm = ui->SelectionManager();
5 S! Q" z7 J+ \3 ~+ t& o( s ?* | - std::vector<Selection::MaskTriple> mask(1);, P' z O5 i& a9 i
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);' A: ~4 K9 J& ^% _
- std::vector<NXObject *> objects;
/ r6 o Y+ C4 V* Q" a ~
% G. D" _3 S: I1 m8 ]& B+ R- sm->SelectObjects("Select Points", prompt,
; {9 E4 V8 M6 G0 e7 Q - Selection::SelectionScopeAnyInAssembly,* V. T! g( n- |8 r7 C6 b) @
- Selection::SelectionActionClearAndEnableSpecific, `" }+ \4 c( U. X, ^% X; @
- false, false, mask, objects);
+ v% _8 W% m' o g% g
4 e; s; T: x" k3 x" N- vector<Point *>selPoints(objects.size());/ x4 j& _6 B7 h
- for (unsigned int ii = 0; ii < objects.size(); ii++)1 @1 x, f+ E n" f
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
" s( f* Y* B2 U; a7 @
2 r. p Z5 F; K3 z- return selPoints;( V [9 L' H* ~3 ]5 b
- }
8 a4 ?* K* o" s3 e( I
4 E1 j/ G4 l1 z8 T- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
. W" J) `6 Y* x - {! G$ b# z8 D# e- O( q7 \
- Session *theSession = Session::GetSession();* a0 m! h0 |1 \: j3 r
- Part *workPart(theSession->Parts()->Work());
6 o& g; g/ S' m# J! e: v0 l - ( @$ O& f4 V9 f6 M) Z
- Session::UndoMarkId markId1;6 h, z- P: Y7 F2 `4 I
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,% P3 D2 ?: J0 P6 k: S3 L8 U
- "Studio Spline Thru Points");
( G( ~% v7 A3 y - 6 d+ b, I1 M9 N
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);2 S8 {8 v5 V% x' N! v1 U7 T7 j
- 8 E, e5 F# I, S0 G i4 D
- Features::StudioSplineBuilder *studioSplineBuilder1;
* j0 E' A( `4 x - studioSplineBuilder1 = workPart->Features()->% b, M+ g7 N1 {# a# X
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
4 [& v& ^! p u" y - studioSplineBuilder1->SetAssociative(true);' K) r; K$ Q; n/ I6 ~1 p
- studioSplineBuilder1->
3 i: O* d1 {6 a- ^6 ]4 v - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; C% f3 S7 L* d) f A N
- studioSplineBuilder1->
2 V: V* l2 E2 K# M; W' K - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
& R, S. `% j0 l. _, S. J - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
1 n+ @2 R' @- _, p# G, s - studioSplineBuilder1->SetPeriodic(false);
' O! S3 }. q! Z" L) h - studioSplineBuilder1->& a4 T3 U9 p+ R
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. m$ R; t: g$ x/ | F& V
- std::vector<double> knots1(0);
7 `( ?5 a# Q% P4 Y# t0 ~ - studioSplineBuilder1->SetKnots(knots1);
# x% y, w; E7 f! I$ x - std::vector<double> parameters1(0);
+ r3 Q! Z { Y: A7 d3 P3 O9 t - studioSplineBuilder1->SetParameters(parameters1);/ ]1 r( t5 R% F$ p
- Direction *nullDirection(NULL);
. p9 T8 D: z7 b& {% t t, c& f& P - Scalar *nullScalar(NULL);/ x, e* ` ^+ w) F. `
- Offset *nullOffset(NULL);0 v: @& |* o7 u! R. J2 ? ]+ Z
8 T8 r3 Y$ k# C5 @& d' Q% b" X6 s- std::vector<Features::GeometricConstraintData *>
7 f; P/ u. @" Y3 K$ z/ `% ? - geometricConstraintData(thePoints.size());6 M; b. n& j% C3 P
- ! v, L1 Y6 ^7 j. R. a, W
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)$ y6 [' C# d; g/ l2 m
- {: T0 S" Y9 m# P9 Z$ m3 @5 n
- geometricConstraintData[ii] = studioSplineBuilder1->/ k' C: m( X5 B' b
- ConstraintManager()->CreateGeometricConstraintData();1 E) {6 v! M4 e$ _8 E( y4 Z
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
: @6 \! _# z7 B" J( x7 t - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
. R* P, c1 Z, S% c+ \- ]9 Z* M - Features::GeometricConstraintData::ParameterDirectionIso);+ P4 k0 r+ O( n: l7 }
- geometricConstraintData[ii]->SetAutomaticConstraintType(
# a5 ]$ s8 X; C6 R) P. e - Features::GeometricConstraintData::AutoConstraintTypeNone);
# n3 Y2 m$ H' ]7 ] - geometricConstraintData[ii]->SetTangentDirection(nullDirection);: o' e o) k, L5 t0 W& B4 M
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
- c0 I& t' K# c$ I) ? - geometricConstraintData[ii]->SetCurvature(nullOffset);* @2 O3 o5 C4 s* e [
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! Y# ?7 S2 O0 X5 b3 Q
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 @" W# {( ]' ^9 j8 a
- }: d3 x) ?0 g4 `! k; K, Y
" }" O& f6 M6 I, O" i& ?( @- studioSplineBuilder1->ConstraintManager()->SetContents(
/ A% Z" z& E8 a1 p4 {( P - geometricConstraintData);" A' ~3 O9 k2 v& U2 e
- % D3 L4 I7 j7 w0 C0 l
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
% A8 {. F0 r) m& B$ J - Spline *theSpline = studioSplineBuilder1->Curve();. M2 {8 s' F. V R: G( W
- 2 ^7 c& u, c* t+ K) S! f3 a4 p8 q
- studioSplineBuilder1->Destroy();
! _2 P* t" ?8 ^* Q& h' L Z& I - " `2 Y# C3 u. r. Y) [8 z7 F
- return theSpline;
- Y6 C- v4 t- f - }
; G6 J7 y* R: t. \( Y- v9 [
" t+ H; v8 s0 n5 {9 E, {' W3 Q7 K3 {- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)5 }6 M( j( G" w1 H' Q& m F
- {4 |" r9 R$ C" W$ z2 y7 P& C K0 k
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
0 ]1 ?2 W0 @; t4 o( o - if (!thePoints.size()) return;2 W* T" W. {8 o3 I
: M2 i) S1 t. b- \5 o6 t4 t! m- f- Spline *theSpline = createStudioSplineThruPoints(thePoints);
* t% c0 z9 P x ^8 _9 [ - 0 x2 m+ B' ?& y V6 M9 f3 S
- if (theSpline)
+ u( j% o; E5 R& f0 r - {
& g U& q' W" k3 h7 k2 F' d+ T - theSpline->Highlight();$ B% O! a) \3 u$ w# x% y9 Y( V
- uc1601("Studio Spline Created Thru Points", TRUE);
1 p+ R% S& ]" C- X; v V0 z7 [6 L/ U - theSpline->Unhighlight();
3 @3 `4 ]) t' [' j- I - }
. j! ?3 T+ \% s6 n# ` U' f - }
" p+ X# ]; i+ c" n% k+ K# s$ @
复制代码 2 I" R# ~- r" Y) W8 s! K
) W T+ K2 S5 _
% y. e! C; x# c/ ]" r; p2 i
|
|