|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线/ O2 D* v; B, V. ~1 O/ {# I
- #include <uf_defs.h>
% q3 d1 a; O8 p( \ - #include <uf.h>
* J9 }3 A4 @5 _0 B( k0 m* x - #include <uf_modl.h>
9 G& T. o2 O V9 P$ e# w - #include <uf_object_types.h>
! c# `( P# k8 A6 @ - #include <uf_ui.h>% K$ o2 g5 E( M
- #include <uf_modl.h>" b$ _6 ^8 U/ y- G
- #include <NXOpen/NXException.hxx>
4 c7 `# y* ?/ N/ c1 w3 P - #include <NXOpen/Session.hxx>" @7 }2 Y( H' ?7 W: p# @
- #include <NXOpen/Selection.hxx>0 A7 q. o+ i# a; [/ j
- #include <NXOpen/Builder.hxx>
7 b% l% {. C% ? m1 p- X - #include <NXOpen/Features_Feature.hxx>
. {7 f# H. K" y! b$ q - #include <NXOpen/Features_FeatureBuilder.hxx>& G4 a% l! o; K: ]' ^
- #include <NXOpen/Features_FeatureCollection.hxx>
+ c1 v+ S3 f6 e1 j- D - #include <NXOpen/Features_GeometricConstraintData.hxx>! R y' o7 r& l+ t# n* I) u
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx> @- } D, H) c7 a+ u: z5 L
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
* P- g9 V/ [3 G4 M0 E& X% U a - #include <NXOpen/Part.hxx>
2 A, p1 Y% }7 T$ z; A% v - #include <NXOpen/ParTCollection.hxx>
# ]6 _" q! ? X: P - #include <NXOpen/Point.hxx>4 K4 A z. X* W4 l, F/ k4 f
- #include <NXOpen/PointCollection.hxx>
4 I! A7 B8 T+ D4 Y; n - #include <NXOpen/NXString.hxx>$ [9 X# ~" W. @, }% j0 G
- #include <NXOpen/UI.hxx>! t5 L. d6 p1 u- k
- #include <NXOpen/Spline.hxx>
( H- n. n ?: Q/ ]1 ` - #include <NXOpen/NXObjectManager.hxx>: n8 u% D8 c' q, I) G& W
8 n' e) [ S# X2 e( \- using namespace NXOpen;! Q+ s/ h) r# J4 J: ?# f# M
- using namespace std;
" L0 A2 O+ Z7 @. l1 c - - I" V. v/ Z3 R% h8 y$ q
- extern "C" DllExport int ufusr_ask_unload()( f* E: ^9 W- q: ^
- {+ m0 Z( z/ f5 d
- return (int)Session::LibraryUnloadOptionImmediately;. I6 t/ X* _( G& E; f6 u: }
- }0 B& \9 F$ r& \
- / e, W# q: A$ Y# ~3 G: R' ?
- static vector<Point *> selectPoints(NXString prompt)
! U8 ]: ^5 _& l2 {. H( \; C( ^) K' E - {5 g8 T/ {" r: a7 Y$ r: V4 |
- UI *ui = UI::GetUI();$ J& a, S! T1 c1 ~% C5 m% f& S# M
- Selection *sm = ui->SelectionManager();
' r" X! H7 d4 ?% D9 a. V - std::vector<Selection::MaskTriple> mask(1);
* j+ r9 C" O! G. C - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- g5 b; \9 h4 U' i: |8 n5 C$ X! J
- std::vector<NXObject *> objects;
7 P6 S: t% u9 D# ?2 U7 i
* ^ V$ Q# V. i5 ?- sm->SelectObjects("Select Points", prompt,
" D/ d) M( d0 ^: f - Selection::SelectionScopeAnyInAssembly,4 r. [4 L, e$ c" y' J) Y
- Selection::SelectionActionClearAndEnableSpecific,9 {$ _0 u! {" h9 D
- false, false, mask, objects);: R+ n9 s6 U' K& r7 P g; x* w$ Q
& B1 k3 b* k( r( U2 ~- vector<Point *>selPoints(objects.size());
. N' L; M A% z/ h* i - for (unsigned int ii = 0; ii < objects.size(); ii++)) t" s" C+ S' x; i: c) y
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);3 H; w0 t' o9 B& {% M* _1 g) R4 j
- 6 N8 z; q* ?7 p
- return selPoints;* G1 J! S7 x: C1 i2 F1 w
- }
3 B* E- I4 c5 \3 B' g! F - + o5 p* W8 }6 y
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
3 {! q9 m9 d* B3 N- |' ~ - {1 ~* K- Q+ p* h; {7 @+ `3 m
- Session *theSession = Session::GetSession();
1 d1 l9 A. }0 @$ B - Part *workPart(theSession->Parts()->Work());, q3 E* K* Q5 b. s6 j l
: n+ ` \- r7 K0 H- Session::UndoMarkId markId1;
! f# w- Z+ E! W; ~% G4 H8 H! F - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,) H# i3 R2 ~$ q& k
- "Studio Spline Thru Points");
0 S( k5 r" g- _* l. Z& A5 y$ V2 I - / r$ b+ T: t5 a, f
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);- D/ r3 m! l7 N4 F" ^( r+ x
* `1 B5 p6 W& W% H" D9 F% f- Features::StudioSplineBuilder *studioSplineBuilder1;
* m. p# n$ y; v9 M; p( x - studioSplineBuilder1 = workPart->Features()->
6 x; q( U) w! b* T$ m0 i1 k - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
- T& x, z* }0 b - studioSplineBuilder1->SetAssociative(true);, m6 L! B7 Q( ] w4 o. }- A
- studioSplineBuilder1->
2 F3 z' k6 L% f G - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
- N7 e7 c0 X3 p9 X/ I - studioSplineBuilder1->
8 V W3 w5 x) x/ M) O2 U( @0 h - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
6 l# {. w* ^: S3 ?+ q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
. I- S7 d8 F# l0 q# e) }! K% r0 @ - studioSplineBuilder1->SetPeriodic(false);2 M9 E8 P- M s& @: O# i
- studioSplineBuilder1->5 y1 F" P: u$ U4 q$ f$ b; V. g
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
' ~3 n: t6 s# l - std::vector<double> knots1(0);: r2 U) D" o) z7 M6 i
- studioSplineBuilder1->SetKnots(knots1);' j9 e+ ]( f1 J/ m
- std::vector<double> parameters1(0);: a' q! \" C# \/ A/ M% Z7 }: B5 m
- studioSplineBuilder1->SetParameters(parameters1);
- x( I8 u; @0 m) I t - Direction *nullDirection(NULL);5 h! v8 L* T, Z) f
- Scalar *nullScalar(NULL);
9 T& c z6 p- D5 F+ a0 z; j - Offset *nullOffset(NULL);
7 G! F: q* v4 T4 z
& g: r5 R* ]0 r' o# }+ v5 L* C6 M- std::vector<Features::GeometricConstraintData *>( O4 P3 b6 p. }5 M8 f
- geometricConstraintData(thePoints.size());2 O5 M* c5 c" U% M2 B% p
: U5 p" r/ P5 X5 r7 {( u1 r- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
k( a! d' P& a' R9 ^0 l0 } - {9 ]) h$ Z1 H" O4 R8 V9 T' W- N
- geometricConstraintData[ii] = studioSplineBuilder1->
+ D- v& v* }% w3 r - ConstraintManager()->CreateGeometricConstraintData();
- p* E7 @$ K/ O, x7 L* c% `4 k - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
5 u$ O- F& i$ Z3 H) X3 S4 J - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
2 ^" |% g" e2 i% m, U- D6 p0 n* K - Features::GeometricConstraintData::ParameterDirectionIso);
* |2 v5 J: s; t2 i) f - geometricConstraintData[ii]->SetAutomaticConstraintType(
B [6 u* d( p0 W$ F* g& f - Features::GeometricConstraintData::AutoConstraintTypeNone);( a% z( |/ O: Y! _6 N& t
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
' ~. M; ^ J7 {1 [ - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);: e) E9 K' W. a! I; G6 K5 C
- geometricConstraintData[ii]->SetCurvature(nullOffset);6 ~- y, ~+ e7 q. O9 N& L
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);8 r C2 e o+ k) W+ F
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
% e, A4 V0 E) }7 n5 V - }1 |+ H' _+ f9 u* v2 d
$ L( m; q* @ F& v/ b' |: u9 t- studioSplineBuilder1->ConstraintManager()->SetContents(
# `4 p V; y J2 {* h5 E4 A6 g - geometricConstraintData);
( w7 U" p$ c# @7 x: \ - 1 @7 A! K+ _ c K
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
3 `" L& y% [5 H" i8 f - Spline *theSpline = studioSplineBuilder1->Curve();
( d+ F* L) v2 d' m
* i u3 ~& m+ Q" o* o1 [6 o- studioSplineBuilder1->Destroy();6 r9 o# r" A: u7 V
- 7 x4 C1 W8 T) j1 K" E3 i% w( L, d0 k
- return theSpline; {( L1 U0 t; e3 Q! P2 d: n
- }
' ~- ]% _. o- ?8 x6 ]- n }8 o) l) l - 1 R6 y( j! l6 w. i6 s
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)6 L# L$ ~3 Y8 A" \- g5 ]! q" T) T
- {
: f1 M$ {! \) X( _' d; b - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");0 ^! G1 _2 ~/ j. L; Y, g0 u: E
- if (!thePoints.size()) return;
- O- g1 G! o: @ f1 X$ K
9 ?0 d& b1 B1 U M8 G- K- Spline *theSpline = createStudioSplineThruPoints(thePoints);
: {+ B. s! a: C3 I3 e/ i- w - 5 m$ X# \8 _' u, v0 w
- if (theSpline)
6 _4 n- `# `% r9 b: Q - {7 \/ _+ ~: f, H4 P! w
- theSpline->Highlight();5 F% r) @1 \7 P1 R
- uc1601("Studio Spline Created Thru Points", TRUE);$ m0 t6 U) P! q) x2 h/ o0 ~! D6 d1 L
- theSpline->Unhighlight();
6 h9 n) b/ `, f: b7 l - }1 k7 a5 b! f$ j. Y9 K2 ^
- }7 G8 \' t( D- U' |/ s$ I/ B
复制代码 / E1 u8 ]9 D5 h5 W' {
1 t5 F2 x) h+ C# n1 P
- D5 `, _* |4 V( B! R, b |
|