|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线; a! ]5 }. ?. c" I
- #include <uf_defs.h>
( H0 |4 N, P. b - #include <uf.h>
6 P: v$ }( G5 ~$ J - #include <uf_modl.h>
& B3 s. F! N- N; l! J - #include <uf_object_types.h>
% q! R; H" m( `9 c" K- _& ]# N - #include <uf_ui.h>
- ]8 B- O% }5 `6 {9 ` - #include <uf_modl.h>: n7 B& {. e2 ]+ u6 F+ l- v
- #include <NXOpen/NXException.hxx>4 G q. Q X' d6 }
- #include <NXOpen/Session.hxx>
) o7 k. Z5 s6 |9 d - #include <NXOpen/Selection.hxx>
4 X9 y1 |- n c( D/ X - #include <NXOpen/Builder.hxx>3 \+ M: e# `, T. U. `* W1 m" X4 h
- #include <NXOpen/Features_Feature.hxx>: v4 `% c7 j! G
- #include <NXOpen/Features_FeatureBuilder.hxx>
4 D2 K6 W+ K2 H; M - #include <NXOpen/Features_FeatureCollection.hxx>
: w u) U% z [+ ~ - #include <NXOpen/Features_GeometricConstraintData.hxx>2 s# }* J' m1 S9 y9 h7 i! A
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>0 V/ X; s4 P5 }7 n
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
$ z; d% T3 p; [+ l. i: G$ \/ @$ s: g - #include <NXOpen/Part.hxx>& t; M' @% P8 P; x% U' i. c
- #include <NXOpen/ParTCollection.hxx>! f6 ` ^0 b1 z& o
- #include <NXOpen/Point.hxx>- C+ y1 }' ]. _7 o' N" O. }$ I
- #include <NXOpen/PointCollection.hxx>, D0 z1 L& V e5 D0 d; |9 [: R
- #include <NXOpen/NXString.hxx>: U0 H' @1 t, b
- #include <NXOpen/UI.hxx>
4 N) j% n- L. H$ Z( r3 L - #include <NXOpen/Spline.hxx>
3 i0 I: L. n# v$ ^; q& | - #include <NXOpen/NXObjectManager.hxx>
$ y* y' S& `4 D: F9 e' l
. b% h* _, K) g5 N! F7 ~- using namespace NXOpen;$ Q- V$ u1 X# R* G& ~( z9 `* B
- using namespace std;# `0 w) ^( O, w
- 6 Q3 E q0 X) u; U5 U7 R* t
- extern "C" DllExport int ufusr_ask_unload()
/ l4 x$ U" ?1 G2 I: \ - {/ H9 [5 ~4 E( y. k8 V" G1 l9 z2 y
- return (int)Session::LibraryUnloadOptionImmediately;8 p- r# `' \! R" e: f E1 {
- }
) F0 q# \; o2 `0 N3 E9 S1 S
, B8 V! r, o1 h# U" p. ]- static vector<Point *> selectPoints(NXString prompt)/ |; Q; S( \. I5 o
- {
3 W! a' l. Q" ^' \( v1 O" W - UI *ui = UI::GetUI();% Z5 L3 J# n ]* M, ]) e
- Selection *sm = ui->SelectionManager();5 j U. s3 d( E/ _" }4 o( E; u
- std::vector<Selection::MaskTriple> mask(1);
; m: s/ a' \+ @ - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
6 Y0 m7 G$ D1 C/ G1 U7 w; m) n3 N - std::vector<NXObject *> objects;
6 q) s1 c7 _' ?9 j6 W! w - ' R$ E7 @# b( n) t0 p
- sm->SelectObjects("Select Points", prompt,6 J& l/ j* D/ A6 U" N
- Selection::SelectionScopeAnyInAssembly,8 U# s1 b2 L, n8 k% R
- Selection::SelectionActionClearAndEnableSpecific,2 g9 U& C- [' F) c n3 n+ j& y
- false, false, mask, objects);
. N0 X2 z/ u0 z% R' y0 |
; _" e; T7 A8 p' [7 b1 i' [- vector<Point *>selPoints(objects.size());: E. a8 }- n8 J6 q
- for (unsigned int ii = 0; ii < objects.size(); ii++)% {. B) t; {8 T) ?
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
- |+ c. [1 N5 `( M* B5 ]1 O - $ y0 b. ?/ P/ G( x5 D
- return selPoints;
* C e* e/ g! L# V; Q - }
) U0 c/ A9 o& G# \8 { ]/ w - 4 Z# L3 z1 L3 Q, U6 R+ u
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
9 J/ G% r9 `/ n - {
$ c! ~: |9 J/ V2 y: W - Session *theSession = Session::GetSession();
* l7 x6 M+ l. k* U* v9 V - Part *workPart(theSession->Parts()->Work());
7 G: k- b2 R( s! \* g: b: S - ) L7 H3 Q" { U3 Q7 ]3 g& Y) O
- Session::UndoMarkId markId1;2 {- ~3 T6 p* b3 q5 [4 _
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
4 ^! k4 m" A5 q& F4 i/ x6 o" \ - "Studio Spline Thru Points");
$ |# P$ t& J1 l- ]
1 L" \# r0 C/ x0 [7 K- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
5 F) R9 e E: d
3 a/ Z/ i7 P5 N( m: |. U- Features::StudioSplineBuilder *studioSplineBuilder1;% R! _$ o- {& _1 y, R6 M/ J( s
- studioSplineBuilder1 = workPart->Features()->9 A! c) _' J" ?0 N7 g+ s
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);" T( B0 L! A4 t: t( z; Q
- studioSplineBuilder1->SetAssociative(true);
" I w0 W) k0 \3 _8 S - studioSplineBuilder1->; |( _5 F a; x: L' a
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
3 i4 b( O8 G# M% A& @8 P - studioSplineBuilder1->
. J2 k# [* E" ^( N( ^ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);" e: S J& o1 v- @
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);3 F( @9 O' A4 E& C0 I
- studioSplineBuilder1->SetPeriodic(false);+ ~8 P+ C8 w* y0 L3 t: q9 e/ s
- studioSplineBuilder1->$ O" x& k1 l8 K. f) H8 K3 U
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
n1 e2 i0 z& x! E* z K - std::vector<double> knots1(0);
1 b; T6 `- p2 r, k - studioSplineBuilder1->SetKnots(knots1);: \+ x2 F3 J4 y
- std::vector<double> parameters1(0);
' e( V N/ J. q - studioSplineBuilder1->SetParameters(parameters1);
/ s! a& l+ J0 d, t& ] - Direction *nullDirection(NULL);
& h$ m; W- t2 S! G. N3 s. C - Scalar *nullScalar(NULL);
6 D2 u' k) {2 g& @- C' N. B - Offset *nullOffset(NULL);
) g( A5 c# k/ B) J% g - / M. q i$ |$ D( N( [
- std::vector<Features::GeometricConstraintData *>7 t# Z! B1 [5 c: j. y8 K, S
- geometricConstraintData(thePoints.size());
2 ^; E3 Y! r- a! H2 B6 T1 H( M
; r- }% P4 w1 @. \/ O4 y- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
. [% [/ r5 _( ?3 x - {
4 y+ ?/ }. g, x1 G8 u" O. }" m - geometricConstraintData[ii] = studioSplineBuilder1->5 e' |4 K( C( [& ~. P
- ConstraintManager()->CreateGeometricConstraintData();2 ?$ s; I5 }. e* q0 Z
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);' F# t8 l. f3 p' Y8 C
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
: A; O, R( _. a4 g$ k8 T - Features::GeometricConstraintData::ParameterDirectionIso);
2 Z+ g* y" U* n2 l& Q! W - geometricConstraintData[ii]->SetAutomaticConstraintType(
3 @/ N0 E) N2 q- P! R# p0 P - Features::GeometricConstraintData::AutoConstraintTypeNone);
: @6 `: f0 A3 }% n3 _4 l# v - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
- P" N" t1 H0 ?$ C a$ H4 x% ? - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
& a/ {! b: w; ? - geometricConstraintData[ii]->SetCurvature(nullOffset);. M: D+ Z4 w* Z4 ~* @
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! [/ m' v8 i' r$ {, R: r! [) y
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);0 Q6 I2 P o. ^; L$ g& A1 n, X; [
- }# q1 d. X/ w6 x" W& H: o
) l6 o4 Q7 |( H+ n X/ g% c- studioSplineBuilder1->ConstraintManager()->SetContents(
2 V. S: I7 w* V) C0 I' D/ U# J& L - geometricConstraintData);5 f- m5 j) a6 n: V+ Y
- # Q3 ~. ]( v; X+ J4 T- V
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();/ A5 x# j4 ^ a. }7 @ Z) K, z: k
- Spline *theSpline = studioSplineBuilder1->Curve();
0 q4 r8 ^2 E5 u, b9 { o
5 c5 X" R) D( c9 L8 @- studioSplineBuilder1->Destroy();
" v2 A0 F! ^: C. @5 ~1 z/ Z y
; G* p" u3 s( i k, W% H* j- return theSpline;! k1 o$ R' D2 }8 ?& h4 k
- }
3 q3 }/ C2 Y# V3 }- u g+ \' p
5 `: P; C/ K" Q! n: R1 `- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
( c* E! f9 B' w- u! X - {2 V: ^ D7 T, W5 K
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( H/ Z8 {5 @6 Z+ v# ]
- if (!thePoints.size()) return;# N, J. D& F' v! [0 `0 _
- ; d+ t3 K% h& c7 t3 s
- Spline *theSpline = createStudioSplineThruPoints(thePoints); ]) A$ {* `) ]- }9 @* n v: g
- n7 ^. R& j9 ~! T7 H
- if (theSpline)
3 ?; w. B7 s$ d - {0 [ K4 T- v, x- |
- theSpline->Highlight();
/ E- o5 n! p9 A0 f3 N1 f1 t U - uc1601("Studio Spline Created Thru Points", TRUE);( p) n) d5 X- m$ U1 l2 t! }8 b
- theSpline->Unhighlight();* \3 m& m i" d
- }4 F; O% m: V) Q1 \8 m# U) `% w8 P6 i
- }
. ^, H# G/ U; `- Q0 d. B
复制代码 # f3 w0 k' s, Y- @9 f5 a
i3 l6 ^- P3 ]
. ~: r4 o" t9 R0 N% K! z( I0 h9 O3 c6 Y ? |
|