|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
, ~2 T6 j' ?: D7 u4 D- #include <uf_defs.h>
- d: X+ Z. o' L/ ^' Q( U$ V5 U - #include <uf.h>; }: f) p5 p; J) W
- #include <uf_modl.h>) E: |6 v' m; }# S; e9 Z
- #include <uf_object_types.h>
" { s3 X: l5 F3 I! D* z - #include <uf_ui.h>
/ f) M( o5 t, @8 [ z - #include <uf_modl.h>, {3 m4 d4 ~# j8 |* ]
- #include <NXOpen/NXException.hxx>
5 A& E5 C( l: g" F - #include <NXOpen/Session.hxx>2 ?6 r6 q8 a! w6 C
- #include <NXOpen/Selection.hxx>
- K- X( |0 D& j$ l - #include <NXOpen/Builder.hxx>, i% j6 H6 E0 O7 i0 z; O# ^* v0 u
- #include <NXOpen/Features_Feature.hxx>
* r0 W b' a! M - #include <NXOpen/Features_FeatureBuilder.hxx>% ?; N5 J: ]3 \5 E- T: l( }3 f
- #include <NXOpen/Features_FeatureCollection.hxx>
; r' Y0 J) n/ L5 M - #include <NXOpen/Features_GeometricConstraintData.hxx> e6 Q$ o5 A: k
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
, j4 I; ^2 }2 x1 h2 _- A - #include <NXOpen/Features_StudioSplineBuilder.hxx>
9 ^; R* r% d, Z' s A - #include <NXOpen/Part.hxx>) Z; d) R5 i- F- {# k
- #include <NXOpen/ParTCollection.hxx>0 q) ^" r4 o3 J' @
- #include <NXOpen/Point.hxx>! C# E. v" A" |5 J# Q3 V1 H: U
- #include <NXOpen/PointCollection.hxx> P" _3 s+ V* S$ T
- #include <NXOpen/NXString.hxx>
) ~2 H5 \2 l% f d+ R2 J( K% ~ - #include <NXOpen/UI.hxx># G5 ]7 l+ D9 j9 }1 z
- #include <NXOpen/Spline.hxx>- o/ f( k4 c9 q W q# M) E
- #include <NXOpen/NXObjectManager.hxx>, V P4 q# E8 Z7 l
+ n& V' U# ]8 T1 \# B- using namespace NXOpen;5 r+ C @; ^& i, s. B2 ^
- using namespace std;" l1 X4 P2 T0 F% q4 ?- c( R
7 k' j# \. @* Y- extern "C" DllExport int ufusr_ask_unload(). p8 X1 U- `2 D4 p
- {) b0 c) _4 S# B( ^
- return (int)Session::LibraryUnloadOptionImmediately;
: ]% C- g% Z- { w v8 L - }7 {- G8 q& U- d# Z; Z% g6 A
D- w5 }, Z7 w0 Z- static vector<Point *> selectPoints(NXString prompt)
4 o" _: q0 ?6 C. M - {
; r6 q$ R% A* i$ ?2 Q2 a - UI *ui = UI::GetUI();& {- T: k0 E' K: X: Y1 F& ] r: P4 U
- Selection *sm = ui->SelectionManager();
6 r7 e k& N2 t; ]# p% e - std::vector<Selection::MaskTriple> mask(1);
1 |# ?+ c% ~! y- \' [- J4 J- |# e - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);# z0 l. C8 D9 w* z9 B) V7 ]) s3 T9 w
- std::vector<NXObject *> objects;3 W* t( ^& ^' c3 M$ E$ w+ H: V' J2 h
- 9 t- h8 ]* f1 f, w) q; `
- sm->SelectObjects("Select Points", prompt,0 ?9 T4 n I O" {5 T) @* x, X5 A
- Selection::SelectionScopeAnyInAssembly,, I" A; w6 A. r z
- Selection::SelectionActionClearAndEnableSpecific,2 b: C: @* N" e/ d+ \, u# _
- false, false, mask, objects);
; H+ E0 t6 K! w7 \7 j - 2 e3 ^9 E5 L/ Z0 i& i
- vector<Point *>selPoints(objects.size());
" T4 Z. |( g' Z1 k* a+ q1 a! ^ - for (unsigned int ii = 0; ii < objects.size(); ii++)7 f( {; k9 a3 f9 R7 W! e
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);/ v O; g# r- x/ r0 f2 O
- # j: g" z9 x# ^1 R: c5 K6 e
- return selPoints;
' [) [) c/ K8 ^1 p- } - }
* m0 @1 k: ^8 L3 a+ C8 D% H0 a
' o* L' k1 [1 g2 |, V% ]( p- y- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)- Q! l3 }* S% O! a
- {
+ v9 |$ Y0 }# v0 R+ `2 \ - Session *theSession = Session::GetSession();6 T3 D0 m/ g/ I/ [, G( H+ w3 |9 R, c8 u
- Part *workPart(theSession->Parts()->Work()); w5 N* l) ~. w$ F6 z" m1 L/ x
; N; j6 O! l$ Y( }- Session::UndoMarkId markId1;
6 \& w# j' Q: D4 K/ Q# r1 M; g - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, q* x. h$ L D% @$ ]
- "Studio Spline Thru Points");
2 {" }, O' H5 U/ A
, ^9 D( ^& g n6 N- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
; w/ s5 C9 x+ C
+ h( _" O. c$ {9 w. }+ r- Features::StudioSplineBuilder *studioSplineBuilder1;
9 X5 h# b) u5 W3 ^4 _9 D! O - studioSplineBuilder1 = workPart->Features()->
9 S p" D% p8 ^, ` - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
4 }+ L0 y6 X8 e* B& ]5 I6 h - studioSplineBuilder1->SetAssociative(true);
, N* F! {" M+ ` j7 W - studioSplineBuilder1->1 ^0 @* D0 L9 y% {
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);- W$ K/ Q9 M# u+ L2 e0 y4 N K8 J
- studioSplineBuilder1->
* x4 \* S v/ S, p - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
1 K7 X! f3 @* M$ t% z - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);3 a n" P* y: |- p+ B4 K' _0 ?% E
- studioSplineBuilder1->SetPeriodic(false);" v" @0 G: O3 R
- studioSplineBuilder1->- ]9 u7 o* p* H; w
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
& I1 D+ t* P4 e) @9 B - std::vector<double> knots1(0);/ v* J8 o- E3 q
- studioSplineBuilder1->SetKnots(knots1);
- ?9 w; l0 W& T# A) H - std::vector<double> parameters1(0);+ s3 X# |( }' {
- studioSplineBuilder1->SetParameters(parameters1);
6 W8 Q1 ~5 ?7 O3 w& w2 [ - Direction *nullDirection(NULL);
" H* A2 E) D2 f5 ]& p% A- u$ T - Scalar *nullScalar(NULL);' I. N+ Q/ q" A: b' W1 Y
- Offset *nullOffset(NULL);
, L/ U- v+ O u% I* n7 Y: n0 O - 1 Z- {4 Z( D9 p
- std::vector<Features::GeometricConstraintData *>* J8 C; D. U2 V
- geometricConstraintData(thePoints.size());6 f5 `. t. B+ \4 T0 d; t
- / {2 m& K7 R2 J- t
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
' }; G+ p! M) z) U - {; Y5 |! R8 z" T5 V# j' E3 b
- geometricConstraintData[ii] = studioSplineBuilder1->
4 C$ [/ ]" Y. \& k I - ConstraintManager()->CreateGeometricConstraintData();
; t6 I) _ B$ ]# r - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
, V5 s- v% ?, b( R, ^ \( c/ B - geometricConstraintData[ii]->SetAutomaticConstraintDirection(" ~# X, D" O1 T
- Features::GeometricConstraintData::ParameterDirectionIso);; E8 V) }$ |; G7 |8 _& w. R( g
- geometricConstraintData[ii]->SetAutomaticConstraintType(" f: T4 f- c9 k- T* |4 p' q6 M
- Features::GeometricConstraintData::AutoConstraintTypeNone);
/ W8 U9 q# V( G. r - geometricConstraintData[ii]->SetTangentDirection(nullDirection);1 E% }7 a- x2 I9 L
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar); h: s2 u( ?, \9 t1 t# C
- geometricConstraintData[ii]->SetCurvature(nullOffset);
7 s) i/ U9 i- G. l/ A# K e - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);# C/ O" R+ Y: K. H
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);4 f. n0 |6 n1 l: o/ C
- }
- {, r2 a) d& b% ~( g
0 N2 S* C9 j7 L: W5 F- studioSplineBuilder1->ConstraintManager()->SetContents(4 `" g1 U: D$ n
- geometricConstraintData);
+ u, m$ W1 R- X4 a) g+ {" G - # h9 S `0 ]) S: S2 e* d( M
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();4 k) I# k* r1 v. H: i
- Spline *theSpline = studioSplineBuilder1->Curve();2 n9 u- \) r0 x' `% H/ G" U/ s! j
' o- i4 k" A% W) a- f6 S& o- studioSplineBuilder1->Destroy();
; w7 u: h F, T( Y - . f0 _7 A/ T8 `$ E& |
- return theSpline;
! c0 s5 N) L" U& s8 h5 G- T - }. g6 r! e, I# @9 \8 F2 v/ z4 u
. L$ v4 z& g2 } ~% K- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)! g- N/ h! C% Z2 C0 V( _
- {
* w7 ?9 |: ?' l - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
; K* u; X$ M6 i4 ?0 v - if (!thePoints.size()) return;
3 i* c+ V, R- Z: v - 7 e" z ~( ]8 d8 }, x6 N* j* j
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
6 M- n' K3 D* ?
% ~8 a% Q- {1 V8 a2 ^3 U1 G% ~4 ^- if (theSpline)$ w2 i, p. N7 |) v1 R
- {
L3 S! c0 T) p( Y - theSpline->Highlight();, m# D* f' x# j U/ g6 b
- uc1601("Studio Spline Created Thru Points", TRUE);% }, D3 a. {2 L( G# O& G
- theSpline->Unhighlight();6 F/ ^4 I# C! r! J n- s1 P
- }1 D9 r+ a) u# ?1 F; H {/ O
- }* o* a) a% @1 ^8 l
复制代码
3 y3 r7 e$ m* C7 {' C
7 M9 M5 d2 n6 u2 n. g6 s2 z2 A. i4 W# S! m4 D
|
|