|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线2 v* s, s# W7 C' N3 ~" Q
- #include <uf_defs.h>) i# ^) O. e& f
- #include <uf.h>' G. ^, y3 r7 W+ q. \, ~
- #include <uf_modl.h>
6 {2 o! A' q! K; l& F7 d - #include <uf_object_types.h>
c0 v* x% }4 E- s7 T - #include <uf_ui.h>
# _: S" o9 a0 R/ f C: y3 a - #include <uf_modl.h>1 ?# U. H+ I% U$ p
- #include <NXOpen/NXException.hxx>
/ [3 j, j9 Y6 m1 D3 K- m4 E - #include <NXOpen/Session.hxx>
4 i- r9 ^: B& o1 ? - #include <NXOpen/Selection.hxx>+ J. y2 E) i: k* n( i
- #include <NXOpen/Builder.hxx>7 T$ @7 p- v: Y o
- #include <NXOpen/Features_Feature.hxx>/ M3 y/ ^0 p& R$ C5 z- M
- #include <NXOpen/Features_FeatureBuilder.hxx>
9 J( G. L. w" }5 c% y - #include <NXOpen/Features_FeatureCollection.hxx>
/ I. o" q9 L( P: T5 ]7 K8 y - #include <NXOpen/Features_GeometricConstraintData.hxx>$ z7 h& U( X- b
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
( [, Z8 t4 J3 L4 x2 [8 ]6 t/ f - #include <NXOpen/Features_StudioSplineBuilder.hxx>8 J) L" F3 {& B
- #include <NXOpen/Part.hxx>+ o- g E8 T. Y* D' \% L9 U( q
- #include <NXOpen/ParTCollection.hxx>
$ Y$ W- Y& Y( ~# _9 V j - #include <NXOpen/Point.hxx>8 q6 B! ]: g( `3 G% z
- #include <NXOpen/PointCollection.hxx>
7 f. J% U$ E5 H( K O7 K: R - #include <NXOpen/NXString.hxx>" M* G% D! d+ L" \7 A" G
- #include <NXOpen/UI.hxx>
; b+ z2 _5 R- O# j# k. O - #include <NXOpen/Spline.hxx>
2 n9 M% K3 A+ y5 i/ m - #include <NXOpen/NXObjectManager.hxx>
' O7 \, n8 v$ g* I+ G" P - + p" p4 m3 c+ d2 D8 A4 B3 q
- using namespace NXOpen;
% g- B* j& G* C5 ], d# e" [/ L - using namespace std;6 A# w9 O& F8 g+ T' N+ r
4 D8 ]( Q, T3 T- N- extern "C" DllExport int ufusr_ask_unload()! M1 U2 N" N! [4 h
- {
9 z5 }( n4 v+ i" @; Y! o1 O" B3 M - return (int)Session::LibraryUnloadOptionImmediately;
2 q3 V2 d3 \5 Q - }
$ C8 J! S4 {# Y7 |- _ - , M2 e& ~& @, C7 Q
- static vector<Point *> selectPoints(NXString prompt)8 w7 i5 R2 O d% I y/ C
- {; |3 D8 c6 U0 c2 a% e- {; a2 s* y+ O
- UI *ui = UI::GetUI();
0 H9 R1 G( d0 n9 n1 a$ p - Selection *sm = ui->SelectionManager();
/ s; f0 o( j% y( C9 k; a. e - std::vector<Selection::MaskTriple> mask(1);# D4 `9 S, i$ \
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
3 `! U# q# m" Y: \ - std::vector<NXObject *> objects;$ a" _" ?' u {6 |* K' f( T
- 5 h7 K5 B/ w& k. u9 n4 I! R# I6 U- o
- sm->SelectObjects("Select Points", prompt,
1 ]7 @& x" |9 U, m6 Z8 T6 T& x' ^ - Selection::SelectionScopeAnyInAssembly,1 |; d, O% J, c4 ~. Z9 a
- Selection::SelectionActionClearAndEnableSpecific,
* B+ a+ g6 G% M! J4 M - false, false, mask, objects);
6 T+ D9 J6 C& z* o# X! h8 ] - 3 k" p m1 u7 l2 \! ?
- vector<Point *>selPoints(objects.size());
9 b' D0 c+ v4 N# V- R - for (unsigned int ii = 0; ii < objects.size(); ii++)
- }8 v6 P* [6 R Q - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# Q& n8 ]+ J7 G4 l3 w# L
% n4 n$ p6 g, h- return selPoints;
) C. s$ p, l+ M) M" L' a& z$ {, u - }* y, j7 I# U9 n0 X
+ `" A7 }9 R4 H% G9 Y/ P- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)' U- U' M# B7 A7 Y( q
- {
" g [% p0 _" `% ` - Session *theSession = Session::GetSession();- t$ _- T* g/ b3 B! T+ b8 T' H
- Part *workPart(theSession->Parts()->Work());
! m K2 O3 q# H( J0 M
1 K$ }1 z) E5 C) G- Session::UndoMarkId markId1;
: D( I3 E9 g. N8 K3 }7 {/ p; r - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,0 \+ |9 N) T1 L$ o5 h/ F' v! ^% @
- "Studio Spline Thru Points");- G6 c _2 |, h9 N' b8 }1 M
+ J8 p& ~5 h! z- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
3 D4 n4 q* o e" v
* v6 J) I I( i- Features::StudioSplineBuilder *studioSplineBuilder1;, ]3 y) U: O) W3 j
- studioSplineBuilder1 = workPart->Features()->* F) P2 _% w% S- U- Z1 f1 Y1 k
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
0 x/ e @5 J0 T: N0 w - studioSplineBuilder1->SetAssociative(true);- v8 r0 o* N) w, {
- studioSplineBuilder1->, `8 n' X) w! G- k* ?, E) g. ^( E
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
' m4 B* x* @- k- U" Y" y( K/ A - studioSplineBuilder1->
* n1 s8 x& w7 p+ }' [% g - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
4 p+ j1 m$ _" J' F" Z' w - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);, H$ V: e/ d6 ` e
- studioSplineBuilder1->SetPeriodic(false);$ ]6 W3 G- q1 F0 ] B8 Y( {$ J6 b
- studioSplineBuilder1->, \3 }; x) w* t6 |. K: p$ S
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ L, J" X* i' T: l, P3 A( R
- std::vector<double> knots1(0);
# O9 L" x1 }, C+ Y4 ]1 x | - studioSplineBuilder1->SetKnots(knots1);
7 b" x0 X/ j5 `4 \4 T- n - std::vector<double> parameters1(0);# D6 E& p# M" w1 K
- studioSplineBuilder1->SetParameters(parameters1);8 M& j; S$ {' @ x* l
- Direction *nullDirection(NULL);8 } C3 i& p( f. v. \; T; [
- Scalar *nullScalar(NULL);
. \, x5 V, a9 S: B5 ? - Offset *nullOffset(NULL);& d: E3 L' K) j T8 a
( k( U$ h3 n+ K6 M0 ]3 C3 h- std::vector<Features::GeometricConstraintData *> g; R; S/ p6 n/ |$ F1 g. f
- geometricConstraintData(thePoints.size());" o! h0 f; ~* O
6 p0 k9 r5 [/ e! N9 l; d, V% `- v- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
2 k6 I4 c! S$ i! l4 \9 T - {6 k1 H% H% @) s
- geometricConstraintData[ii] = studioSplineBuilder1->
% m$ `9 Z4 z( V5 [# q - ConstraintManager()->CreateGeometricConstraintData();
% M; V4 u4 H1 ?, V; d0 x7 i - geometricConstraintData[ii]->SetPoint(thePoints[ii]);, ~# n; @; P7 @% X* R
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
/ W- z+ F% f- K, L4 s - Features::GeometricConstraintData::ParameterDirectionIso);3 A" } ]. G: u, a* I1 i) l
- geometricConstraintData[ii]->SetAutomaticConstraintType($ S$ N3 |: ~0 G6 u" w$ W' ^
- Features::GeometricConstraintData::AutoConstraintTypeNone);
$ E. R0 d7 E5 {7 { |2 { - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
Y* J$ ~9 f. M* }+ S4 C - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);- c- ~/ u7 E: n* `# C& Q9 w& h
- geometricConstraintData[ii]->SetCurvature(nullOffset);$ j, z* ?5 f+ y9 K; o
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 I0 r. K, w% U& I7 Q5 G
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);: l, X+ m& i; \! v- x6 d- [7 z' u$ D
- }5 q& C. Q. R2 L+ {- b% C
- 2 E2 g+ Q9 f' \# `
- studioSplineBuilder1->ConstraintManager()->SetContents(" o9 p* `" ~; E, v$ t
- geometricConstraintData);2 U; n3 }, S( \& c P3 m
4 K# `1 l, w5 P8 C6 J9 E- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();: {- a- T1 p0 d1 s
- Spline *theSpline = studioSplineBuilder1->Curve();
1 P" u5 m; B9 \9 K$ s# v9 C( U
, \( u% o. W# _! h! M' v- studioSplineBuilder1->Destroy();
! `- m5 P5 I4 Y' D; r - . J/ ~( q' O S: @
- return theSpline;
! B$ v9 e* i5 J. j$ L. f( r" ` - }
% G4 n$ `9 A+ K' |0 |6 y - : o0 ~6 a' }$ u& Y, `# {
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)% s) L; f4 K; ?2 p' n
- {+ t6 o2 ~6 a) L7 e# u
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
3 M: l4 f- x: r5 g6 H- k# c% P2 c - if (!thePoints.size()) return;
) t, q% l3 U: ~5 Q - 6 S: u% o- ~! y3 h/ Y2 N
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
8 g' Q$ T7 @/ w3 ~8 X - ! B( U+ _: Q3 d9 l; O
- if (theSpline)
" {1 I/ L8 r3 _ _ - {
" R8 ?7 B6 {6 }; Y - theSpline->Highlight();
$ w! j# J# D/ f3 V9 X - uc1601("Studio Spline Created Thru Points", TRUE);
3 S7 r6 C- @9 u* Z- [ b9 P - theSpline->Unhighlight();6 E5 K) j% \- M9 m; |! z- X: _
- }. A) r6 ~( ?9 u. G5 S, f
- }# H3 n- U2 v/ ?& Z
复制代码 ) ?& S1 R. k2 P+ t# h9 l) Q
7 p0 i( r5 V, s5 Z& F# C# t
( J2 L! Z: b% s0 L+ c% a6 C |
|