|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
& ?- j3 z k8 \! r1 l. A- #include <uf_defs.h>
) ]' y+ `) z; q; V- m/ ` - #include <uf.h>
! ~! B+ V G7 ^( H9 _ p/ Y0 ] - #include <uf_modl.h>
$ e4 U, @! Y; W! y* O7 r$ `/ Q- k - #include <uf_object_types.h>
7 C" ^+ u. l. A! k - #include <uf_ui.h>
* p) G; [' K7 b, ~/ C0 S$ v$ e - #include <uf_modl.h>
# @1 I: ^( e3 t! B) V4 ^; t - #include <NXOpen/NXException.hxx>
( F1 g# d3 L: p+ H7 d4 \ - #include <NXOpen/Session.hxx>
' d7 U) G' J/ [& w( N% b! u - #include <NXOpen/Selection.hxx>+ f( R. S8 I6 o8 U$ {
- #include <NXOpen/Builder.hxx>4 [7 y/ X Z' |0 D9 B
- #include <NXOpen/Features_Feature.hxx># D# e7 Z$ K$ ~# B+ W
- #include <NXOpen/Features_FeatureBuilder.hxx>
2 H$ A$ H. z- F' y* b p5 ~6 r - #include <NXOpen/Features_FeatureCollection.hxx>' r5 x& g. K' [* w
- #include <NXOpen/Features_GeometricConstraintData.hxx>7 L! F9 N0 ]/ v1 L# I" u
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
5 @- C3 k7 a7 Y% Z9 i# j - #include <NXOpen/Features_StudioSplineBuilder.hxx>0 d4 O; d! H+ h0 x9 u
- #include <NXOpen/Part.hxx>
( b. W7 r9 L5 }. U- F - #include <NXOpen/ParTCollection.hxx>2 g5 y T. b* b1 d, b3 ]5 b
- #include <NXOpen/Point.hxx>' h. H4 x2 d; ^* A" H# \, s0 C4 Y
- #include <NXOpen/PointCollection.hxx>
' U# J" h; H3 } - #include <NXOpen/NXString.hxx>
, q. u7 h2 B5 f" ^4 N, C1 s" Q - #include <NXOpen/UI.hxx>8 \1 P& ^, P. c. \
- #include <NXOpen/Spline.hxx>$ f! R9 i) H) P' t U+ S
- #include <NXOpen/NXObjectManager.hxx>0 g) Z2 T$ s" A; {
: F% Q& `; g+ c4 E- using namespace NXOpen;% H2 f* B' l# N" N
- using namespace std;
# R9 ^% u% y9 v( j2 q1 y. { - 1 t' d& k9 s" \0 c! N
- extern "C" DllExport int ufusr_ask_unload()6 ]1 u; r' d8 O7 `3 T% ^: P, Q
- {& v% K" E4 \" W% ~* e5 V
- return (int)Session::LibraryUnloadOptionImmediately;
v- R5 E* N3 ]+ D% O. j! J8 x! R - }
. T4 P2 P% L" Q0 g R - 1 t# ~( B' \* ^
- static vector<Point *> selectPoints(NXString prompt)
- ~. e c) p! y" L' @/ {- p) z - {
! F: @. Z# {1 C2 N { - UI *ui = UI::GetUI();8 B# @: C, `3 w3 J+ z2 [8 J$ ]
- Selection *sm = ui->SelectionManager();( [2 p" m5 A; r0 J$ S/ l# Y# E& X. t3 ^
- std::vector<Selection::MaskTriple> mask(1);
^# n' @! A% B - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
' B5 H3 X; M& r3 D+ _1 j2 l4 b0 t - std::vector<NXObject *> objects;
/ ~& N/ o F" V; z3 ]5 D6 `, p
9 o f8 @5 F' a* L" f- sm->SelectObjects("Select Points", prompt,
, F4 E& ?! q5 i5 p) s - Selection::SelectionScopeAnyInAssembly,- U9 \# @# { B
- Selection::SelectionActionClearAndEnableSpecific,
0 f ]- D, ^5 Z" W0 O R8 g - false, false, mask, objects);. ~, @/ ^" A1 s. ~/ k2 c
- % U- j) C5 V) \- ~
- vector<Point *>selPoints(objects.size());
% k2 u1 m7 Y# N- \ - for (unsigned int ii = 0; ii < objects.size(); ii++)
; I+ H7 r+ b) c0 q$ D1 ?7 P. T - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);; G" P6 }! T6 g
2 v! ^8 Y- [$ O( C: I- E7 @4 A* ^- return selPoints;
; u3 f# Z' v- k" s6 S5 q# u - }5 ]: @; `% d* k3 e0 q
- 5 Z9 c7 h: Y7 P# h' Y( i& c
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
) \. D$ p P. L/ H: C& B - {
$ n' b# \' }: z! }, v3 m6 } - Session *theSession = Session::GetSession();. V- J. I2 ^3 n, c
- Part *workPart(theSession->Parts()->Work());$ U) G0 {) S6 s" ?& _% `) g
8 R2 N ^+ S- s; `( u% I6 p! v) V- Session::UndoMarkId markId1;
. K: c& o5 l7 E - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
0 q/ ~# s* T8 N V. e - "Studio Spline Thru Points");' y4 s( K" @- X" A# f
- / z* H' X" |& [$ ]5 x6 u( C2 x
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);- ~# ~; K w: I9 J3 s# a5 L- r R
- " v1 a ]6 Q" n
- Features::StudioSplineBuilder *studioSplineBuilder1;
* R2 d' ~/ L% ~7 q! w7 a - studioSplineBuilder1 = workPart->Features()->
+ M9 W( w$ ^6 f - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
9 j. S0 b7 n& @; G+ P) l) | - studioSplineBuilder1->SetAssociative(true);
1 B* y; H$ y3 d* M B+ q - studioSplineBuilder1->3 ~& D# ]4 c; W+ }
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
+ C. `/ O; _9 n, h7 G1 h% n - studioSplineBuilder1-># n& a1 z8 v+ E& s H! T0 ^
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
1 \- P* q2 C- ?( U( V/ o8 b - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
! z: b# F+ {! n0 a c - studioSplineBuilder1->SetPeriodic(false);9 I' J& g5 u, u- L% o
- studioSplineBuilder1->% h" S9 S6 @) _( E" {( H
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);3 h3 c K- A. u/ ?8 G8 d! a
- std::vector<double> knots1(0);
8 a& }) t3 y( P9 x$ h - studioSplineBuilder1->SetKnots(knots1);% x' `5 U; Z g# E$ }$ z
- std::vector<double> parameters1(0);: t* n7 f$ X7 n) r( W( ]+ ]
- studioSplineBuilder1->SetParameters(parameters1);
, q) j" H8 P+ l* S" z( e" \. c - Direction *nullDirection(NULL);
8 n8 {) R/ V/ u& ^& C _1 A% ]6 g - Scalar *nullScalar(NULL);
1 c- E3 s5 D& q- s5 a - Offset *nullOffset(NULL);
; \: u) O" G0 Q: b* s9 h& _6 e$ c - $ b+ h5 n5 ]0 N4 G7 f. v: E- k8 S
- std::vector<Features::GeometricConstraintData *>
6 B) S/ h& Q3 }* P1 |' y4 Y+ \$ g - geometricConstraintData(thePoints.size());
2 t- H" k1 I$ | ?+ f X, k# T
8 a1 T" t& _0 | b- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
- @7 f/ }4 ]3 A/ E - {
2 I/ a. t( j0 }. p! k* Z - geometricConstraintData[ii] = studioSplineBuilder1->) C) a: d3 d7 ^: f q$ ]
- ConstraintManager()->CreateGeometricConstraintData();
/ n. o0 B( h" r+ d y! x - geometricConstraintData[ii]->SetPoint(thePoints[ii]);. w" i1 p, P* n! h, [9 l" B7 J
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(( G, `0 ]% S( i# p4 `
- Features::GeometricConstraintData::ParameterDirectionIso);
/ W8 {5 Z; N6 C" _ - geometricConstraintData[ii]->SetAutomaticConstraintType(4 ~0 B2 F: M( a' w& q' H
- Features::GeometricConstraintData::AutoConstraintTypeNone);% y: C( \6 u* F( n# z
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);& l5 o- h- n) Q6 [9 {' \ o! }/ t& n
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
) @) i* q2 t% U5 ^7 n, q+ f - geometricConstraintData[ii]->SetCurvature(nullOffset);
# N& ]9 a1 d$ t1 Z - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
' K, Y5 o1 m9 J x' C. \, Y( Q - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
( T; V7 p# A* N4 f9 U - }
( K2 i. ?. L; ~) `9 s - 0 u, J# F6 d7 n! `/ P& U8 H4 F
- studioSplineBuilder1->ConstraintManager()->SetContents(% M. e7 M7 @, `6 ?& W7 V& m J
- geometricConstraintData);4 D; f- J' M' N
- 0 }# ~* G" i- N! j6 D- a! ]
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
2 _, B2 u0 q' y6 R - Spline *theSpline = studioSplineBuilder1->Curve();
5 H% v( n5 ^* M
$ E; N- Y) o. @4 l) R8 w- t$ k8 `- studioSplineBuilder1->Destroy();
5 _2 A4 l" D+ P! ^) x
: o" k: K* k$ z8 k* K4 e! j+ R3 N- return theSpline;
* z* `. w, |; S/ W9 [ | - }7 r* ~6 m C( P; [) j" N" {6 {
- * \- P) l2 w& r& r
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
8 \; V/ e$ D5 N3 w; Z l - {
) c( T/ g) x% m5 f2 J$ O6 J- ~& q - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
3 d/ @( ~, `) F6 y7 z( j4 j3 G - if (!thePoints.size()) return;5 j8 n' X4 g8 v, h4 _" g
- - J! L9 ^$ I% U) `+ P3 S
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
2 g' m; [7 j. W# d5 o - ; d* E) k: U" L( u( \* a
- if (theSpline)3 d2 X( e) T3 R& U9 t" K
- {
. F$ P8 k! \8 B8 m - theSpline->Highlight();
3 N/ I- N( f8 q2 s3 q" [ - uc1601("Studio Spline Created Thru Points", TRUE);
; @3 T# K' |* W' G6 j - theSpline->Unhighlight();
$ P" O; A# h. W x - }
( O0 K' w4 P' G8 J - }2 i2 c$ L+ O; d/ L: e
复制代码 " X) K1 S4 q& ?" ~' n
1 N. q) A" a" W0 K6 E6 X5 n3 ^5 X3 U1 h7 k, {2 Z3 V/ U
|
|