|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线+ {3 ^' `# Y k. e) Y* d
- #include <uf_defs.h>
! J, k- l1 y: W1 M6 V" a2 g - #include <uf.h>
; g. a: \& Z& I+ z: B# S9 B! O - #include <uf_modl.h>; E0 s1 F& z2 Y) h
- #include <uf_object_types.h>3 p* n/ S: n/ X8 U$ g, N
- #include <uf_ui.h>
( K. X; D" }$ r' D - #include <uf_modl.h>
0 q1 M+ p3 T1 x1 n9 P - #include <NXOpen/NXException.hxx>3 q* s4 i0 H1 z( J0 q) w& y
- #include <NXOpen/Session.hxx>
7 U5 V$ G2 {: b+ B* o - #include <NXOpen/Selection.hxx>
& _" ~2 J' J# f7 R+ e. o) S% N- q* P - #include <NXOpen/Builder.hxx>
4 o' d2 {) Q/ E, P( \6 h# ?! \ - #include <NXOpen/Features_Feature.hxx>
. T% I) [- ^! B - #include <NXOpen/Features_FeatureBuilder.hxx>
9 i, Y" d# s/ j' q; W - #include <NXOpen/Features_FeatureCollection.hxx>
" c- ` w3 X$ f: x9 d% S- ^ - #include <NXOpen/Features_GeometricConstraintData.hxx>
0 Y+ X5 D# f. r, i. A0 _+ I - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; T# g7 p1 @! D7 G9 Z1 Z% ]; ?
- #include <NXOpen/Features_StudioSplineBuilder.hxx>7 a5 i ]$ K+ H5 c% s2 p5 Y
- #include <NXOpen/Part.hxx>
/ ~2 m$ Y9 y2 D - #include <NXOpen/ParTCollection.hxx>
v4 q) G, G/ l% Z& J - #include <NXOpen/Point.hxx>. w0 P1 I6 h- g0 q' \( p
- #include <NXOpen/PointCollection.hxx>
+ A7 P3 }, W$ m" a4 D3 a - #include <NXOpen/NXString.hxx>
! r( i: V. ~+ S0 T - #include <NXOpen/UI.hxx>9 w( s: y! g, Y: c* {1 _8 b9 m
- #include <NXOpen/Spline.hxx>
4 S6 P+ ]( [" O& q0 o4 D( {( C - #include <NXOpen/NXObjectManager.hxx>
. e- y l) w% x* y' ]% b. A
5 d* s+ _4 P- ]1 v$ G. r- using namespace NXOpen;
. E* @3 v; @$ ?" x. q- |7 E - using namespace std;! o1 Y* A4 |- a3 e' P0 g/ B, N
- 6 N0 P Z5 ^% i+ L7 l
- extern "C" DllExport int ufusr_ask_unload()( N" P$ m( }8 f3 S7 F$ T3 L
- {
" X1 E N0 \8 ]& q% Q, E2 w - return (int)Session::LibraryUnloadOptionImmediately;0 V# L: {1 I$ R; S( v8 K8 S. Z5 r) e
- }$ Y& k7 }6 g2 h) U. h" D- l: y( e
- & I. |, P' q) q- h
- static vector<Point *> selectPoints(NXString prompt)- k2 |: \* `# g( l/ z
- {
9 i+ e) Z% L+ [3 M; ^: k q - UI *ui = UI::GetUI();, x8 g' O$ K! T7 F& X
- Selection *sm = ui->SelectionManager();0 Q/ \/ _. n. n5 Z+ X4 S
- std::vector<Selection::MaskTriple> mask(1);1 P3 W& _. c4 F/ d9 f A' b
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
9 O* d. s) e5 i* B' S: L - std::vector<NXObject *> objects;# x# L8 N+ k, J& U2 A- W
% [$ \* a7 F9 p, v2 V+ h# K- sm->SelectObjects("Select Points", prompt,
0 T& x+ }9 U+ R - Selection::SelectionScopeAnyInAssembly,$ _% w- y9 d8 _. _$ p( D
- Selection::SelectionActionClearAndEnableSpecific,) S j1 N7 a' t1 c( ~
- false, false, mask, objects);
2 m9 W1 c& C& G( R) z/ ^& a - 6 X: K2 a5 D' j: i
- vector<Point *>selPoints(objects.size()); ] }6 W" H- P: c, }" x
- for (unsigned int ii = 0; ii < objects.size(); ii++)
- U, U" b' f# |. l- Q - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 ^2 W' u' l0 ^: i' e+ Z
% a: m* B, A% w+ m3 h- return selPoints;
- ?9 z4 O- o# h p# ^) N9 F - }, s1 Q+ _( U# y2 U$ t$ W
- 3 G _# b+ z4 H2 \, g' m: r
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
: i6 G7 ]+ _. w; ], _3 R Q# j' Z - {8 _ p$ s9 M5 p) j6 F- C: N
- Session *theSession = Session::GetSession();
2 P0 `6 h9 G8 S, [5 Y1 E - Part *workPart(theSession->Parts()->Work());
/ y& ?! i( b2 h$ S$ H+ x( H
/ H. X. @* g3 H2 ~- Session::UndoMarkId markId1;
- Y( H! s* F% x E4 m3 b! Z) m - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
( g V# P+ K- e- P+ X - "Studio Spline Thru Points");! j4 B, g5 R8 \6 v7 g/ ~2 ]# f7 c, u
, z! V, ~1 [9 L/ d/ c \- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
( X7 y3 m, t. F: C: M- I$ |$ T* P
4 f( P Z6 g+ w7 z) k' X; _& h- Features::StudioSplineBuilder *studioSplineBuilder1;
' O! I( } V. o - studioSplineBuilder1 = workPart->Features()->
4 y! X6 g9 d$ I' D# Y: c/ ~ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
5 @' P7 r+ E- s* d3 ^2 ?, m9 G - studioSplineBuilder1->SetAssociative(true);
$ Z1 ^, d$ a8 U3 S - studioSplineBuilder1->
7 j7 D) D# Z6 D* U - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 ^0 a5 {$ V6 u: ~1 h
- studioSplineBuilder1->
# {, l A( m: [4 k+ v8 s - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);: f _6 ` @' O: e a. M1 |' l
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
8 J% G+ r+ z( q1 @ - studioSplineBuilder1->SetPeriodic(false);4 [. a1 P* l4 r; a
- studioSplineBuilder1->
( o) B4 U: m: c) j& @% j" m% o - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. d8 M; u& U. y. A9 m: Y4 U6 Y7 H6 p
- std::vector<double> knots1(0);
% x4 P' y7 x" j% X/ C: K - studioSplineBuilder1->SetKnots(knots1);( G5 P3 S5 x- T8 y6 q! t
- std::vector<double> parameters1(0);9 e; X+ W* | [3 S* b
- studioSplineBuilder1->SetParameters(parameters1);
- @, p! F" w; O" |4 X% H - Direction *nullDirection(NULL);
8 N X+ V5 O2 w0 e4 v5 C$ T - Scalar *nullScalar(NULL);
5 `6 p; r1 q7 Q, P) x) D+ W! a - Offset *nullOffset(NULL);
/ N9 h) P! U' w5 P3 L7 E# y
3 Z3 O6 P/ j! f4 _& K0 g- std::vector<Features::GeometricConstraintData *>
+ Z3 M# ~2 b9 }3 E7 k - geometricConstraintData(thePoints.size());
( `% F3 A6 }# ~ - % e! |; l h3 w) z# E7 Z
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)5 Q% k8 {! @" T* a, [
- {
* G. A- v! Q: d$ b+ L% S - geometricConstraintData[ii] = studioSplineBuilder1->
2 u. _9 |3 V! U8 E - ConstraintManager()->CreateGeometricConstraintData();
2 w9 ?* H. {" ]2 W3 t$ K - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
; c' W7 N W4 L! L. x" m+ v - geometricConstraintData[ii]->SetAutomaticConstraintDirection() q- H' M* w; S0 B4 O6 b
- Features::GeometricConstraintData::ParameterDirectionIso);9 l3 J6 m2 K' C2 e+ {! l# b0 C
- geometricConstraintData[ii]->SetAutomaticConstraintType(
4 V. l/ [' R, X9 N9 d+ W9 u - Features::GeometricConstraintData::AutoConstraintTypeNone);
1 R( R) w3 R( z( i' ^/ X - geometricConstraintData[ii]->SetTangentDirection(nullDirection);6 s- j! k& b! L8 m. A; V
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar); s& E% ^ S9 @5 O
- geometricConstraintData[ii]->SetCurvature(nullOffset);: s: I2 T' O5 Z! }" s# H" N8 ^
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
0 s' N" [9 W) h# } - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);+ \; u( ?' [# [. `# g
- }
" `, @1 D0 E9 [, ]) c5 M
" j* }9 x0 [+ g) r! [7 I- studioSplineBuilder1->ConstraintManager()->SetContents(
- Y8 c8 {" ~- O0 [/ y - geometricConstraintData);5 e: J" L5 O+ _, V6 M" P( K2 o' v
& ?1 [4 }5 t- u$ F- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();$ h$ \# x2 T7 k# x8 F/ C0 U% @$ I
- Spline *theSpline = studioSplineBuilder1->Curve();
2 A8 X |% ]% `: p5 S - ) ?' l( ~( k! Y- n; Y) `
- studioSplineBuilder1->Destroy();
/ `$ c+ _) ?0 W1 j4 Z3 h; K4 a- Q5 t
2 G# f4 o( g/ _+ Z/ C4 N0 {$ S- return theSpline;5 \# X0 v3 ^8 z) M+ V! f5 Q! M
- }
7 ]5 O: }% [8 G/ X% W( R8 s
+ v! d; n4 v% o# T* M- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): k0 Q% w# }0 p5 X9 a2 V8 C
- {
4 j+ n6 f3 C" i% J# S. z" s$ o - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");2 |7 C: z; y: U& l
- if (!thePoints.size()) return;9 K# [' C* q8 A
0 h* Q( r+ s3 t1 i' l& H- Spline *theSpline = createStudioSplineThruPoints(thePoints);
' n; p- k+ d5 c* g6 N, c - * \. r/ k# \3 j: I
- if (theSpline)' r) z# Y$ I) g; P, C5 D, q# K* l
- {
9 a+ d9 y) y6 h) [: X; Y$ x - theSpline->Highlight();
' R0 p; B k. H; [ {8 \ - uc1601("Studio Spline Created Thru Points", TRUE);
+ b1 Q% M* N1 T, A4 Y4 J- l4 v - theSpline->Unhighlight();
: z- ~# t- V1 h# ?& v - }) P |* ^: J- f, m
- }
* E9 \6 O6 X! O* R4 a$ A: p4 l
复制代码
( B! f; P& \0 D1 c' ^
$ O `, q$ f1 N6 i7 E% W; w( }6 ` ~$ D4 Q
|
|