|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线7 s8 ?" r0 L; e1 o$ y4 v
- #include <uf_defs.h> L- p$ M1 J: J9 W4 a
- #include <uf.h>6 N9 f( k, R/ R8 V
- #include <uf_modl.h>
9 ^* i! s& n0 c# g0 ? - #include <uf_object_types.h>
, Y* G$ ?5 p! L, e1 y- k- F - #include <uf_ui.h>
$ N/ r3 W8 P7 X( s8 k8 r" B - #include <uf_modl.h>
( p5 |1 o: r/ k; q' M - #include <NXOpen/NXException.hxx>
7 w4 ^7 y1 j3 z9 F9 s. k - #include <NXOpen/Session.hxx>* ]1 R+ J6 v# R' M; }
- #include <NXOpen/Selection.hxx>" C8 U5 z8 f: N
- #include <NXOpen/Builder.hxx>1 }( @% n. Y$ k
- #include <NXOpen/Features_Feature.hxx>% s& {# H5 U" y% ~8 U2 l' x
- #include <NXOpen/Features_FeatureBuilder.hxx>
) N4 M# H3 T2 @. O- q% Z - #include <NXOpen/Features_FeatureCollection.hxx>" a# P2 H) X2 [! o$ Y/ K
- #include <NXOpen/Features_GeometricConstraintData.hxx>
: @' E/ ?/ N$ m1 g - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
, V3 f8 Y# y6 @6 U/ G8 W) v/ x - #include <NXOpen/Features_StudioSplineBuilder.hxx>
9 n* S& j) o4 U9 o: K* r! i/ A - #include <NXOpen/Part.hxx>( K# s2 C a& m0 W7 k* `4 v; m5 F
- #include <NXOpen/ParTCollection.hxx>% t3 _5 Y4 y* }8 w9 K' Q- ?
- #include <NXOpen/Point.hxx>
/ [- v2 Y* [, [$ _ - #include <NXOpen/PointCollection.hxx>
1 {; \, f$ B% [: \$ V7 G - #include <NXOpen/NXString.hxx>3 _& ~: ^* u9 i
- #include <NXOpen/UI.hxx>( i( } \3 Q4 G2 L8 k, |
- #include <NXOpen/Spline.hxx>% {" H6 a: X/ T' ~2 P* \. Z7 u
- #include <NXOpen/NXObjectManager.hxx>. P$ t$ b3 O: d9 W
- / ?/ a' \4 U% F8 o! B8 o
- using namespace NXOpen;9 L+ z5 {+ ?) g, ?: `+ m: A
- using namespace std;9 l9 R% j$ q2 {' p
- Q$ m, ^, H% F# G* t H( Z9 p
- extern "C" DllExport int ufusr_ask_unload()
+ Q1 [. l) {! a+ U0 H4 r: a - {
& c" _$ L% I1 G - return (int)Session::LibraryUnloadOptionImmediately;
p3 n- N! h S9 n - }
* n" N C; k+ R# w+ [
7 D# b3 J" M- y) f# {7 n- static vector<Point *> selectPoints(NXString prompt)
! P0 v) T( I% c- O/ _* ^/ r" p - {( n) L! L; C+ T, K0 B! m! o( o
- UI *ui = UI::GetUI();
% H _2 \8 ]- ?* \5 E" P7 p' Q3 S - Selection *sm = ui->SelectionManager();( W! E! ]8 Y) w. @% b9 j
- std::vector<Selection::MaskTriple> mask(1);
0 h# o, X9 t; @2 C - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);0 X$ U* Q6 b" \, @" g S! z+ e
- std::vector<NXObject *> objects;1 G9 L+ \3 g# F8 h1 e: S, F
- 1 X ^: e3 X: x2 V1 i& r
- sm->SelectObjects("Select Points", prompt,% d# `# I2 d8 i5 u4 A. F
- Selection::SelectionScopeAnyInAssembly,0 x6 k. L; [7 e3 M7 g9 r" G
- Selection::SelectionActionClearAndEnableSpecific,9 U7 Z- J ]! `/ |2 X
- false, false, mask, objects);
0 \+ u/ F: P0 N2 s - " c: F) E% \9 l5 b+ ?# \
- vector<Point *>selPoints(objects.size());
5 C2 Z; c7 v- e% ? - for (unsigned int ii = 0; ii < objects.size(); ii++)
3 R2 I) o( B& d0 ~7 c1 K - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
0 D `/ F6 n$ A# Q. ~' \3 q
3 Z: g6 C9 a" ^- return selPoints;
/ X2 }. u( _4 C4 C# ~3 S M5 }6 i - }
3 [6 v# W# w) l9 z: ^2 C2 p4 p
6 @* T# i q; Z( ?3 h- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
7 b) X$ W, r% L% G) @4 M. e - {3 q; b% J4 U, L# v3 v
- Session *theSession = Session::GetSession();) A+ o( F# r0 z& |: W+ Q7 P
- Part *workPart(theSession->Parts()->Work());
; I# c( S6 @* z2 x+ F2 O/ v - * X$ j7 [% S4 E0 a5 u$ u& o
- Session::UndoMarkId markId1;' w; |5 @! u6 k8 ?
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
4 R R$ _8 h/ u - "Studio Spline Thru Points");3 V& {) V& G8 o" L
) S+ R+ D) v0 b7 \( L* J- Features::StudioSpline *nullFeatures_StudioSpline(NULL);% i- p" H! n# G N4 L
1 f" N! a% {" F% q- Features::StudioSplineBuilder *studioSplineBuilder1;4 ~ p; d+ B3 H( O- W
- studioSplineBuilder1 = workPart->Features()->2 T$ o# i' q+ @- B
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
; k, h: d: N$ ~, q: \ - studioSplineBuilder1->SetAssociative(true);, P. F4 L0 y4 D @( H* G
- studioSplineBuilder1->
) U5 n1 Z' F! I0 K9 p7 k8 @ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);8 h; N: E5 g7 t. l' m) z7 y
- studioSplineBuilder1->
! c/ n' X4 o# M* [8 w - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* d% k0 @1 w5 R' D, F4 B
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
( B; A2 O0 n' _# H0 U - studioSplineBuilder1->SetPeriodic(false);
& g2 Z8 {- d1 Q' Q( Y8 s" ~ - studioSplineBuilder1->
& e; ~, v' g3 { - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);2 q# p1 e7 o; C4 H: B k9 u- g
- std::vector<double> knots1(0);$ _# ?- k1 @, U& A4 I% k
- studioSplineBuilder1->SetKnots(knots1);: k0 L* e2 R5 W; B" @4 F* V( b; S/ [ S
- std::vector<double> parameters1(0);) P% T) |9 }& F. Y/ t6 p
- studioSplineBuilder1->SetParameters(parameters1);$ y4 o$ @8 r# }9 u1 s: @
- Direction *nullDirection(NULL);5 r8 v! m$ A$ I8 J2 v$ X( }7 F
- Scalar *nullScalar(NULL);
! D$ T7 u" f. t" b3 K - Offset *nullOffset(NULL);
: c, ^4 \. b$ L: J6 ]( N
5 i2 m+ X/ |' P% b% `$ z- std::vector<Features::GeometricConstraintData *>6 p5 z- `- k( A, j
- geometricConstraintData(thePoints.size());
) B: u0 F: w2 k" ?; C4 }0 i
" F0 l* x I- w, L' d( G- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
) { V# @, l2 I& |+ ] - {
6 u1 t/ d, n% p+ h, C4 w e% Q& k - geometricConstraintData[ii] = studioSplineBuilder1->
+ ]8 y9 @ ]" M5 I - ConstraintManager()->CreateGeometricConstraintData();
0 {$ V1 J2 _+ X: c# | L) o - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
6 C3 P* T) h& F& l: U - geometricConstraintData[ii]->SetAutomaticConstraintDirection(* t; V' g' ]3 h3 g
- Features::GeometricConstraintData::ParameterDirectionIso);
/ }' l7 d2 O0 H# @) u, Z. X. d - geometricConstraintData[ii]->SetAutomaticConstraintType(
K) |5 G( \ @# Q0 E% h b: u - Features::GeometricConstraintData::AutoConstraintTypeNone);
; a* Y5 } M7 ], K) t0 E( S - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
2 @/ V2 c/ F# C* F - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
) @4 ~+ y" f. @' h# @2 O# ?( Z! Y - geometricConstraintData[ii]->SetCurvature(nullOffset);3 _1 k2 j3 z( Y; W! z- p' g
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
! Z" h; E) J* H$ ?+ t! {+ \ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false); p- k# K* g4 }( q2 N. v
- }* C8 b1 ]8 A! |
- ; b* E: U p' D2 t7 ]2 @ D
- studioSplineBuilder1->ConstraintManager()->SetContents(
& @% P% Z8 U5 g" M" b/ |/ m - geometricConstraintData);
1 q: V+ @+ {4 @+ j1 ? - . T7 u& n0 S4 d4 ?% ^+ Z# Q
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
$ _9 Z, \; B6 `, b# | - Spline *theSpline = studioSplineBuilder1->Curve();
& x ~# Q# o6 k w9 `0 W2 x, p0 k
" [( @; [& m+ ^/ f$ Q8 j- studioSplineBuilder1->Destroy();" T4 s# J/ c5 \0 f
- ( L& E! |8 a8 o' c' E8 E; V
- return theSpline;; g! [. J) ?( G; V/ C2 e
- }
: z; f" e4 K: E - 1 O# r9 D- B9 ?, X
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
6 v0 n0 H$ n- y' L/ s8 u; t2 b - {
: \. u' N, b+ b7 M+ I8 n3 x - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");5 p6 X R# T" b( O8 R% {/ v* { Q
- if (!thePoints.size()) return;7 |3 I. \( m* L$ C# C' H
- 0 @ r; J" C8 ?1 k# V
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
# J: q6 e: M9 c) A* D0 [' L( ~7 e; t+ V$ W - & J- t) N* @# Y& b+ M6 x" v( P* O
- if (theSpline)
; ^9 Y, B, c3 k! n% F - {
A+ L0 C( o8 ]9 j6 ^. C" z - theSpline->Highlight();
$ J' W5 X* Y1 Q) G( n2 R - uc1601("Studio Spline Created Thru Points", TRUE);% }4 N! y. `7 s# @9 L
- theSpline->Unhighlight();# } `3 L' z2 t
- }
) u; i* k: |+ y- A' m' @ - }
% c7 l( [- J8 G( c
复制代码
* n( W# w3 I! s* v- U& S. A6 Z
+ H5 i4 o" A$ x _7 R9 d- Y
5 B7 x1 ?/ \) N3 K$ L |
|