|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线- R# `4 P5 }; p$ Z: m2 y9 U# A
- #include <uf_defs.h>
- D4 G( K2 }: Q/ d+ ] - #include <uf.h>
+ a6 l f& w; D# G) f4 i) M! r Z) v2 a; \ - #include <uf_modl.h>" Z6 Y5 ]9 k2 |' I- Y& t9 ^ g
- #include <uf_object_types.h>! {8 g4 a4 |+ E. Y: L2 z" h
- #include <uf_ui.h>
4 L2 G) B+ m% W- [' @3 y - #include <uf_modl.h>3 f/ T9 v' n; b/ ]
- #include <NXOpen/NXException.hxx>1 M0 O# w- B! a) W. M2 q: v$ x
- #include <NXOpen/Session.hxx>
/ r6 c0 v. b1 s# r( D+ H - #include <NXOpen/Selection.hxx>+ t0 Y9 ?! V8 t+ T* Y- T
- #include <NXOpen/Builder.hxx>0 f& V5 P6 V/ k: e1 h8 j, y8 u
- #include <NXOpen/Features_Feature.hxx>
5 k$ j1 G" W; J: T9 ~! a% X - #include <NXOpen/Features_FeatureBuilder.hxx>; L' B; K. |# K+ O2 i
- #include <NXOpen/Features_FeatureCollection.hxx>' a/ k/ w* u1 z1 M3 p0 \* V
- #include <NXOpen/Features_GeometricConstraintData.hxx>! z5 O7 c6 w3 \
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>1 |% q! w# Z. f# O4 r
- #include <NXOpen/Features_StudioSplineBuilder.hxx>; t. m% F! t/ c9 v! H7 `: X; }
- #include <NXOpen/Part.hxx>! p" n! v8 l. _. S# A) ]/ c3 [* A
- #include <NXOpen/ParTCollection.hxx>1 q C6 }% p, A9 b
- #include <NXOpen/Point.hxx>
+ U. T( j* G: T - #include <NXOpen/PointCollection.hxx>
: d! |# n' a; B8 k/ X+ S+ C - #include <NXOpen/NXString.hxx>- s1 f S7 p1 g5 |# \( J' ~, e/ ?
- #include <NXOpen/UI.hxx>
5 u0 z! O/ U1 k5 J# U2 r& x: Z - #include <NXOpen/Spline.hxx>
T0 ]6 S. d# {. Z - #include <NXOpen/NXObjectManager.hxx>: E. W$ n; d! Y9 M4 y- H8 j
) H N* O4 \ ?5 ~9 Q- c- using namespace NXOpen;0 t; h- r R4 u; @+ Y# u, P7 ^6 B1 R
- using namespace std;; |2 I& I$ h }" G$ Q
- : q# ^1 |0 M. \+ \4 E- K
- extern "C" DllExport int ufusr_ask_unload()
% p6 O2 Q1 f5 o+ T1 N# i0 c; ] - {
( e/ E( Q( {. A4 L% W# u6 g - return (int)Session::LibraryUnloadOptionImmediately;
+ d% P8 ?( a: d4 y - }" C3 O( X2 ~( s* }
6 M- B5 U) Z0 K. G- static vector<Point *> selectPoints(NXString prompt)
; H- Z7 ` p* p5 W2 \; h - {; u! ^8 U" k% x; z
- UI *ui = UI::GetUI();
5 R" F3 N0 r8 H - Selection *sm = ui->SelectionManager();
* }: Q" d$ q) q - std::vector<Selection::MaskTriple> mask(1);0 v S* T4 F' L. k& W4 U
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 T# u9 j9 I* v5 ~
- std::vector<NXObject *> objects;
& G' H( m" ^" s: C' _3 n) g& j - & x( h6 o+ N6 g0 J
- sm->SelectObjects("Select Points", prompt,# K' K3 c7 [4 H
- Selection::SelectionScopeAnyInAssembly,
6 j& H3 ^9 G, R- r. M& Q& \ - Selection::SelectionActionClearAndEnableSpecific,; m+ U8 z6 X/ c8 S: x: b
- false, false, mask, objects);
9 x( P+ T" }' P4 @6 m - 4 y# b8 D" [! G, w. T
- vector<Point *>selPoints(objects.size());
9 O& }7 |. F2 t$ {# }" s* _4 a l- a - for (unsigned int ii = 0; ii < objects.size(); ii++)1 _2 h* j$ x# l$ J0 N0 \% Q
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
' j8 m/ P. ]8 f/ ^! N" I0 B1 O - ' r( e( Y0 m$ V
- return selPoints;" i8 d1 q8 r" _% y4 z% K& |
- }: t/ u- W" ^8 K% ^9 o1 G
- ; _# ^6 ^& Y! T' K: s
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints): p- k7 \! K7 I0 s0 n6 Y
- {# u7 @/ p( w6 F- W: k7 q
- Session *theSession = Session::GetSession();
/ _5 Q' Y5 s/ {7 C6 M - Part *workPart(theSession->Parts()->Work());8 Z' C; V6 E# Z5 x8 B
- & u# F# k4 O* d1 u: X+ U
- Session::UndoMarkId markId1;: Q2 A% k, N G {, C* `: a
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible," l" z4 M' c. R9 ?8 |/ C' o
- "Studio Spline Thru Points");3 ]1 Z2 H. c; ^& r$ W1 j3 ~( {' G7 i7 n; {
- ! F+ q$ i2 a: M' ?* Q5 d
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
) u' R9 ?+ |1 P, I2 | - % ]9 @4 F5 R# ~
- Features::StudioSplineBuilder *studioSplineBuilder1;
. Q: I! ] O: M4 D/ C - studioSplineBuilder1 = workPart->Features()->
$ p* M/ b% t2 v. }7 x! _% a - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
( z2 U; g3 y8 V+ D% H$ ]: M - studioSplineBuilder1->SetAssociative(true);
5 N! [7 J W8 V0 L+ R5 [7 e3 P - studioSplineBuilder1->
3 g6 Y" [+ J2 h2 y( l1 l - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
, J8 e6 C7 G+ |8 \8 K/ C - studioSplineBuilder1->
! o( Q+ R2 S+ a% p6 }4 k - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
" Q: o$ b1 p8 z6 z - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( p8 N1 K5 b7 i$ y; N V
- studioSplineBuilder1->SetPeriodic(false);
2 D; u3 e! a- p - studioSplineBuilder1->
% @" U* ~2 T1 }+ M8 q `9 d. [5 l! C - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
6 F7 \5 f+ E) g r - std::vector<double> knots1(0);' `3 J& O' {0 K7 C
- studioSplineBuilder1->SetKnots(knots1);
d5 R. O6 u5 ^; ]$ A - std::vector<double> parameters1(0);
2 U6 a) |5 P/ Y - studioSplineBuilder1->SetParameters(parameters1);
! ^% C t `7 H; Q2 L- w - Direction *nullDirection(NULL); B6 E+ n/ A q- N
- Scalar *nullScalar(NULL);
0 O/ ]$ `* _: S - Offset *nullOffset(NULL);
) }. t# B1 q) L - $ k# `1 c' D' |. E6 x( L* I$ c$ t! O1 [
- std::vector<Features::GeometricConstraintData *>
2 S6 W: ]! [1 X - geometricConstraintData(thePoints.size());9 l5 _- ~/ }; O
0 }( F- J" }- W( C5 O, a- for (unsigned int ii = 0; ii < thePoints.size(); ii++), Z! u; A1 E w/ Q
- {, ~# w" a U4 z K( [8 H" v
- geometricConstraintData[ii] = studioSplineBuilder1->% J. z; S' {6 g6 [5 j) G7 ` u
- ConstraintManager()->CreateGeometricConstraintData();
4 V: p0 m; H2 Q$ o3 H( I) R - geometricConstraintData[ii]->SetPoint(thePoints[ii]);; U' B; v: _, R0 }: k3 V4 A" v/ J' D
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
/ v3 F) U; _ `$ W T& y+ v! e - Features::GeometricConstraintData::ParameterDirectionIso);* s6 H& Q7 K9 p$ b1 d$ s8 M3 J
- geometricConstraintData[ii]->SetAutomaticConstraintType(, Z/ r% d( c$ w$ \
- Features::GeometricConstraintData::AutoConstraintTypeNone);
, m6 G; y/ S7 {8 ]: J - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
- }' x/ j/ T1 N8 L3 j - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
" |1 P0 y p* R* W" h& s& V, I% z - geometricConstraintData[ii]->SetCurvature(nullOffset);
4 u# V, Y1 ]6 n: F5 ? - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);, J" ^! S, x% @
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);+ H# S5 l6 U( a4 v
- }
5 ?$ ^! ]& ?7 {. j
1 N" i: b$ Y7 ~* P! U" R7 Y- studioSplineBuilder1->ConstraintManager()->SetContents(
. I0 v) I+ ^! }; }( F {& C% \ - geometricConstraintData);
) [+ T! T+ o2 p3 c D - 4 s. [# ^- x |- @. o
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
$ {; c& r) w" F& L2 Z# y - Spline *theSpline = studioSplineBuilder1->Curve();( R, R/ t" A9 n# ] i+ U
1 ~1 V" l: g0 i+ f- studioSplineBuilder1->Destroy();
/ H7 n" L1 x' H - ; \" `: d) o3 c9 c/ A* p
- return theSpline;
/ c- a- o( Y- f0 o, r! L - }
( j" s F- f% y - 6 I8 y5 K: c/ X( S$ a3 B
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
, Q* D& c7 P9 O. Q - {& n; R) ?8 `- z6 N. w
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
) w9 T# h0 r/ d4 a* [: n$ ~6 ~ - if (!thePoints.size()) return;+ g H2 i4 V, |& W2 o0 M1 W% M
- ^) `3 g0 @0 v Q
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
# _4 D4 i0 f& F0 g- O6 ^5 L+ B8 v - X: i6 G) W4 S) x; Q y1 l( P# n
- if (theSpline)
7 d$ ]8 F5 x4 X; S. X - {
9 k8 O f# ~) N; s5 ~9 R - theSpline->Highlight();
9 B: Z- I& d R) r/ r - uc1601("Studio Spline Created Thru Points", TRUE);$ c# Z! }7 R+ L& `6 {* O* j
- theSpline->Unhighlight();
3 i) ?" Y' W6 W/ B& P - }
1 w; _" ]4 N, A$ x0 l - }
7 r7 G4 G7 d2 y& P
复制代码
4 o8 |2 K/ P0 |7 s% w' [) n" N
1 B' J9 X- I. @: _+ }6 b7 A2 p! L5 Z. r G F
|
|