|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ u; F2 R4 y- a) ^( s$ h
NX二次开发源码:通过选择点创建样条曲线7 e: }! `7 n. |2 ~! p# N2 f
: r* b& a+ l3 k; F& I, L( \6 E( Y: q8 D
- 0 i8 p+ s! j, u7 o
- #include <uf_defs.h>. v" F, H& t) Y8 W% _! D$ K; k
- #include <uf.h>
( C1 F6 M! Y& A7 C8 U - #include <uf_modl.h>0 _: J" K: M" H+ N
- #include <uf_object_types.h>. ^+ T' Y) ]8 e) O
- #include <uf_ui.h>
) k/ y- W4 c U. | - #include <uf_modl.h>
p1 o% \% ~' ~. W$ L! @( w - #include <<em>NXOpen</em>/NXException.hxx>+ B; n+ D `7 p( \, \
- #include <<em>NXOpen</em>/Session.hxx>
5 W5 u- M0 m4 u- w8 |! Z) y! N4 ~- T - #include <<em>NXOpen</em>/Selection.hxx>
) d' \4 b/ }$ V4 `3 ]. q0 C" U1 t - #include <<em>NXOpen</em>/Builder.hxx>/ _9 O# B( _8 r: s% M: ^
- #include <<em>NXOpen</em>/Features_Feature.hxx>
1 z; r. }6 t3 U( x) E3 X8 h& x - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>0 u& p0 Q3 m; k1 G6 B6 ?
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>: l$ Z! T( G% j& d
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
- Y+ e3 k6 }3 H: B( n - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>' Z) Q* L, g2 j0 ]
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
7 h& \' g" A7 K" E! j3 c. y - #include <<em>NXOpen</em>/Part.hxx>
3 m: r8 Y g8 p3 W- D' d - #include <<em>NXOpen</em>/ParTCollection.hxx> n! J1 D/ I4 L4 ~2 i
- #include <<em>NXOpen</em>/Point.hxx>
7 e4 K& P' n. V; X - #include <<em>NXOpen</em>/PointCollection.hxx>& x; \( d/ p! k- d& C2 f) @! Z
- #include <<em>NXOpen</em>/NXString.hxx>
% J& ?' r# b7 D6 O% U. i ^' Z - #include <<em>NXOpen</em>/UI.hxx>
. x1 I, q. z7 R( K; Q- D - #include <<em>NXOpen</em>/Spline.hxx>
2 k2 y; K8 L. i% o& s/ ^ - #include <<em>NXOpen</em>/NXObjectManager.hxx>; H( m# f4 s; Q# H# N/ N
- 0 ^5 O$ A2 |3 y
- using namespace <em>NXOpen</em>;% s" Z0 L: T1 }0 R/ E
- using namespace std;
7 T% E1 [0 Z/ I+ Z: U' `
I1 d: }$ o) A7 R: P- extern "<em>C</em>" DllExport int ufusr_ask_unload()
+ i. N% c2 X0 o q" G - {
$ } _! h; v8 r, S @& \ - return (int)Session::LibraryUnloadOptionImmediately;# i: s0 v* S" v9 S* C
- } ^3 C. v) _$ F
! l8 Y2 X6 f6 `7 K2 n# o- static vector<Point *> selectPoints(NXString prompt)
; ]/ w# H T5 ` - {" f/ \8 X, D* P" }, h
- UI *ui = UI::GetUI();
+ q8 B6 O3 s3 ]% n [ - Selection *sm = ui->SelectionManager();& A) g; T+ r, p% N
- std::vector<Selection::MaskTriple> mask(1);
! K) q6 y1 @* f U4 w - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
* z) U0 n0 k8 g, W# V: w! I - std::vector<NXObject *> objects;
. v2 l `, l! z. E4 z1 G - h7 l2 w- B8 N
- sm->SelectObjects("Select Points", prompt,$ E1 w' e! C# W# `- i$ h
- Selection::SelectionScopeAnyInAssembly,5 z e, Z' n8 l5 x) W1 |* q; L [; K
- Selection::SelectionActionClearAndEnableSpecific,
# O z+ B; E9 k! B' k* g) l. `) y7 s - false, false, mask, objects);: h3 R) ] T7 `' I" B0 f$ q# m
- b. M. U: D Z$ [/ f f) {
- vector<Point *>selPoints(objects.size());1 S4 U0 R8 m( a9 T
- for (unsigned int ii = 0; ii < objects.size(); ii++)# A, _ P% _7 W/ F2 I
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 i6 Z4 S( v* Q. U
9 {8 Z4 ^' I) N' o- P/ }- ~. E/ X* b/ t- return selPoints;
) q' y5 D9 J, F1 j. u- Q- ^ - }
; D4 t3 A5 E/ e - 6 B1 I3 I' G! [: m8 a
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints), L) r9 w) M2 g7 l# E: m
- {
4 c% _# V( b; g; u0 |6 G6 @ - Session *theSession = Session::GetSession();
, p/ T( i( b$ a" R* I0 Z - Part *workPart(theSession->Parts()->Work());
: J! J( w$ ^; \( {, } - : `0 V5 A" l6 v( U/ g& W2 x
- Session::UndoMarkId markId1;
- q! `) B% D0 M0 w - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
7 T! x/ j& c/ H4 s J( b - "Studio Spline Thru Points");
5 M9 b0 q3 P1 }% _ - 5 F h3 }2 i/ F
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
! I# d# N7 ~7 b. y$ ?: Z( P P - 4 f: a9 Z; G7 X2 r( a
- Features::StudioSplineBuilder *studioSplineBuilder1;; J9 J2 g& A1 r8 S3 @1 U
- studioSplineBuilder1 = workPart->Features()->. R. ?- | T+ W% z. `
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);+ b0 ]0 g/ z" w- r6 {* H
- studioSplineBuilder1->SetAssociative(true);& \0 z: ?$ T$ Z) H- V
- studioSplineBuilder1->7 k9 j' X4 M# o" _7 p9 l# P2 C: Q
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);8 ^" Z0 c- f( O1 }5 t7 }# A
- studioSplineBuilder1->
: N+ h$ q0 m8 | f) A. w) c5 @ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
4 {0 d; {5 z, S. _# ^% k - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);3 L: U s8 [' C& V) a8 k a
- studioSplineBuilder1->SetPeriodic(false);: L7 J$ z# f1 Z4 l; \( c
- studioSplineBuilder1->3 j" h6 Y) H I6 V* q
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);# S; I, n. m$ I& t" ^" U. A
- std::vector<double> knots1(0);) K3 Q( p$ Z: [0 O" f1 U2 m
- studioSplineBuilder1->SetKnots(knots1);; \6 r5 n6 G2 T
- std::vector<double> parameters1(0);% w! ]& Z6 ^& F
- studioSplineBuilder1->SetParameters(parameters1);9 v9 M" O9 W4 m A. c o
- Direction *nullDirection(NULL);: |0 \, L9 ~. Z7 t' ^
- Scalar *nullScalar(NULL);5 [" B4 m. l3 \0 l6 R' _* W
- Offset *nullOffset(NULL);
8 U/ L/ J" M8 G' H
3 A, H. o3 Z7 F$ q+ N2 w- std::vector<Features::GeometricConstraintData *>
/ \% a4 b1 i5 m2 v9 u( a - geometricConstraintData(thePoints.size());- \* |+ X4 W4 I9 n9 u
& L$ ?- G2 J) t0 x; R0 K) ?; C- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
* m2 c V L$ P' _5 T+ N - {
; p/ s |' T8 g. @+ s9 h - geometricConstraintData[ii] = studioSplineBuilder1->, |6 m6 r J+ V/ E# Z6 N3 D
- ConstraintManager()->CreateGeometricConstraintData();- q2 i+ E; C4 T% {9 W* w4 G3 c
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);, Q3 I+ ?5 J/ l6 ?+ S& ?! l
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
, ~ }: [, u9 E# L' H/ o' J& | - Features::GeometricConstraintData::ParameterDirectionIso); R9 p4 A H8 C; R/ z
- geometricConstraintData[ii]->SetAutomaticConstraintType(; k t4 W/ Q: M6 H/ L
- Features::GeometricConstraintData::AutoConstraintTypeNone);
& Z9 D) H: e9 a; V/ r - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
! S9 Z" s8 R# e' i2 R$ r - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
5 q$ ^0 U, H f0 O/ o1 B - geometricConstraintData[ii]->SetCurvature(nullOffset);
) r" B% j, q, g - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 i; ?) S+ b2 k; _. {
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
- R: F3 M# e5 l0 ?/ j: r# m$ s2 Y2 y - }. ^8 m5 s( S, K$ E" p9 e
- 9 F+ ?. Q8 ^! b. b
- studioSplineBuilder1->ConstraintManager()->SetContents(, E( T( v |2 z
- geometricConstraintData);# H+ N3 {( D$ |8 E) g
- % q& ~( N/ F8 O
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();) P4 P2 ]0 n2 t9 B& E
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
; f9 m+ n& b( G$ j; o! b+ z - - t9 j# o7 K* x9 N! c! Z& g( j# }
- studioSplineBuilder1->Destroy();1 e- P2 w- y& C& M6 n; a
- # y' j: a3 A. Y5 c
- return theSpline;
& M: L w" N' r# f2 `. W. j - }
2 x- V' k( @& w4 o9 E& C& ~
0 B" d3 {4 V% y3 `0 W# `- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)1 t2 G( p9 `0 _, K
- {
% C* @% K3 W% S+ R Z2 p; K5 k" y - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
" H6 C; P3 ]* c& E% O1 m - if (!thePoints.size()) return;2 Q! T. Q. q s* k6 p* [
- 0 g* |# `6 S; f4 H# T
- Spline *theSpline = createStudioSplineThruPoints(thePoints);% `4 J# Y% L) ?5 |( d9 L4 X
, Z7 i' `! L2 ^' i' e* D7 [1 p- if (theSpline)
7 I2 o$ ]4 @. R! t6 T! g1 ^ - {
( U f6 R9 ?( a, ~ - theSpline->Highlight();
/ ?3 g- n5 T, @+ h3 m2 K - uc1601("Studio Spline Created Thru Points", TRUE);8 E6 s2 F1 h' B2 K( g
- theSpline->Unhighlight();7 i4 ]& P% ^5 t
- }* a# l/ d O `( q
- }
: Q) G: x Y2 v( T - <p> </p>
复制代码
# z& M4 N8 R! [1 Y |
|