|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线5 V' f. I* w# Y5 N' R
- #include <uf_defs.h>
7 x6 S9 h/ g! |# G0 Q8 t* F - #include <uf.h>
8 ^6 O d' `5 |2 o - #include <uf_modl.h>& `& m9 C8 E9 l9 a5 g T
- #include <uf_object_types.h>
' ^# N* Q- m2 O1 N, T) L - #include <uf_ui.h>' y; D' k @. P
- #include <uf_modl.h>
" z* e$ h$ t+ } - #include <NXOpen/NXException.hxx>
% r+ [3 }& w9 D5 ?' j - #include <NXOpen/Session.hxx>
$ a% y, a# G6 I6 X - #include <NXOpen/Selection.hxx>: X8 C" V+ |% }
- #include <NXOpen/Builder.hxx>2 R/ e0 q# Q! i. \3 ^" \
- #include <NXOpen/Features_Feature.hxx>
- O& D! D( q" X - #include <NXOpen/Features_FeatureBuilder.hxx>
/ ^# Y% J* g% Q( \" p: v - #include <NXOpen/Features_FeatureCollection.hxx>
% n% Q- h1 L: b* {+ z! B1 Z - #include <NXOpen/Features_GeometricConstraintData.hxx>- ]/ D5 b j" |/ x) @' l- J0 g' B
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
( L+ Q) w, z. \+ f& P7 y- H1 i9 ` - #include <NXOpen/Features_StudioSplineBuilder.hxx>& a- t) d1 K: q" j# e
- #include <NXOpen/Part.hxx>
4 w, ?: ]1 j8 ` - #include <NXOpen/ParTCollection.hxx>
3 \1 M$ D( `" _' o+ P- ^& x - #include <NXOpen/Point.hxx>
6 S2 j0 h; L: B - #include <NXOpen/PointCollection.hxx>
; _! m% |) ]6 _7 e. E5 A) k" K - #include <NXOpen/NXString.hxx>
$ C3 Z& x9 B& m* X. n - #include <NXOpen/UI.hxx>) f4 x2 V8 d1 E7 \9 g
- #include <NXOpen/Spline.hxx>4 n* n$ B1 V& e o) W; V- J
- #include <NXOpen/NXObjectManager.hxx>% e" n) b5 \7 G& h
% a0 I) A+ \( b, B# J- using namespace NXOpen;& u" N3 E S9 ~ |) g5 u
- using namespace std; K- ?4 A: R9 }# h( u2 A4 S" S0 m
- * ^5 U0 x% D, }& o0 |( y% y! |8 Q
- extern "C" DllExport int ufusr_ask_unload()* L. d j1 N' q& A0 `
- {2 d# R' o* A4 \9 W- E" A
- return (int)Session::LibraryUnloadOptionImmediately;
' a! B7 o! ^6 W8 F$ I5 o/ { - }
4 I! C5 L' H# ~1 q* c$ {3 V
7 o. H! Q4 |, o' O) k- static vector<Point *> selectPoints(NXString prompt)
( L7 a. Y0 D( w7 H: Y2 L3 |! C - {, X; U5 s& E& g d& W# u6 @; y
- UI *ui = UI::GetUI();
: E, B& d. }9 U - Selection *sm = ui->SelectionManager();
8 g& P9 s, l# f8 | - std::vector<Selection::MaskTriple> mask(1);1 `' w, g0 x7 U$ C1 ?. o$ @3 O! B
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
4 R7 }2 N7 u. C; }$ [& d6 S - std::vector<NXObject *> objects; m( k. j2 M' D8 I) ^! N+ j' K
- X- K7 A+ A! F3 z j0 m; y- sm->SelectObjects("Select Points", prompt,
9 q5 H# c/ K' \/ K8 \' C S1 z - Selection::SelectionScopeAnyInAssembly,
1 Z; F6 S& n6 T5 b" O2 j. j - Selection::SelectionActionClearAndEnableSpecific,
+ E3 B$ |* F' N$ w - false, false, mask, objects);
2 W. W7 o0 \' H$ y
0 |& }! c0 H* w, r, U: v- vector<Point *>selPoints(objects.size());, Z$ K" }1 E7 s' [4 \ o
- for (unsigned int ii = 0; ii < objects.size(); ii++)
$ d! E: J$ \" i8 I9 } - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
1 [: C% A3 l% @
8 P7 n/ @" Z' K A& _- return selPoints;% T. |/ C( v$ Y0 B4 x
- }
R5 O+ u/ v$ ^+ z6 ~0 f
4 _, h) |# s6 I( }- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)" Q+ p3 @, ]! N5 y
- {3 A: b/ i9 _9 N. A! Y7 F1 e3 B' k5 |
- Session *theSession = Session::GetSession();
) m. B( w, k' J# U a9 g - Part *workPart(theSession->Parts()->Work());
" ], O. r N1 s5 l2 b( G! o3 {
$ [% _0 z: n; J9 i0 N! U3 _- Session::UndoMarkId markId1;
' w/ b: C/ K2 Y- S' j - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,+ f$ b4 Q. Z# h9 y) C
- "Studio Spline Thru Points");
; Q& {! g; q* U7 j1 E
9 i. W! K( Q+ X) V' U! J5 H+ c; k8 d! m- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
: P8 C: l5 _ y9 [1 i% k! D* N - 3 f7 x) _/ j7 t! J! `# L0 g0 g4 i
- Features::StudioSplineBuilder *studioSplineBuilder1;6 r: z# {3 P4 c& _; s7 _2 Y. [
- studioSplineBuilder1 = workPart->Features()->
8 `4 z8 d z0 L - CreateStudioSplineBuilder(nullFeatures_StudioSpline);3 S( Z6 t- b' N4 J- R- v* N: B
- studioSplineBuilder1->SetAssociative(true);6 N9 g" J- S! L
- studioSplineBuilder1->
: l b6 t0 `, i# A: X4 \: d - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
* r! i a! X: t+ M1 v - studioSplineBuilder1->
6 D7 Y E# P& _% L& X4 i5 Q - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
9 B7 v/ b, a9 ?' Z4 X( J - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);! A8 ~% i# x$ V
- studioSplineBuilder1->SetPeriodic(false);: j# w+ d7 v& U
- studioSplineBuilder1->
- `7 A" f" d, h0 t - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone); j) y1 [4 L, R. _3 m: V
- std::vector<double> knots1(0);0 k6 p- H( C, m4 t7 T. Q: B
- studioSplineBuilder1->SetKnots(knots1);
% i, o& a, w0 s* `! o - std::vector<double> parameters1(0);2 s+ _. {7 U& w9 L- r
- studioSplineBuilder1->SetParameters(parameters1);
) G! q$ B u( J' }9 L" s! b* P - Direction *nullDirection(NULL);
# h; F9 {2 g3 M6 x - Scalar *nullScalar(NULL);$ _. v1 Q: b5 R- e. k, k3 j8 U% M
- Offset *nullOffset(NULL);
8 J! Y/ H, D+ X$ L
! k- ]) ~4 v/ ^, I- g, T" V- std::vector<Features::GeometricConstraintData *>, ~& {) O2 u$ {( }3 z
- geometricConstraintData(thePoints.size());/ P5 b1 O+ N$ X$ r7 v
- 2 F' j. D/ [7 b) `6 G
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)- R( p3 |, F, g4 C
- {/ r, }' _, [9 }
- geometricConstraintData[ii] = studioSplineBuilder1->
. R! t& g% [9 @- w/ P( D - ConstraintManager()->CreateGeometricConstraintData();0 \2 }; i/ m5 h: t! Y
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);' X1 w. [9 I8 x8 z
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
+ Y( W. _( r5 G; z( \- y% D( e0 I( a - Features::GeometricConstraintData::ParameterDirectionIso);
' P# l% f# U( U( g( g6 [' c - geometricConstraintData[ii]->SetAutomaticConstraintType(/ S! y* ?- h' G1 S) g5 r
- Features::GeometricConstraintData::AutoConstraintTypeNone);# M/ N- U' y( s$ X6 q/ ?8 f
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
7 {; }2 e; q' R* _! f2 X% \ - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* ~( `. k3 g: j1 s6 N: X7 A3 [6 P& z7 Y) A
- geometricConstraintData[ii]->SetCurvature(nullOffset);
7 k: c% V3 D, ]8 | - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset); ]0 W5 M) a9 x- q$ d, U2 G
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);( ]* G) i1 d) N0 Z' ?
- }
+ j! Y* i% V- Q% @2 I
; n: T: [. m) p- y& S/ ~ r* K- studioSplineBuilder1->ConstraintManager()->SetContents(7 y( u- R; @2 S$ U
- geometricConstraintData);9 H. m- Q. a1 }
- . r/ C. O ^5 v& O$ N
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
3 k3 U. r& s( N. c" O+ I - Spline *theSpline = studioSplineBuilder1->Curve();% B- @5 n \- I; y1 T
6 S3 k5 E `( _* a G$ c- W- studioSplineBuilder1->Destroy();
( P6 R' s& |7 K7 h
' g6 i6 X0 N; N- return theSpline;1 {" H0 K* d2 R( D4 D- ~! b) d8 X# ~
- }" y6 ?- ^- N1 V1 q+ |' D
- * H) q# X% y: W# Z2 d" E
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)- \$ d( z3 y0 t
- {; l) i5 M B/ ?# m# x- k
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");; r9 J. m& r: Y" u, _9 P0 F; |! t
- if (!thePoints.size()) return;( P/ F2 Z: P# ]
- ) {) H- h& S- O
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
+ Z' {, o: N* p1 U+ Q3 i3 w
1 e4 E1 {2 P% p9 e: B- B1 v' E- if (theSpline)" I, @" Z: Z% E, r6 F
- {
% C! {4 ?4 T' N# S$ f2 U) g - theSpline->Highlight();
l- v! ^, _% I# [& I5 j1 `0 c& X( U - uc1601("Studio Spline Created Thru Points", TRUE);1 ^; a% y- G1 c6 R7 ~0 k
- theSpline->Unhighlight();
4 ?( k+ O, D& q* W5 a! k - }
5 {" N- F. f& H5 h* R - }
: g# i Y; R- e y; Y
复制代码
" W- x: A9 C; r6 g5 ^: r/ r! i0 n8 f
7 v1 f# X! B+ d2 x; V I$ k- g! s
|
|