|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
7 F5 @0 F6 ~1 ]+ w( _& d6 M- #include <uf_defs.h> y' U# b, @& L, S( D( c! s
- #include <uf.h>; x/ `# F3 t+ Q9 [% V4 F8 U% `
- #include <uf_modl.h>
1 ^8 c0 V1 K* Y3 i% n - #include <uf_object_types.h>
, D2 w, [$ G g( v - #include <uf_ui.h>: H5 F: H) P% l( Z0 v* {" X
- #include <uf_modl.h>
( M* o$ s6 o- L0 A6 Q - #include <NXOpen/NXException.hxx>
( K5 d1 F, K% [) G4 k - #include <NXOpen/Session.hxx>! v8 \+ s: U: W: t
- #include <NXOpen/Selection.hxx>
5 Y- r% J! C/ H - #include <NXOpen/Builder.hxx>; v/ b2 e, ]1 I3 y) w" p
- #include <NXOpen/Features_Feature.hxx>
6 D$ @" f( `' y4 Q, J3 I- r( [ - #include <NXOpen/Features_FeatureBuilder.hxx>
4 K- y: y. L- g2 S; R - #include <NXOpen/Features_FeatureCollection.hxx>
6 \5 O* \- T5 ?4 l& A8 M) u - #include <NXOpen/Features_GeometricConstraintData.hxx>5 P+ e8 v( ^- I8 P5 Y
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
: {( q( K) y2 ^1 \) Q( y - #include <NXOpen/Features_StudioSplineBuilder.hxx> \# Q5 U, k$ H/ ~" Z& [
- #include <NXOpen/Part.hxx>2 i8 U1 _. |/ s! }. J- V! o
- #include <NXOpen/ParTCollection.hxx>; n9 v4 g% g4 f7 X0 }" Z
- #include <NXOpen/Point.hxx>( I: E; u0 Y/ k. \
- #include <NXOpen/PointCollection.hxx>; ]9 {/ M. @# X+ w
- #include <NXOpen/NXString.hxx>
: Y& T$ {; v$ _3 n7 K - #include <NXOpen/UI.hxx>
! x7 A9 W5 O1 x& J" k' o$ f- y - #include <NXOpen/Spline.hxx>2 D) b3 A6 M% f. e
- #include <NXOpen/NXObjectManager.hxx>2 A3 S5 d3 A) @: ~, r
4 u k3 {0 u8 y- O6 e% y. O- using namespace NXOpen;
; y E1 |: A0 X! [1 X - using namespace std;8 G2 T5 R5 G" F9 w/ v
- 6 n/ f, }4 h( D* C$ ~ u
- extern "C" DllExport int ufusr_ask_unload()
0 S) g3 U1 y) q: A+ Q! S - {' V; |/ |6 a/ b: F9 l2 o2 ]
- return (int)Session::LibraryUnloadOptionImmediately;; i8 ~: x5 P6 y' B8 [5 A
- }% K1 b! }+ V$ e& C$ M5 O
- 9 Q! i& R- M: K5 O( f" \$ E
- static vector<Point *> selectPoints(NXString prompt)" v, ]1 W8 n) ~, E4 b
- {
7 _) N0 C7 P! L& o Q/ ]6 l) T - UI *ui = UI::GetUI();
, A6 N7 I9 D- l$ G& u1 P - Selection *sm = ui->SelectionManager();% X( a) _5 D) n; A1 p+ g6 G
- std::vector<Selection::MaskTriple> mask(1); R: r2 A. C( ~+ ^) [8 i
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
: p" j* {% r+ Q- S$ B - std::vector<NXObject *> objects;0 o5 F4 `" W7 A
- ; d; X; P( t$ _1 U
- sm->SelectObjects("Select Points", prompt,& I) ^7 S% y6 T/ m
- Selection::SelectionScopeAnyInAssembly,
9 [) A; F! x4 ~; R" u- c - Selection::SelectionActionClearAndEnableSpecific,
$ K( z3 \, A! o5 d: q8 D9 Y, m - false, false, mask, objects);+ M$ B6 L7 g/ C# a8 v5 |! i! u
- 5 ?7 g6 x! H1 u Q) ]( i
- vector<Point *>selPoints(objects.size());/ R3 b3 [9 J. y, L
- for (unsigned int ii = 0; ii < objects.size(); ii++)
) {2 }& l8 |, }! G - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);: Q( z- C. |$ T* ~4 B) Z6 [, q
- 3 `8 }7 y4 k6 \! i$ p3 ^; G
- return selPoints;
6 M# K5 _5 c, P; G# z - }
! v* K) u K+ b# X
' B2 n+ V* Y7 k+ d3 [. Q- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
1 ^: _6 d# _ K: [, c - {
* l' l7 j2 `8 I4 K - Session *theSession = Session::GetSession();
; `4 I; g7 A; ~$ b) t+ x - Part *workPart(theSession->Parts()->Work());
- ^2 n, S- }8 k5 u* Q8 [8 [' W
+ a: A& n+ I# _0 T0 i- Session::UndoMarkId markId1;5 }* P: C4 @+ b
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& a z' L3 m7 v. k" L
- "Studio Spline Thru Points");- x; c8 J4 Q3 V i
- 9 L" Y% C8 k* a0 H2 [
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
* r' B) Z, I" g0 e& r7 v4 l - / q$ A5 }$ e8 e% R+ {0 H R. L. ], t& [
- Features::StudioSplineBuilder *studioSplineBuilder1;, M8 b# Y# }; C9 h" g" ]6 S
- studioSplineBuilder1 = workPart->Features()->
! p- b- C1 D* K( X - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
i2 F7 @) } j+ V - studioSplineBuilder1->SetAssociative(true);/ ^ f- X+ w" F( s4 t
- studioSplineBuilder1->" M6 j1 Y; ^3 e8 g
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);- v# ?/ k8 ?9 d* ?4 P0 L& l2 b
- studioSplineBuilder1->
+ Z1 W4 O6 V6 [/ D1 o" t - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
! [" O+ p: C' e* L. z4 u - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
( r9 T7 y# |5 B; m; H2 K - studioSplineBuilder1->SetPeriodic(false);
+ W4 H1 {5 d6 h - studioSplineBuilder1->0 q" n( ]% M8 u* h) q2 b
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);! R3 n" X+ m2 t9 P5 c- F/ m4 H
- std::vector<double> knots1(0);. y: L* Y1 [- A
- studioSplineBuilder1->SetKnots(knots1);
8 W3 |: S8 L0 u6 J0 _7 u8 c0 B - std::vector<double> parameters1(0);8 J) I3 i' H& l% w. s; [
- studioSplineBuilder1->SetParameters(parameters1);" Z* n/ O6 k' ~, Q
- Direction *nullDirection(NULL);4 r, W( O& Z1 v0 {" S3 I
- Scalar *nullScalar(NULL);6 e* e- j- e1 s) X7 u
- Offset *nullOffset(NULL);# u" L$ ]4 s8 n- c5 C- Z
- + _+ P, L+ v& N; N: L8 g# B
- std::vector<Features::GeometricConstraintData *>
$ v; P* |& F) [5 i. A6 o# B) g$ `8 s - geometricConstraintData(thePoints.size());
2 [+ b( n# Z# f, u; T! x4 c- V - 4 _$ d* h: o3 h$ j/ }
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)! n0 L) c4 J4 z8 u0 N
- {6 V) h0 t* j4 i* ~" |& X4 X" d
- geometricConstraintData[ii] = studioSplineBuilder1->
5 Y8 j/ R4 P" f, t! v0 d5 v" E - ConstraintManager()->CreateGeometricConstraintData();- z, ?: S1 [0 n' X9 {- l
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);0 I( W$ I' T* T5 B
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
3 Y( j% V% l/ k8 y# `) Y - Features::GeometricConstraintData::ParameterDirectionIso);
3 @2 X! x/ b. z( k! b& @ - geometricConstraintData[ii]->SetAutomaticConstraintType(# K) J# S7 x% P" h$ {
- Features::GeometricConstraintData::AutoConstraintTypeNone);" A3 w. h! k3 j0 b0 T0 l
- geometricConstraintData[ii]->SetTangentDirection(nullDirection); {; c% J8 p. O. b2 ^0 P
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
, t) l; {" W) p% r5 F - geometricConstraintData[ii]->SetCurvature(nullOffset);
# n8 G6 U x/ W* b - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 V9 i T8 |. }" ]( M: R
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) K1 d; i. Z3 Q# _& {
- }0 y" s* z7 i) I, q* ?! D, z
- & R" T5 |# y: W+ z0 D
- studioSplineBuilder1->ConstraintManager()->SetContents(
# V2 [) `$ `$ v" ? - geometricConstraintData);
. x! X# X7 I4 u/ k - ) }% s' f) S' n$ {" V4 p
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();; _7 N( e6 `- V- p: Y) k4 g0 [
- Spline *theSpline = studioSplineBuilder1->Curve();
& K! [) t$ X( \, j; m& z8 M2 M
% I+ f8 T, N' M3 b( G. z4 x- studioSplineBuilder1->Destroy();. r2 h1 E9 Y4 Q1 W6 R+ i& ]
1 r4 Z7 u+ A' I* `3 g- return theSpline;
' e4 K1 r: K) J6 G( Y6 A0 ]7 w - }, O2 ]9 r, f7 F& }6 Q
- 4 a: {: e: E1 H4 i, P
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
2 [' l9 x- E1 ` - {5 g4 A. U' E6 f% G
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 e6 }. S. j1 O! m) s$ U
- if (!thePoints.size()) return;( |6 S& o0 Y0 `6 M' Q% |
- Z( v, t1 E0 b( s. z2 j6 {+ b
- Spline *theSpline = createStudioSplineThruPoints(thePoints);, p! Z3 D p6 R* k) `
- 5 l7 l& q. u0 f* i$ E
- if (theSpline)
/ ]8 E$ v8 L* X5 k* } - {' x$ ~+ T3 `; x) v0 f+ Y2 B
- theSpline->Highlight(); l9 L. \+ G8 V, `; X
- uc1601("Studio Spline Created Thru Points", TRUE);$ P k% Q) ^' q0 o/ K, Z: Y; {! f
- theSpline->Unhighlight();
5 A& S5 h1 ]* [# `) `. Z& r2 D - }
0 T1 Q9 s& h9 R2 t7 t - }
5 n- p8 p% P2 l- u& A Q: f
复制代码
0 \/ ]! S' T* B8 a
6 C# S3 ]3 z; F. K$ h0 I
2 P' N. `, m U/ b. L/ U4 w4 u- f8 X |
|