|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
# l' {- a7 w% u- #include <uf_defs.h>
2 e$ @" N" ]$ R s Z' D - #include <uf.h>
$ S9 W) ~# v* _% i$ x/ z - #include <uf_modl.h>! U' A0 h, D) H- [% v, w
- #include <uf_object_types.h>" l3 V3 U, s& I# `2 I1 }
- #include <uf_ui.h>
) ?' X5 i% a4 P - #include <uf_modl.h>
& u3 w, i# C: O6 @ - #include <NXOpen/NXException.hxx>$ a2 e+ N4 L/ e4 w6 R% ~5 ^+ O
- #include <NXOpen/Session.hxx>1 t: x$ l, ?) S
- #include <NXOpen/Selection.hxx>6 s" @; p* L4 @- x$ K
- #include <NXOpen/Builder.hxx>! s5 o+ ?3 V6 S4 e5 a
- #include <NXOpen/Features_Feature.hxx>1 Y' f) G( l- H% K) ]6 @5 G% V" t
- #include <NXOpen/Features_FeatureBuilder.hxx>
; s1 @: L2 s1 \4 f$ t - #include <NXOpen/Features_FeatureCollection.hxx>& Q! q- o: E% Y( F; l
- #include <NXOpen/Features_GeometricConstraintData.hxx>
; m/ u, R5 Q- R# ?: M8 m8 v - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
4 p, T1 B o7 E1 w- ? - #include <NXOpen/Features_StudioSplineBuilder.hxx>
' s) o6 f' R& z q( O0 ~ - #include <NXOpen/Part.hxx>; T1 o8 W) i2 r8 @, f
- #include <NXOpen/ParTCollection.hxx>
* m: e9 \& Q: h0 o% Z - #include <NXOpen/Point.hxx>
- ?: \) @. I* `0 U" ] - #include <NXOpen/PointCollection.hxx>
+ K4 n7 ]; r$ z1 k% z - #include <NXOpen/NXString.hxx>( E/ S* }" H- l) |" [! ]5 B
- #include <NXOpen/UI.hxx>, h1 l( w ^+ Q; h
- #include <NXOpen/Spline.hxx>% p8 b x7 _5 |) X/ Z0 q1 P3 d
- #include <NXOpen/NXObjectManager.hxx>7 W% g, |0 v2 l+ j1 j
1 L5 m' ?# b( J; `8 D- using namespace NXOpen;" V1 |* I/ j! j S$ a! O) u
- using namespace std;
. L; r& f2 N1 N8 k; B8 F
1 T. }6 T. Q5 ?/ |# @- extern "C" DllExport int ufusr_ask_unload()
# n d# d* V, _5 J( Q+ _ - {
: d! T1 J* i$ ?6 U) x) F3 S. } - return (int)Session::LibraryUnloadOptionImmediately;7 f6 ~' R# a8 h3 y8 A- p
- }! ^; |3 L1 f8 p& w2 R# I
- w* y( P+ p' J/ v6 S- static vector<Point *> selectPoints(NXString prompt)
3 G, D/ r" N. C% o$ L' h: Y - {
2 h) O0 F$ u" K6 A4 w1 V0 I - UI *ui = UI::GetUI();
4 E2 c5 e6 a$ e% s+ D - Selection *sm = ui->SelectionManager();( k: }3 u% {$ O/ X; ?
- std::vector<Selection::MaskTriple> mask(1);
% L8 f' t# d6 u6 F' K. _ c9 _) @ - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
! \* x, y8 n3 P; v9 K- X - std::vector<NXObject *> objects;
+ Y9 U1 n- a3 L* a+ F' k- r - : o8 z3 z" e$ |7 I$ y H2 ^2 `( z
- sm->SelectObjects("Select Points", prompt,* _2 V3 G" \1 ^
- Selection::SelectionScopeAnyInAssembly,
2 s5 g3 G1 B$ M/ B1 k& n6 n; z6 s' l7 g - Selection::SelectionActionClearAndEnableSpecific,1 ^5 V2 M5 Y5 |- H
- false, false, mask, objects);. x. q! K) H9 {- I. U
- ; J2 r7 e4 T0 `
- vector<Point *>selPoints(objects.size());. I5 a7 O+ ]: ~
- for (unsigned int ii = 0; ii < objects.size(); ii++)
4 ]3 m9 v" c, @8 c! B" ? - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
" {0 b1 P. v' P2 e+ U" { - ]$ J/ \) a1 G j$ c4 K) Y
- return selPoints;6 A) t Q- Y0 O6 N1 Y( w2 g
- }
" {* u" n# K$ {" h% l& Q4 }* b J
3 o0 X, J- I8 K6 Y k- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
, i5 L6 e# t x, m% `9 t* C/ H - {
2 A3 o6 r- d# T5 b& ` - Session *theSession = Session::GetSession();! _; i E# F- D! f4 K
- Part *workPart(theSession->Parts()->Work());
: e0 @( F" E$ P - / y- U; N5 }: m& ~) ?5 Z2 f
- Session::UndoMarkId markId1;
2 n5 U5 b. _! u - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
. O: m2 C$ \/ a - "Studio Spline Thru Points");+ F4 ^! S t4 P1 J3 X
1 H& C/ ~# o9 \1 Z& d3 l) F- Features::StudioSpline *nullFeatures_StudioSpline(NULL); p( V9 O- u r2 U0 z o% f- K
- , J0 \: b- U1 W% N, q' C
- Features::StudioSplineBuilder *studioSplineBuilder1;
2 m6 ]+ D1 g' {, c9 B - studioSplineBuilder1 = workPart->Features()->
# }( H3 U1 M1 _% Y+ I - CreateStudioSplineBuilder(nullFeatures_StudioSpline);7 S; E6 g6 R9 @
- studioSplineBuilder1->SetAssociative(true);
' N9 i C1 f/ X E! d - studioSplineBuilder1->7 m' w4 l; F5 w" l2 M- m0 g# m
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);& L1 u8 W% @- u9 B* o4 a9 G8 |
- studioSplineBuilder1->/ K+ B3 a- ?% [( D! j0 }8 ^/ O
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
% Y7 ]& m8 ~( f2 m" U" j1 e+ s - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);. H# x& _0 c: m5 E# T
- studioSplineBuilder1->SetPeriodic(false);
9 s2 q; ?6 I. P - studioSplineBuilder1->
* x. S8 v0 _; q# L @, p# Z. |6 [ - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);% }1 R: N* n# w
- std::vector<double> knots1(0);
. ^0 L; C4 M1 a" n - studioSplineBuilder1->SetKnots(knots1);: k3 X/ m# n! {+ B3 [
- std::vector<double> parameters1(0);
- G0 ]( j: {5 N; F - studioSplineBuilder1->SetParameters(parameters1);7 Z) ~' K, e9 I/ F$ t
- Direction *nullDirection(NULL);
" B2 o. u) ]. t8 C* v3 i - Scalar *nullScalar(NULL);
/ g9 B: K) @, Z* n1 N3 g: z7 Q - Offset *nullOffset(NULL);' @1 ?( z! @, ]
" X$ l9 |4 O$ w% P( Z) F# C- std::vector<Features::GeometricConstraintData *>
* \2 W+ ^% d* O' E+ C" B8 y- W9 z - geometricConstraintData(thePoints.size());
( V* S) S7 \- S! V: w* r
. z1 v7 V1 {! [! W4 ^' t: u" A$ D: g- for (unsigned int ii = 0; ii < thePoints.size(); ii++)4 ~! D0 ?; {/ q9 [4 m! W7 B
- {
9 I( B( g* Z d1 g' X8 { - geometricConstraintData[ii] = studioSplineBuilder1->4 g4 z* |; C. G
- ConstraintManager()->CreateGeometricConstraintData();
& ?# A: b r4 `# U- p( _ F" I - geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 r, C' R) d/ f
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
# s4 d& Q: p/ E - Features::GeometricConstraintData::ParameterDirectionIso);
3 b/ Y) z8 }" ?% B8 G J2 v! E. g - geometricConstraintData[ii]->SetAutomaticConstraintType(
# n, ` |+ L7 ?6 U- S9 D - Features::GeometricConstraintData::AutoConstraintTypeNone);! n0 P1 T1 z$ Z4 [$ j( T
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);! [) g0 W5 r: }
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
9 t" X$ U2 d$ n+ r - geometricConstraintData[ii]->SetCurvature(nullOffset);
$ Z1 s) K% Z }+ j. j: h - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. k8 @8 G: k% Q. f) n) h! k s+ l
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
5 m/ O& V8 o; Y - }& t1 u$ e' M, q# r% N/ [% h
- 3 Y8 K/ H9 f4 u% N% G" g
- studioSplineBuilder1->ConstraintManager()->SetContents(- j3 M/ D2 ]: a4 K# M/ m9 y8 z" [8 l
- geometricConstraintData);# K! B3 `- w: v8 P) s8 u
# E+ b% y7 ?) O: j0 j4 o; l: A- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
6 f9 E. V+ K8 F( c) @1 Y - Spline *theSpline = studioSplineBuilder1->Curve();
) ~( q$ I7 F6 H& J9 q5 w2 W
! `/ z& t' T, T8 [+ l- studioSplineBuilder1->Destroy();' K9 x( M7 ?2 C1 ^5 \ x; V
- ) p" `' I) O, w
- return theSpline;
: I9 @: ?3 ^7 d0 w# M7 ?. P" w - }) e4 q! r! P- D
7 B( n q2 I8 j' _/ m- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
2 L# |0 k. Q, m - {
. n; U3 a9 `$ ~# {" j - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
( r" P- v7 Z+ b' o3 l/ K5 z" I6 ] - if (!thePoints.size()) return;8 m0 S/ e+ Y0 _6 G/ I" z
: K7 _- e* Z3 M/ @0 D! W6 A3 B- Spline *theSpline = createStudioSplineThruPoints(thePoints);; p9 o# E, T* Y4 Z
( @# K; |5 Z1 D H- if (theSpline)* `1 V0 o: u2 R6 X- [6 ^$ D
- {+ q5 Y( }+ [0 c4 @
- theSpline->Highlight();
3 v4 {* D) e4 t' ~+ m: G+ E$ M - uc1601("Studio Spline Created Thru Points", TRUE);
9 o) F. Z/ j5 J - theSpline->Unhighlight();' W, g$ r; i2 l
- }
7 e& x% p) B% m! M - }8 Y4 S/ a0 {: B! |
复制代码
: X8 w# h0 y# h0 k
# Z) t' a% F) E' D# f" b
$ |8 `0 ^0 A! e8 r% y |
|