|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
8 {( d9 F) R9 j8 p% Q- #include <uf_defs.h>
. u, D6 `4 P+ Y& q/ J - #include <uf.h>% E' L- X; `- Z# R c( W7 ~* I5 y3 a
- #include <uf_modl.h>, V2 u* A- Z5 j! M" \% ?' |% ~+ M# R
- #include <uf_object_types.h>, P9 q! T* @) H. \2 ^& l( B' G
- #include <uf_ui.h>2 z' B8 G1 S& A6 R
- #include <uf_modl.h> p0 l. U9 a8 J$ }. o" r2 l1 e
- #include <NXOpen/NXException.hxx>8 `( J5 V* s5 N3 p! s
- #include <NXOpen/Session.hxx># A( }, Y0 V n" @/ W
- #include <NXOpen/Selection.hxx>8 L: `3 \. @" n% N$ h$ O
- #include <NXOpen/Builder.hxx>2 D" q) i8 b$ I/ I3 O
- #include <NXOpen/Features_Feature.hxx>
9 O3 s5 X7 S$ k2 j% f' p6 b5 ^ - #include <NXOpen/Features_FeatureBuilder.hxx>
0 D2 G* }% @. O - #include <NXOpen/Features_FeatureCollection.hxx>/ ~4 p3 {0 W- R
- #include <NXOpen/Features_GeometricConstraintData.hxx> s! i+ l: }; Z# v
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
9 t( j0 J+ @# r! H7 |; k/ ^* p - #include <NXOpen/Features_StudioSplineBuilder.hxx># |( ]$ q: @' S
- #include <NXOpen/Part.hxx>
' a5 R( `/ o& W4 j. g' L7 g - #include <NXOpen/ParTCollection.hxx>
- {* w1 Y: q/ q8 c - #include <NXOpen/Point.hxx>) |: C2 p% _2 q
- #include <NXOpen/PointCollection.hxx>
* h" x# h/ |9 X3 B7 ?+ y3 X - #include <NXOpen/NXString.hxx>
: L- l: }! p* Z/ e. {- X - #include <NXOpen/UI.hxx>
4 Z) Q7 B% u; L8 j - #include <NXOpen/Spline.hxx>& G, J0 J2 t- @# K6 ?
- #include <NXOpen/NXObjectManager.hxx>
V! m+ p2 e4 U1 m- P1 _) l - - x9 r& B k8 \
- using namespace NXOpen;
) l5 }. u4 _3 ?/ d- L# ^! r0 v - using namespace std;
& c+ {; f! `( W# f$ X- X& g. K" L
; I6 B7 r: T" P- extern "C" DllExport int ufusr_ask_unload()2 {* ^2 g% d% _/ S$ Z# P% r3 }. L2 @
- {
" A, v+ \% B4 X! S% q - return (int)Session::LibraryUnloadOptionImmediately;
' a* ^; ^: p4 w- s8 C0 \ - }
- a, y# h2 j) U. X/ K, }) g& }. l
' U' B, D, V* i9 d# X- static vector<Point *> selectPoints(NXString prompt)
- z" a$ |0 U& t/ P0 [& l6 `3 R# @) A - {$ g7 C: R, s* j* _9 S3 _
- UI *ui = UI::GetUI();/ S% w d* c$ B3 v/ T, D
- Selection *sm = ui->SelectionManager();
1 m. ?, Z- \; q9 v - std::vector<Selection::MaskTriple> mask(1);8 V9 x3 Q. ^5 q4 ~" o8 p6 R
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);/ |3 [! I/ x, c5 r* @) \
- std::vector<NXObject *> objects;3 v2 m7 j, |0 X: J. {8 L u
6 Y) ^* ]8 b3 ~, i2 [8 m1 ]5 ]- sm->SelectObjects("Select Points", prompt,
' h" g. I$ c, ` M' T - Selection::SelectionScopeAnyInAssembly,' T: c+ N' C- C0 _; d' U; D8 |
- Selection::SelectionActionClearAndEnableSpecific,: j+ j0 z! K3 c, `; H
- false, false, mask, objects);
: d+ Z+ i4 b0 A3 B$ ~3 t# {& `) c - , U" ^8 Z# T. w) u9 K6 F! e
- vector<Point *>selPoints(objects.size());
+ t# z) m& |/ m+ K' u - for (unsigned int ii = 0; ii < objects.size(); ii++)
7 N6 ~. P8 z3 f0 ]/ f1 _" p5 c' k0 W - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 s; I* _8 i1 q) D# i* e
/ Y( S+ ^0 [) a- return selPoints;
6 f8 ^. s# q o S$ L - }; {3 `, w3 G1 A D5 p
6 f; n# v2 {$ g: ~6 ^% ?- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
/ e6 m8 l2 c) H' O5 g - {/ l {! p0 x/ y9 E: k
- Session *theSession = Session::GetSession();
9 R) |: S0 Z% e- O - Part *workPart(theSession->Parts()->Work());+ O6 g0 {; X$ r+ y: B4 I& _; P" r: Q5 d
- x1 r- Y2 S- K; P# ^- Session::UndoMarkId markId1;
0 H; J; K# g4 J! {4 o# A - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
0 h8 ]* Z& L6 K2 J; ~ - "Studio Spline Thru Points");
" l% X) J1 R! \: S5 l' \( j. O4 a! C% \ - / q: v4 H( s$ ]2 o$ K* l
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
# O* c+ _- _1 ~( }- z- \: ^+ p
, z+ \- b; D8 i$ t2 `+ D- Features::StudioSplineBuilder *studioSplineBuilder1;- E8 G1 n' f. c2 g% N* A c
- studioSplineBuilder1 = workPart->Features()->
- A( s/ h, ^3 @ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 B; r8 q5 O& v# Q1 p, y
- studioSplineBuilder1->SetAssociative(true);
/ i0 O% g2 T- O' ` - studioSplineBuilder1->
" ~2 W) }3 f7 N% O$ q$ W# v - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);! k4 \. J& W( J, _
- studioSplineBuilder1->% A2 F2 i0 W0 p3 l
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# k% w d% R5 V7 l. e
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
! k& @6 k% z. M% O# B& S! G - studioSplineBuilder1->SetPeriodic(false);1 z8 g, F6 {& i& \5 n+ V: l- P
- studioSplineBuilder1->+ L* L5 A4 E! s4 S$ k& r ^
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
. H6 l6 `9 ]2 g. i0 @ - std::vector<double> knots1(0);$ \" o$ b) a. x% _) S4 U1 b$ \
- studioSplineBuilder1->SetKnots(knots1);& h3 B5 L* ]; b
- std::vector<double> parameters1(0);2 m$ E9 j7 J' b6 K* Z# v
- studioSplineBuilder1->SetParameters(parameters1);
! Z& x) g% V7 m" e - Direction *nullDirection(NULL); `% T3 O _2 Y, D# ~# P7 X6 A
- Scalar *nullScalar(NULL);
- W, }. ^* @: l9 ] h, |' m - Offset *nullOffset(NULL);
$ z) g8 m4 d( n
- i2 i' ]6 Z2 X* c* p- std::vector<Features::GeometricConstraintData *>
- p! [- T M2 u1 ?% J9 N; M: ] - geometricConstraintData(thePoints.size());$ T( A4 {3 Q f+ T5 K* U' v
- ( Q* X0 E4 M5 U. {$ V2 m) Q. U9 r
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)# c! S: f5 @4 A% X% |3 O) r& i
- {
! ?! `" E4 O2 t* o - geometricConstraintData[ii] = studioSplineBuilder1->
- @) n# o, q! W" K1 m) {3 t - ConstraintManager()->CreateGeometricConstraintData();
% V1 ^1 v0 d% I) E- l6 V) c - geometricConstraintData[ii]->SetPoint(thePoints[ii]);/ {' M) t) t$ T' v) ~4 |% c4 l
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
+ p" k; w' ?( x' n& D8 r - Features::GeometricConstraintData::ParameterDirectionIso);
7 R: U" }/ R. z. H. F7 `3 C8 _ - geometricConstraintData[ii]->SetAutomaticConstraintType(
( E/ r. q* Y; n$ m7 H+ I( y: [ - Features::GeometricConstraintData::AutoConstraintTypeNone);
. i# q6 a0 d) m. K' \ - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
, I# B5 y5 G3 O - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
' h0 B3 r( v. E; V' g- L - geometricConstraintData[ii]->SetCurvature(nullOffset);
( ]; c1 T) Y! w9 y8 U - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
2 N" r( c0 \: g& X' d* o - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
# w% p% s( y! Y" M, M+ t ? - }
c: M9 R7 z2 B1 m - $ S+ @: i# Z( K% R4 {; v4 ^
- studioSplineBuilder1->ConstraintManager()->SetContents(
- t: A1 S3 v1 B+ v3 K; d4 u; e% | - geometricConstraintData);
+ l2 H& v2 [: Y4 |4 r8 r. P - & O5 r8 _" i+ U/ N. O$ Z( P
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, m4 |) O/ N7 r" r" E
- Spline *theSpline = studioSplineBuilder1->Curve();
6 S3 ?: b8 p8 s w
- y# f' \$ q9 s/ x% a7 L9 P- studioSplineBuilder1->Destroy();2 m* Y- |, X8 K% A1 n' V/ U# @* |4 q
- 0 w/ J. e3 k& v5 l- @: X7 d
- return theSpline;
: X$ z$ t/ y' X+ c( w - }
' ]: q/ L' q. S - & n4 x; c% W8 o$ ^6 U- N
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)2 h/ Z/ f9 ~" w9 u M* S' ]. b
- {
! f; c/ H! R$ B; H& U9 L' Q. Y+ B - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");; \/ r) P( F2 r4 E2 j% O$ ^4 n
- if (!thePoints.size()) return;9 Z# ]6 Q7 O- {: }9 Q' B
5 B% n% Z+ D6 g, I- Spline *theSpline = createStudioSplineThruPoints(thePoints);/ m+ Y2 K4 F% I9 g9 f1 j% ?0 t
7 z: D& ]4 y$ G+ |! H- if (theSpline)
% w0 r5 i, W3 Q% o" G: t - {
$ J; c0 E, s/ h# U2 I; e9 X2 G, ] - theSpline->Highlight();
& t% C% y- R7 H1 }* F0 W - uc1601("Studio Spline Created Thru Points", TRUE);
3 X: E+ ~6 s8 h' l - theSpline->Unhighlight();2 @+ @: X" n+ w0 _ m3 N
- }
( i% h+ d1 \2 h& a5 [/ g4 D% n' k" K. t8 c - }/ X2 i7 h) N0 a" }- P- V! S
复制代码
) A! R- g2 @+ }; @
( U( O4 A. M' S& `6 ]% \
$ K8 _6 g; e& R1 j7 w' a |
|