|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线. U9 A, s y% A* `& u2 B4 p. h
- #include <uf_defs.h>
8 B6 i% d$ K5 `! K8 Q, h! ? Q B - #include <uf.h>' z3 ?$ b6 D9 ?- c7 Y2 K* Y8 w8 M
- #include <uf_modl.h>+ p- V- Q& I* G& s; k
- #include <uf_object_types.h>% d9 f9 @ O: S3 y4 B
- #include <uf_ui.h>
0 o) Q( P/ o! n) ~1 V - #include <uf_modl.h>0 v, c2 ^7 I7 c$ O9 P! @
- #include <NXOpen/NXException.hxx>8 Y! ~' \3 B# N: M+ T/ b
- #include <NXOpen/Session.hxx>
* N+ G$ ?5 @" ~/ B0 y' U) q - #include <NXOpen/Selection.hxx>6 X; L/ B% J7 Z2 @, D& e
- #include <NXOpen/Builder.hxx>( ], Z' M A+ O) ^+ [( s4 m
- #include <NXOpen/Features_Feature.hxx>. h5 P- J F: b
- #include <NXOpen/Features_FeatureBuilder.hxx>- z3 ~/ s7 @; z# `% c
- #include <NXOpen/Features_FeatureCollection.hxx>
8 m9 v! |$ `' V - #include <NXOpen/Features_GeometricConstraintData.hxx>
# ^! P5 O# K! m" h1 h2 W' X; w' o - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>& W0 F7 G$ T: w! I, F
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
3 \( X. t5 o2 m/ T5 ~9 r8 M - #include <NXOpen/Part.hxx>; g8 I( H. e6 q( J* M0 g
- #include <NXOpen/ParTCollection.hxx>& p. u0 a" M: V4 {9 V& M8 ~/ p
- #include <NXOpen/Point.hxx>
* J1 p8 T, ~: L - #include <NXOpen/PointCollection.hxx>. X8 \; A0 R3 P! I
- #include <NXOpen/NXString.hxx>, i$ Z7 w4 P& t- w! H
- #include <NXOpen/UI.hxx>
( g3 I& T, N" T/ g' Q& { - #include <NXOpen/Spline.hxx>
e' O4 b' i' H; Z7 _ - #include <NXOpen/NXObjectManager.hxx>
' m# F4 x: R6 r
& h4 j2 ` L- i/ \- using namespace NXOpen;
, i# Q" A" M/ J7 e/ k* F6 K" h - using namespace std;
0 u3 z$ b7 h* s
6 e# D. ]' l* ?) ~# \- extern "C" DllExport int ufusr_ask_unload()* W2 P3 c; k6 J, R- z; G& ?; s
- {: n( }4 z, c8 V
- return (int)Session::LibraryUnloadOptionImmediately;- i) c5 c% h @# h
- }
5 m) X* Z" M/ X" q* P; ~ - / b9 q9 N0 v2 w, ^
- static vector<Point *> selectPoints(NXString prompt)( [# i/ r4 n! j$ |4 `
- {7 z$ K( M% D3 q3 @! r- }
- UI *ui = UI::GetUI();
3 _& W. V9 t- P0 S - Selection *sm = ui->SelectionManager();
6 Z5 ^# l y0 L J$ \! t9 N7 i7 d: J/ A - std::vector<Selection::MaskTriple> mask(1);. s3 M; F' T9 r f5 ?, c7 n
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);! B- G6 g5 N4 l! X' h
- std::vector<NXObject *> objects;
# k' }7 C; M5 u( G7 e. k - ' h; s. t* s7 W: r. @) Z5 }/ N2 s
- sm->SelectObjects("Select Points", prompt,
4 a& `$ a+ o# s7 x- ]$ i - Selection::SelectionScopeAnyInAssembly,
1 {9 }* z1 R2 [# X; C" Y - Selection::SelectionActionClearAndEnableSpecific,
# Q- t* u& Z+ I0 B - false, false, mask, objects);
! ^# P8 k+ t1 B: Q& k4 {, R/ Y - : h, K! o% q2 y& K- l
- vector<Point *>selPoints(objects.size());# l" z1 d6 L" f
- for (unsigned int ii = 0; ii < objects.size(); ii++)
0 p% _8 H, P4 S( d' k* C8 | - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 k) r9 V" L6 P& `+ g" W8 c2 ^. P6 l
- p7 H: S7 z4 c
- return selPoints;
* n x* c! y. U1 j! k - }
- g- J, w( \. p: {
& q' `, Z, A E# ~- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
1 f* C9 F$ K: D - {
2 J- j1 `; j; W: W) a% i& k3 [7 } - Session *theSession = Session::GetSession();
( ]1 G/ J2 `, y6 b, s2 k - Part *workPart(theSession->Parts()->Work());3 \1 m1 ~7 _* \0 I
- 3 O/ S; V2 t2 Q
- Session::UndoMarkId markId1;* @3 d) a. E( Q( D
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
^ r" H: T) c2 i - "Studio Spline Thru Points");( b9 [6 y; Q5 ]/ N3 j" ?3 C
! J) R7 ]; @: B- s: S- Features::StudioSpline *nullFeatures_StudioSpline(NULL);$ t/ i/ S* x3 @; ^
- }7 d; i y! t K! n7 D
- Features::StudioSplineBuilder *studioSplineBuilder1;3 C3 {# j5 P' U2 y$ N! P1 S
- studioSplineBuilder1 = workPart->Features()->
6 |7 K; W2 Y6 H; o9 h1 B - CreateStudioSplineBuilder(nullFeatures_StudioSpline); Z% E& c% ]: f( \1 n2 l3 e
- studioSplineBuilder1->SetAssociative(true);+ C- O5 |' o5 Z' `" Q
- studioSplineBuilder1->) E2 i3 W/ u$ s! `. A3 [! j: S
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);! h# e; _+ T+ {6 U% N2 b% X
- studioSplineBuilder1->1 U* n6 s' X- Z! @, d5 a
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);% q Y% `. N7 t9 n. D: t- Z
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
9 ?* m, A, |. M6 q, I% m. S - studioSplineBuilder1->SetPeriodic(false);+ L1 W+ D I+ T. C1 Y) X
- studioSplineBuilder1->
[$ i$ d( V% X# g4 G% V - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);: r- h% W+ c) d6 H
- std::vector<double> knots1(0); h Y1 _/ x8 U; I4 X( f
- studioSplineBuilder1->SetKnots(knots1);
+ V6 I- ~ z) F# o - std::vector<double> parameters1(0);& h1 {. z4 ]' g( e+ ^* X) C
- studioSplineBuilder1->SetParameters(parameters1);
2 W1 C0 M, M5 _7 F& ` - Direction *nullDirection(NULL);+ P) |/ X6 f/ n) G& a8 r2 Q9 @
- Scalar *nullScalar(NULL);
2 ~. I% \1 h0 Z! s! I - Offset *nullOffset(NULL);
) U' F% w- i/ ?+ \
, H2 ^: y! s2 }) I- std::vector<Features::GeometricConstraintData *>
. ~/ I4 E* l0 V+ S - geometricConstraintData(thePoints.size());
- h3 H! b# i }( F6 O. H - 6 n, D" B' w. p2 \+ M
- for (unsigned int ii = 0; ii < thePoints.size(); ii++), S/ |: A" y+ n6 U% l: M) `
- { ^3 L6 z8 |3 _7 o9 f
- geometricConstraintData[ii] = studioSplineBuilder1->5 t! A$ H3 B; U8 s5 ^* b/ t# T# S
- ConstraintManager()->CreateGeometricConstraintData();
% p8 a! I7 a7 u - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
a9 Q0 A; [/ G& U/ x - geometricConstraintData[ii]->SetAutomaticConstraintDirection(* C. B5 H4 Q6 G( I, F3 c
- Features::GeometricConstraintData::ParameterDirectionIso);8 u K3 C: q& p2 I8 j9 g
- geometricConstraintData[ii]->SetAutomaticConstraintType(/ O& o) M* c0 n% `' T/ E/ g
- Features::GeometricConstraintData::AutoConstraintTypeNone);, V1 X) ~5 ?' q
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
' h5 x; ^; h3 t3 d - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);, A' Q- e4 z, |) n; x2 S
- geometricConstraintData[ii]->SetCurvature(nullOffset);
% {5 t4 R! n u& ` - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);% ^: h6 V: j$ n) d9 G2 R( z9 D3 U4 x
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) Z1 b- ]( x0 z
- }- Y$ Y+ }9 E+ ^7 a; U3 W( j" l
$ F' i! I, i1 U5 M! V: b- studioSplineBuilder1->ConstraintManager()->SetContents(5 W% ^8 o; `: a3 |9 v
- geometricConstraintData);
8 Z* z, T* W+ m) I' j+ L - + \# N% g2 c7 S* L
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
' m& H6 m+ b. }" A0 T - Spline *theSpline = studioSplineBuilder1->Curve();( k, l1 Q1 a8 X$ S D9 x
- p' N' d+ M) }. b' z- studioSplineBuilder1->Destroy();+ H5 R: R/ l+ a- Q
- - d7 g* U" X8 Q9 R9 b
- return theSpline;- H z2 z+ Q0 }( R/ V( R8 b( Y
- }
. W* e! C" s; j - : W, t+ S: c7 o9 [
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len), A- a2 t+ q/ W5 M5 f% l
- {
8 M W$ S) V& e2 x( k7 o - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) r$ ]7 ?6 i) s" `; ] f/ p6 x
- if (!thePoints.size()) return;2 T4 U! k. U: u! Z! y- h
- # C% B9 A6 H' m
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
; R. z" [- `, B( p& w - ^# o$ f8 N7 }/ Y/ k' X
- if (theSpline)4 g6 W' S" s) D+ r: V, d( p, m+ z
- {
5 i& o2 S+ |2 k! o - theSpline->Highlight();8 a: D2 P" n6 D
- uc1601("Studio Spline Created Thru Points", TRUE);
( W5 i1 O7 _( g, t. j# A - theSpline->Unhighlight();
/ B; x E. |, [( e - }
; k2 U2 t G1 r/ y2 X# K - }$ b x% Q: h/ _2 A( m2 R
复制代码
2 \1 i3 K, Z/ `8 C4 F
4 V% d/ c/ ?2 C9 G! I5 @" I, c$ B$ a* U, Z" N3 G+ R% P
|
|