|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线, k2 S. G2 c2 |4 Q
- #include <uf_defs.h>. E: S/ ^7 f* a- Q7 e
- #include <uf.h>3 ?- F S1 T$ q( e, p" Z
- #include <uf_modl.h>
% }' ?4 T& K' E! X7 q! I8 _ - #include <uf_object_types.h>! D6 p2 `0 b9 L5 ]7 F7 d& w( M1 T
- #include <uf_ui.h>& ]9 J* q+ ?; {1 F$ D7 K$ Q
- #include <uf_modl.h>
) l; f. H* ?+ J ~ ^& n5 l6 ~ - #include <NXOpen/NXException.hxx>
( E. R+ q/ l2 s' F$ u& D( Q - #include <NXOpen/Session.hxx>
/ d; ?, Y3 m7 }% G0 J - #include <NXOpen/Selection.hxx>
! c' }+ B* N% n' O - #include <NXOpen/Builder.hxx>) x- x9 c \( S# x6 J9 o
- #include <NXOpen/Features_Feature.hxx>6 q& \# @" H" D+ @% x/ N
- #include <NXOpen/Features_FeatureBuilder.hxx>/ t3 y7 F% G7 \4 m; { O
- #include <NXOpen/Features_FeatureCollection.hxx>" G f1 ^3 h7 e' |1 P- y9 ~# @& w
- #include <NXOpen/Features_GeometricConstraintData.hxx>& Y4 Z5 V% T+ W% C4 F, h1 o8 v) K
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>- d9 D& z5 F; j# D0 N% m9 a4 r
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
6 l3 {/ ~( T* ?. y0 R# S - #include <NXOpen/Part.hxx>5 b5 }$ P3 R) Z
- #include <NXOpen/ParTCollection.hxx>
- l1 S* W8 x+ i# K/ ?3 z$ k: C - #include <NXOpen/Point.hxx>+ W0 M8 z; O7 [: L. e! J1 n
- #include <NXOpen/PointCollection.hxx>
* Z( q7 a# f+ ]" T( U5 M - #include <NXOpen/NXString.hxx>
/ r: s( u: F- f+ g" A5 k - #include <NXOpen/UI.hxx>% b& B5 A. [" V+ p p
- #include <NXOpen/Spline.hxx>8 |$ \9 W' ^* m7 H" l
- #include <NXOpen/NXObjectManager.hxx>) l9 V q% t( Y& ^- M( ?* f( t
; r7 ~9 |7 H' }1 E& ~% l4 S) M1 o- y$ j( u! Q- using namespace NXOpen;
, u' w B0 l) G5 Q' p7 Z - using namespace std;/ w2 v% D' [3 F3 ]
+ a9 @% r, P2 N# h! D- extern "C" DllExport int ufusr_ask_unload()+ @$ E% A8 n; R' K' v
- {% _, I8 l2 F7 Y3 e0 m" E) O9 A
- return (int)Session::LibraryUnloadOptionImmediately;2 G0 O8 C1 W% W/ {2 [0 D
- }& t2 L1 r' D- [
# x% N- s2 ]" W( `- static vector<Point *> selectPoints(NXString prompt) h6 E1 I* X) ^# {% Y, `
- {
4 M* |8 s+ d* r) f2 y: S- A5 ^. v - UI *ui = UI::GetUI();# J f9 u9 z+ s, z0 ?0 P1 I
- Selection *sm = ui->SelectionManager();
% V; d* T9 Y0 |8 U: O# V$ b0 B$ s- O - std::vector<Selection::MaskTriple> mask(1);
! _9 \* w. K1 T K4 A+ L - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);5 F3 K7 U/ o3 l7 ^6 A$ {' ^& }( F3 q
- std::vector<NXObject *> objects;# v, M6 R9 s' _
) T* S& z) ~0 i* y8 G- sm->SelectObjects("Select Points", prompt,
% Q- Q' [6 u: f* O8 ~ - Selection::SelectionScopeAnyInAssembly,
" c+ a# A `: t) J1 o, u# I; A7 ? - Selection::SelectionActionClearAndEnableSpecific,- P1 I# r6 E: m' c* c1 A3 O
- false, false, mask, objects);* u- b& H/ K: c8 w/ @
3 w7 a0 W0 i" |2 ?- vector<Point *>selPoints(objects.size());
! ^$ b) E! D# ~, T: m. g( i - for (unsigned int ii = 0; ii < objects.size(); ii++)
4 a: K( v6 Y2 u# V2 u. v) S - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
) ^" j3 C. w& [0 X - ! ~9 Z, O2 i* U
- return selPoints;9 ^( ~; g! L( E6 z$ v {
- }
5 q/ a# f( d* l* U3 Z8 a - : _5 ]2 p: c# `6 p2 p4 m# C
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
' x' t% X# d* K6 T. b1 \ - {
3 \* c9 Q, K2 P- j3 @' n - Session *theSession = Session::GetSession();' v, V# _0 m' }9 A
- Part *workPart(theSession->Parts()->Work());
8 P* n* h7 k1 \9 f& p* a
/ B4 N8 F& J6 q- Session::UndoMarkId markId1;& f/ E( e$ m) I4 x9 N
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,7 x9 q! b/ E8 f: |, x; ^" ~1 {
- "Studio Spline Thru Points");
9 N2 z, q! T9 j& F1 V; | - : K6 V! p* n3 Z6 Y
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);' _. \- G% ?* ^. Y$ {9 K
- / C/ ]& ?: n `( E
- Features::StudioSplineBuilder *studioSplineBuilder1;
8 B6 z' M) @" F6 O# X+ ~( B. z - studioSplineBuilder1 = workPart->Features()->/ z; k) {2 h6 S H) R! K1 N/ C3 T
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);, N% Q: Z3 ^) }" N7 ~& H( R
- studioSplineBuilder1->SetAssociative(true);: ^1 E% _1 P$ w2 x& W& ?
- studioSplineBuilder1->
+ t8 W: ?. c0 C5 o$ X - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
! U2 ^5 ]" d/ f( m - studioSplineBuilder1->5 z3 A: H& k4 T8 ~" o- o
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 U+ y4 W7 v, g6 I
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
* P6 h" E0 F6 m+ B) O1 F - studioSplineBuilder1->SetPeriodic(false);
$ c+ |* ~0 r) K' n# O - studioSplineBuilder1->6 z- X( o( K. [5 b- m
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
: y! _, u& e* x, \# \( j( R - std::vector<double> knots1(0);3 @7 A# s! Y& J0 ^0 _- C
- studioSplineBuilder1->SetKnots(knots1);
3 K1 k9 j) }$ `) _ - std::vector<double> parameters1(0);
7 U7 @4 P R2 @5 f/ m+ b3 T; X - studioSplineBuilder1->SetParameters(parameters1);
1 T5 u; N P4 |3 |6 K - Direction *nullDirection(NULL);: R% p h! s9 _* M ^! N
- Scalar *nullScalar(NULL);, m1 K8 ^2 A4 a6 n9 x6 m/ L Q' u
- Offset *nullOffset(NULL);
2 X+ Q6 \" T' K. M# ` - 2 \: L: S7 P/ V* `* W
- std::vector<Features::GeometricConstraintData *>
$ F. K& W( d j$ J/ [ - geometricConstraintData(thePoints.size());5 E. _. b4 v, s$ @. S/ x f4 R3 I
- : `1 H* D, Q% t
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
! F0 |5 T2 G1 m& C3 r. y - {
' u& |+ @' b% t+ | - geometricConstraintData[ii] = studioSplineBuilder1->+ O" W* O! I. ]/ J
- ConstraintManager()->CreateGeometricConstraintData();8 y: ]& D) g$ ^0 J8 P
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 ^3 e' c [& D+ w
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(" Z' {+ {8 ~' }- L3 U
- Features::GeometricConstraintData::ParameterDirectionIso);# d: `1 K; F/ C( ?
- geometricConstraintData[ii]->SetAutomaticConstraintType(
G6 k1 n5 _) z' Y7 L! f7 H# _ - Features::GeometricConstraintData::AutoConstraintTypeNone);
( G! s% K2 }9 [7 w - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
, l1 v! p- t0 b - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
! L z. x# _9 H0 @$ D" | - geometricConstraintData[ii]->SetCurvature(nullOffset);
: I" c. X8 M f8 k1 t+ {/ O( m& u, @) f - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
2 x, a, |+ V$ [0 ?* P7 g: q - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
2 m I' w2 q( I! K9 M, D8 ^( ] - }
: J* ^2 @6 H5 c+ { - 6 L. J4 [/ w% y, I
- studioSplineBuilder1->ConstraintManager()->SetContents(
( C9 E3 H8 |' z- X, |' S, G! _! |, d - geometricConstraintData); r6 A/ r: S1 Y% Z; _6 b# N& v
7 P3 r R/ r: s: x- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
: x- u, T, S) p+ x, k8 T/ f6 s+ d2 F - Spline *theSpline = studioSplineBuilder1->Curve();4 G$ D) z* W( q! b9 \
- 2 E* N" H6 Y( u
- studioSplineBuilder1->Destroy();, T1 N1 k% w! N1 u
- 5 m! \7 m& i I& Q0 p% q t. q
- return theSpline;8 E. O2 f4 a, l7 L
- }
! C: E2 x- L( W- _ - 3 C! B+ I' @7 S s9 o. t7 a
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)0 X7 x) R' K) |( m. {2 K( Y
- {' ?! }5 _ U/ {5 F0 x+ l4 t4 f& G
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");/ B9 Q- r# r' ~: L
- if (!thePoints.size()) return;' J; h# `/ D8 T( ~) ^
- f6 {) {: r: t" ]+ Z& ~) b* O- Spline *theSpline = createStudioSplineThruPoints(thePoints);
) \6 I! E+ X: Y" s
. j1 \% ^, D, T* Z- if (theSpline)
9 L7 F8 v6 D- ] - {$ |- F) f7 p1 \+ O# r- k2 y' V
- theSpline->Highlight();
1 u0 k& |9 x& ~; t W# m( m/ e1 l - uc1601("Studio Spline Created Thru Points", TRUE);
" P- V, R9 p1 u - theSpline->Unhighlight();
0 @* M: Q* V& p: b. E - }
# y- I' E" N) ]) O" V. `" m - }5 J( f! U7 L" \; {( y6 ?# I9 A
复制代码 & ]# J" ?% w$ T3 X
4 E& ^: G& C. E& Y/ o2 u( d
# z7 D O- `# {: F. ] |
|