|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线+ g& j: s5 K; T) f3 B- e& r' d
- #include <uf_defs.h>/ ~0 P1 y$ J9 B; Q, N
- #include <uf.h>
2 x4 e8 L+ Y% v" e: ^1 W* ]% g - #include <uf_modl.h>
F7 i3 r% Z1 _4 i X - #include <uf_object_types.h>
9 d) F/ i8 H5 t5 t/ W+ A' V - #include <uf_ui.h>
9 W" K: C0 \6 o# r# w2 I2 x - #include <uf_modl.h>
9 |& Y, p) t8 F; [" f: `5 ] - #include <NXOpen/NXException.hxx>
* H& h% n. k) z# I. X3 G& n! M - #include <NXOpen/Session.hxx>
0 P* ?0 {7 T: H9 h - #include <NXOpen/Selection.hxx>
1 q; x" E2 j6 E! ~: K4 o5 @ - #include <NXOpen/Builder.hxx>
: E* p8 T: W! {8 u - #include <NXOpen/Features_Feature.hxx>
$ d7 Q n, l; Y9 q( t1 D. [. a - #include <NXOpen/Features_FeatureBuilder.hxx>' B3 @ Q6 S y
- #include <NXOpen/Features_FeatureCollection.hxx>4 b: y& A/ D, b, Z6 R9 V7 z; q
- #include <NXOpen/Features_GeometricConstraintData.hxx>
$ x7 k2 O m5 m; a$ ^; }! J - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>3 a9 A& [3 S! c$ e; U
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
" O. P% o2 F% }7 A6 F - #include <NXOpen/Part.hxx>, T2 g! L3 K3 ^
- #include <NXOpen/ParTCollection.hxx> N, O! R& Z& d0 r
- #include <NXOpen/Point.hxx>
7 `8 {$ f( q$ s: U3 ]( I* H$ ?4 y - #include <NXOpen/PointCollection.hxx>
4 x+ J! Y! J* [% }( @ - #include <NXOpen/NXString.hxx>9 l4 F1 {, }% O1 h
- #include <NXOpen/UI.hxx>, F& C+ L a1 i
- #include <NXOpen/Spline.hxx>
# u3 b5 a5 } J p: O7 s% C/ A) | - #include <NXOpen/NXObjectManager.hxx>
3 c4 D# E& `* [& h8 I4 p9 V% [ Y
: X4 f9 A5 s: l& R- using namespace NXOpen;
9 @' S3 ^2 M: n9 \8 G- Y - using namespace std;9 f/ H8 d; s: d; G0 T
3 {2 Y R; x" p& @ Q! X- v- {# E- extern "C" DllExport int ufusr_ask_unload()& u8 E* g1 I8 }) y9 T2 M/ d% ~
- {
& h, M0 y; h+ t7 Q; f( \& S - return (int)Session::LibraryUnloadOptionImmediately;+ o1 W' S) y: y3 d$ U
- }
9 R, O8 J* {2 |# _; g - 7 l8 f5 a3 A5 d* I. k
- static vector<Point *> selectPoints(NXString prompt)$ P! A3 y/ u+ z9 \2 h+ p
- {
5 Y9 A; i; Q1 G' d; Z# y, c: ^& K - UI *ui = UI::GetUI();2 v5 H; ~% m7 ~: _ X
- Selection *sm = ui->SelectionManager();; ]3 b. {) i8 d1 |, k
- std::vector<Selection::MaskTriple> mask(1);, W( h7 p+ ^* P( Q0 [ H- h
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
1 p/ m6 }3 F9 z( P - std::vector<NXObject *> objects;, c8 s) s! H$ W: L- O8 G/ W9 e
' |' t) H- `4 v: W5 n' @- sm->SelectObjects("Select Points", prompt,
8 g$ D# N! u" A" s% N- O# k4 c0 S - Selection::SelectionScopeAnyInAssembly,' Q0 I' D& X- v" j- ?
- Selection::SelectionActionClearAndEnableSpecific,
$ q/ M7 L5 Z7 j9 Q6 e, X - false, false, mask, objects);
+ m& H4 P, K1 T - , v' P7 v6 [! a5 V1 y
- vector<Point *>selPoints(objects.size());& l0 k6 i7 k3 A) N/ \0 l* _" f% t
- for (unsigned int ii = 0; ii < objects.size(); ii++); ^( W& t3 K) K3 H
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
. h# q7 }: L t2 q: b0 \' E - & Y4 r0 C; ]" j, U) v9 f
- return selPoints;$ l& x; f" p9 S9 E0 |
- }5 _/ x1 W/ ~ ~
- $ C6 _5 s! m# O( t( f {, w
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
- {8 Q4 S5 @) b9 o - {! }) B/ [5 I" _& P( @7 \, F# G
- Session *theSession = Session::GetSession();, x( F! }2 O/ f2 V& R
- Part *workPart(theSession->Parts()->Work());
5 P3 T8 |; e& E0 } - . J- i# ^0 g) R F/ |+ Z+ K2 Q; Z
- Session::UndoMarkId markId1;
( ]$ X% U6 c/ i: k/ Z+ G, l0 ^" R& @ - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,$ t: Z, c# O0 j
- "Studio Spline Thru Points");4 q; B: L+ L' F& q7 P# q3 ~3 P
- 8 Y6 Q% b/ q% h% b. P' {
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);6 `$ i0 a3 i" \) s
: m; a9 }. V8 l: |7 r- Features::StudioSplineBuilder *studioSplineBuilder1;
9 I5 Y0 `- G4 W! j - studioSplineBuilder1 = workPart->Features()->
) G) e9 e C. Q0 J7 A# H - CreateStudioSplineBuilder(nullFeatures_StudioSpline);5 I/ w, ?% W$ Q2 @
- studioSplineBuilder1->SetAssociative(true);* ?* d" ] L- w0 J) L7 p$ T
- studioSplineBuilder1->
" n1 N6 e3 ~4 u1 U7 e - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 O) S( E5 ]9 H( P0 e. _
- studioSplineBuilder1->
. L8 {, W" U- Z* _5 @3 w - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
1 A( P6 D) o v% _ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
5 \* c- f; W4 p1 m% I, i* @, j - studioSplineBuilder1->SetPeriodic(false);
. N* P1 c3 F: _8 M% I3 E - studioSplineBuilder1->8 P; u% K% c/ ]
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
( s3 [3 G/ R% w0 r$ k7 d7 k# K* P - std::vector<double> knots1(0);5 h9 r3 Y& M* I$ @ Y* `
- studioSplineBuilder1->SetKnots(knots1);) s3 O2 }: r6 A t2 k- g9 c
- std::vector<double> parameters1(0);* U* x3 D7 J8 _, }
- studioSplineBuilder1->SetParameters(parameters1);. K. o$ g: b. k; m3 V2 ~- m2 O
- Direction *nullDirection(NULL);+ b' q1 i" X5 `# ~
- Scalar *nullScalar(NULL);
- Z3 X+ M' [4 o) [1 C5 }7 h - Offset *nullOffset(NULL);7 E6 D( n' J) x- V% i g
- 4 x& U2 u5 N1 _: c+ N) {
- std::vector<Features::GeometricConstraintData *>
1 F- Q8 U- ?5 t! ` \- }% \& r - geometricConstraintData(thePoints.size()); l+ \. \+ t# x1 B1 N/ n( ?# x5 Q
- 8 t; I! t8 o$ [! f' q
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 }9 c- M, L1 Q( ]" ^
- {+ j9 v O! O% W8 e, L& [
- geometricConstraintData[ii] = studioSplineBuilder1->
5 p1 `6 P6 A& Z8 I+ ]* V8 d - ConstraintManager()->CreateGeometricConstraintData();
9 ?# i& Y. j- L u8 E - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
$ E. ~- z2 ~% N3 u. b; A1 F7 X! c - geometricConstraintData[ii]->SetAutomaticConstraintDirection(! G4 [8 Q1 l( F+ }7 }5 S9 x" A: M' `. M
- Features::GeometricConstraintData::ParameterDirectionIso);
2 R! u$ a0 V k" q - geometricConstraintData[ii]->SetAutomaticConstraintType(7 t1 _( o5 g/ @* C8 a- o" @
- Features::GeometricConstraintData::AutoConstraintTypeNone);5 F2 G" \; v! j
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
8 [: v' F* P C, B h3 C - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
8 W6 P/ e6 g; ~+ y7 D6 q4 R8 l: o3 } - geometricConstraintData[ii]->SetCurvature(nullOffset);& |. f( b2 g3 w0 D+ s3 Q
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
1 h M5 l* U" ?/ L) Q% k( l - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);( I+ o6 m4 {4 E' R# ^; g* _
- }8 q" i/ V4 {9 e9 Y" b8 C% ^
- l! l/ H$ _5 c- studioSplineBuilder1->ConstraintManager()->SetContents(
( _' z9 ^6 C Q- {9 \0 e2 |, h! ?, O. } - geometricConstraintData);6 u8 z# @# ?" _/ S, k: |
2 J F) ?$ h( B2 I- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
" A i' I, A) h2 @6 s& i8 b4 t - Spline *theSpline = studioSplineBuilder1->Curve();2 Q1 y" b( y$ R! m; e& n8 [
* @* u, S' H [5 Q, Q' h- {3 r- studioSplineBuilder1->Destroy();% J {" r- c0 x
: f# q) Q- }% ?6 u3 d0 T- return theSpline;, y8 F8 |1 d( [7 `* L0 Z$ L3 k# n
- }, b5 p" t7 | c: i
- , B: o q$ ^2 _: [& ]! V
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
1 \* A! e" I# R6 j7 G - {
5 X; ]) l, G7 C8 g; M+ K1 P - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
3 g3 V& `" ?, b - if (!thePoints.size()) return;7 g% _; n. d: v1 U) e; F
- : A0 H) {2 l9 ~% I: C+ l1 N5 v
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
9 z# t9 [& D, M5 q
/ O5 g/ e0 ?: Q" {. q q/ R8 J' ^- if (theSpline)# L( c! b6 |6 R- b
- { c h7 T0 G7 U6 l; V! x) D9 @
- theSpline->Highlight();$ e" [+ A* V$ d
- uc1601("Studio Spline Created Thru Points", TRUE);8 D9 K4 \/ c W5 T
- theSpline->Unhighlight();
d$ w* ]$ a6 W0 s, H5 Y+ y" |8 j - }/ p( S( J6 s7 o( ~0 Q
- }
' P1 k: w' T$ \7 D0 o
复制代码 ( e1 k' ~5 h4 Z* k1 N }
1 E! W' O( A2 ?
3 Q* g( N" L, U, r. a- S
|
|