|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线3 E; e* r( i0 ^& x) J* K
- #include <uf_defs.h>
5 f# r& k& F. @3 K) l. k - #include <uf.h>8 ?8 n$ a* l v L
- #include <uf_modl.h>2 w6 v) S' E v5 d0 d- p
- #include <uf_object_types.h>& P- Q5 ]) i3 j5 {6 R2 T. J) I8 i
- #include <uf_ui.h>
) {- y7 s* m: z) ?+ r" e; H+ i$ Z4 [ - #include <uf_modl.h>
6 h6 f% T9 R0 p) S" A, w; M5 O - #include <NXOpen/NXException.hxx> Z$ ?" P' n6 [1 Q+ }4 N( ?. v
- #include <NXOpen/Session.hxx>
9 R; F& r8 R9 |' |( h7 {- i( M - #include <NXOpen/Selection.hxx>; U# \3 F: ]- Y7 y3 ~
- #include <NXOpen/Builder.hxx> x& M" z) H5 w% e
- #include <NXOpen/Features_Feature.hxx>
% x: r- ~9 y7 x. k - #include <NXOpen/Features_FeatureBuilder.hxx>
# [/ T3 p/ q$ c" T" M - #include <NXOpen/Features_FeatureCollection.hxx>
1 M# O1 @* m/ n4 \9 A - #include <NXOpen/Features_GeometricConstraintData.hxx>
. I- X4 C- ^6 u0 F - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
$ Y ~2 P4 A& d# s - #include <NXOpen/Features_StudioSplineBuilder.hxx>1 R# r8 A6 C- A: ~+ S
- #include <NXOpen/Part.hxx>3 N& G( i1 d2 A
- #include <NXOpen/ParTCollection.hxx>0 H; r1 z! z2 X5 k- D
- #include <NXOpen/Point.hxx>
+ C" P" M$ b8 K - #include <NXOpen/PointCollection.hxx>
- @! F& I' G( N+ O* T5 n3 W - #include <NXOpen/NXString.hxx>; ?3 y7 q: S* o
- #include <NXOpen/UI.hxx>
7 |, f" Y. r, } - #include <NXOpen/Spline.hxx>
7 V% j4 b+ r, y% x& ~; ?! d - #include <NXOpen/NXObjectManager.hxx>; a$ F. E7 c) D) @ g! t( {4 M
- , `* F6 l/ {8 G! N2 @
- using namespace NXOpen;( x7 B' `# V J2 E0 v
- using namespace std;1 C- l: d) m6 O; ^
2 L$ M/ N* S& H- extern "C" DllExport int ufusr_ask_unload()
7 m) G: V# k. @8 |6 j- i7 d - {
3 J: j8 ^% r: w6 X9 C6 g- @6 D - return (int)Session::LibraryUnloadOptionImmediately;- m9 d5 W) S( w
- }6 z' Z8 `* _$ R* G) r( V. e8 H8 K
+ O r y: J9 C9 [5 ^4 w- static vector<Point *> selectPoints(NXString prompt)
. W8 }& h- s( w# @, K' x - {" q! w+ z$ v- i% a9 ]9 ]; i& p7 V
- UI *ui = UI::GetUI();0 \: o3 u2 W G* m' X
- Selection *sm = ui->SelectionManager();
& r Y6 u1 N, t0 O/ |- c - std::vector<Selection::MaskTriple> mask(1);
2 J; c5 x1 E' @0 E7 U" L8 U' F - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
8 K3 v3 Z* [6 l. q - std::vector<NXObject *> objects;1 p* z# b& z# P! h* Q* e
- ) w4 {: o; a% G3 j& H2 q: U
- sm->SelectObjects("Select Points", prompt,
v5 O: y6 ~ Q8 l0 \3 `4 Y - Selection::SelectionScopeAnyInAssembly,
% G2 Y# H2 ~9 V# o# I8 M) l& R% ?7 Y - Selection::SelectionActionClearAndEnableSpecific,
7 c, m( d: ?' s3 `* J - false, false, mask, objects);) a4 \8 y* a! J" e- R3 G
( _+ ]! ~6 ?7 j; |3 A- F2 n6 `- vector<Point *>selPoints(objects.size());, X1 G6 B! s' c1 @
- for (unsigned int ii = 0; ii < objects.size(); ii++)8 E" Z8 T1 v9 r7 r
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 E G; q A+ m! I2 }
" A1 _5 x* t! Z* q& h3 U- return selPoints;% r' T' G- S) x3 z" L1 ]( ^
- }- q" P" F4 L5 `9 b- R/ v
- , W9 }( y* U+ N& ~& p' D
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
7 }0 b6 l+ T( i/ R7 c$ X - {
+ N/ \% F: q) q Q8 D/ k3 i - Session *theSession = Session::GetSession();
7 v, I2 [6 R1 W8 A# m6 v+ \; n' n - Part *workPart(theSession->Parts()->Work());8 n5 Q0 f. t4 G, \5 n$ c6 l7 [
R* `# l) T) x* @$ x- Session::UndoMarkId markId1;! _, J* |( }; q/ d- n0 n7 W; t* G, {
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
& v* F6 |2 a* i - "Studio Spline Thru Points");1 l! ? E2 k+ \9 C+ e
- 5 `4 W! J: z: ]1 ?
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
& Z# ]+ @* C! y2 Y
/ |% z7 j1 i* v9 f" q4 h- Features::StudioSplineBuilder *studioSplineBuilder1;4 a! C$ g- @* r$ o
- studioSplineBuilder1 = workPart->Features()->1 w0 b: S w6 {! ~6 M& I" D* Y
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
& o2 f8 N. C" u# B6 { - studioSplineBuilder1->SetAssociative(true);
0 C; D1 g: O8 n2 @! ]4 U( A3 Q - studioSplineBuilder1->' y+ L# q( M, G& _" c
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain); f& j Z, g* o" H5 n
- studioSplineBuilder1->
9 B, Z- Y/ [: S+ O, ]! I) u - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);- g2 V9 ]" Z/ I i$ `
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ t. G$ {0 K- N# ~- l1 r5 o* I
- studioSplineBuilder1->SetPeriodic(false);
) K; Q& _* c, ]. k! K - studioSplineBuilder1->
2 o! J* u, S+ k( |) L6 @9 z1 i$ A - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
5 ]5 U1 M0 N1 H. j: G( }; U1 r - std::vector<double> knots1(0);
1 C; z8 W! t% j( p4 D - studioSplineBuilder1->SetKnots(knots1);" ^( G/ \, N3 O! A% G
- std::vector<double> parameters1(0);0 u3 z4 U1 y S. G0 Z* ^
- studioSplineBuilder1->SetParameters(parameters1);
; ^1 I: o# P4 J k& ~$ i6 I - Direction *nullDirection(NULL);
( V2 D7 t5 a2 V - Scalar *nullScalar(NULL);
3 H4 O, ^% L* a5 g% C9 W - Offset *nullOffset(NULL);
0 D3 _* P. g- _3 D; Q - # v! a* e# V: g
- std::vector<Features::GeometricConstraintData *>
: X2 p/ o$ o2 E - geometricConstraintData(thePoints.size());
* O% Z' e1 R% d4 y - ( ?! S2 g8 q8 O% ~( q0 S: u
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)9 U* p" P0 D, D% Y
- {! @3 A. j5 ^5 }1 v
- geometricConstraintData[ii] = studioSplineBuilder1->
) D% o; j( n# k - ConstraintManager()->CreateGeometricConstraintData();
) \' t& [9 p% a9 I0 k2 | M' S - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
% }$ S2 K6 a8 }& R - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
2 T' S; y3 J" i0 c8 N! w9 _1 H7 E g, e - Features::GeometricConstraintData::ParameterDirectionIso);
# X' X& s8 w0 R1 r4 x* N! V0 ^ - geometricConstraintData[ii]->SetAutomaticConstraintType(
3 P6 {+ e4 q; D p* y) v - Features::GeometricConstraintData::AutoConstraintTypeNone);
+ H( ^' u6 ~1 Z - geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ K: O! W6 g# z' t
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);0 Y5 D/ n' H$ E# F+ f1 N
- geometricConstraintData[ii]->SetCurvature(nullOffset);! o, P' u' Q9 }5 J' a8 y1 r* _7 c
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
+ {9 O# g/ I# p1 ^9 B& c9 A/ W - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);5 [1 C( ^& W% n. D3 m9 V `0 m
- }
8 {* k$ c H4 y( _
4 c# h; {' g& {6 H9 k- studioSplineBuilder1->ConstraintManager()->SetContents(
8 ]8 b9 I* Z/ B: N8 J9 a8 V - geometricConstraintData);7 H6 @1 V5 }% h
0 u3 T- Z, f: \- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
5 k' j9 V- Q% d$ s% V$ Q, n - Spline *theSpline = studioSplineBuilder1->Curve();( p: M( r9 U( @4 V' y3 d' D
- 0 o* q8 A% y4 y+ i4 }* j" z/ N
- studioSplineBuilder1->Destroy();
J V( Z! D8 a - - C9 S1 @1 h# s- ?: w+ Y c
- return theSpline;: B3 L* Q) |6 l
- }
/ u. F: u5 B4 v6 ?
) h9 h6 ~, J9 |4 ~8 \- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)& c4 H% T4 n, y
- {, d1 O8 s' a) @7 n4 ]; t
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
4 @4 y1 ]0 g) V - if (!thePoints.size()) return;
! L% }9 p2 a/ y - * B. M- c& r3 \% u* E
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
9 @3 V& z0 T l7 r7 J" x/ T - 8 x2 C m5 D+ M9 |' [" v
- if (theSpline)
& ^( Q" l% d5 J: ^) T0 W" k - {( V5 ^7 d/ h3 b# c c6 }" \7 w& P5 f
- theSpline->Highlight();
0 D- {$ G K# s/ p - uc1601("Studio Spline Created Thru Points", TRUE);" {+ e, T" h1 H I) G P" O* {+ e9 m/ @
- theSpline->Unhighlight();
9 p; E6 Y7 D A$ b - }
. e0 n) @3 L' @' {+ z - }
4 w5 q4 D6 e$ S7 j9 n( r# E
复制代码 # P9 m& [: _9 A$ v" E2 D
+ s" I4 X; J. T3 _) T
' A5 I( Q1 t9 o6 v! Q |
|