|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线! R4 |( |. S$ k% X, t
- #include <uf_defs.h>
! [+ d3 W* G+ p- W - #include <uf.h>7 b7 A/ O# F# ?( P" ]' t3 q; b0 E; l
- #include <uf_modl.h>4 X+ |2 R2 I# [* ]
- #include <uf_object_types.h>
6 h& \0 e) c% v, G+ b6 X2 q& ] - #include <uf_ui.h>
. _; q: I- |! l) j) Z4 u - #include <uf_modl.h>
+ Y$ M+ K5 h8 }1 L: ` - #include <NXOpen/NXException.hxx>
7 Q: @0 _# ~' x0 i* @ - #include <NXOpen/Session.hxx>, ~" p, s) L0 B9 ]$ ]2 P3 E7 H6 V
- #include <NXOpen/Selection.hxx>
: E7 q0 P3 x8 N# X. h: t: Q# }+ b - #include <NXOpen/Builder.hxx>9 S/ r) o, _* n( e5 v0 [
- #include <NXOpen/Features_Feature.hxx>
. E3 d: I) S7 R - #include <NXOpen/Features_FeatureBuilder.hxx>
+ d. G j, |' O& V - #include <NXOpen/Features_FeatureCollection.hxx>% f' E. t: T. Z6 K6 e, G1 P$ d" f
- #include <NXOpen/Features_GeometricConstraintData.hxx>/ j7 o; |& }3 ~4 f
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>( Z1 u9 _+ D+ i+ m# D7 r
- #include <NXOpen/Features_StudioSplineBuilder.hxx>7 F! x% b* j5 h
- #include <NXOpen/Part.hxx>
+ {! c8 s2 I, a7 s0 g2 B - #include <NXOpen/ParTCollection.hxx>
/ } {( V1 R* h5 B+ l% I5 r - #include <NXOpen/Point.hxx># I" v0 o) E5 P( p! L
- #include <NXOpen/PointCollection.hxx>
& l. A! M1 T% G) J |- F - #include <NXOpen/NXString.hxx>
: G w! c; L3 ]5 W" ?6 L - #include <NXOpen/UI.hxx>% L8 K v; \, B! ~0 R9 V
- #include <NXOpen/Spline.hxx>
! V |8 C" L, l. a q2 }- Z/ V& r' v - #include <NXOpen/NXObjectManager.hxx>4 z' e# \! z j; j' i
' n% y7 z5 I! @) R/ |7 ~; @2 }- using namespace NXOpen;
8 A5 x/ r6 J$ @& w2 w% ] - using namespace std;
G8 B; q4 o$ \# T - 7 y$ k% A1 F/ H# j+ f9 _( v. F
- extern "C" DllExport int ufusr_ask_unload(). k& g! ]+ ]4 |5 B; A
- {" L1 G* i, v( a i- ?- ?
- return (int)Session::LibraryUnloadOptionImmediately;
, ?- T R) H2 C5 e4 |" w - }4 a; B9 i! l( \% ^
( R& O# O1 p: [5 z. @- static vector<Point *> selectPoints(NXString prompt)
$ z; l. @' a& T6 H/ v; T0 I# ~ - {
, |3 F. f+ Z/ s& f" l - UI *ui = UI::GetUI();% w/ |( G6 u! I2 s, b- g1 B9 ?
- Selection *sm = ui->SelectionManager();
3 p( u& l( I; p/ y4 K/ u - std::vector<Selection::MaskTriple> mask(1); P( H2 A) s! Q1 B
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
. y+ a! g! B3 |9 _( ?7 ^6 `% @ - std::vector<NXObject *> objects;- s: D5 T Q6 T" D
- 3 B; i! d* x4 O6 f7 E) l
- sm->SelectObjects("Select Points", prompt,
9 L' ]$ F' R( J1 C - Selection::SelectionScopeAnyInAssembly,
6 Z4 L* j& ^# k+ I: I9 B: |# N. ~0 q - Selection::SelectionActionClearAndEnableSpecific,' R, T( w# N$ K% m2 c6 L
- false, false, mask, objects);" [1 _0 m/ ?) x
& @2 C! n f, g: e$ ?+ s- vector<Point *>selPoints(objects.size());
' `0 X; k, e* R; ] - for (unsigned int ii = 0; ii < objects.size(); ii++)2 K+ \/ A+ W) U4 {! M
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
3 @+ {6 T) U0 T T6 Y1 U/ H1 [/ e
7 F0 p r. G0 A- return selPoints;
/ t( n2 a+ o% Z- v6 M - }: a/ M) t8 m+ {- P0 T- d! K
- 3 `) N7 V+ J& F7 r3 [$ D1 R
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)$ [& T. t! f1 `0 c
- {
! x: r/ O- N" Z+ u - Session *theSession = Session::GetSession();
9 d7 W3 u# y5 p+ f1 g' a& M - Part *workPart(theSession->Parts()->Work());. J$ r6 e9 Y* Q# O% ?- \6 f& u" \6 W
i# L; R+ ?0 G$ T- B$ b+ @( |& k+ G- Session::UndoMarkId markId1;/ A4 q/ C i5 Y. n2 |
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,. s- s8 @' T) o- l* e r
- "Studio Spline Thru Points");
0 f6 M$ z+ y; f# P" P0 J - * l! f1 Y& ~4 a" ?* w
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);/ m4 v$ B; a! }/ n% I* q+ d
- & N G8 _) {' b
- Features::StudioSplineBuilder *studioSplineBuilder1;
) a& b5 ^, W2 L! c. p% b8 H3 `6 [9 k - studioSplineBuilder1 = workPart->Features()->
3 a9 @, P9 J" P! e- B - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
8 s" s: ^$ B5 Q' _. q9 t; s - studioSplineBuilder1->SetAssociative(true);
& j9 G; R: U1 u& y9 x" f/ B) f - studioSplineBuilder1->
! c R! j3 r+ g - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
. o* T6 r% I7 w# o9 c- _* ?! N) _ - studioSplineBuilder1->
( |/ g( {. ~0 y* ~3 o5 ^ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* S7 [! J, |3 H' t( b7 e5 K
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);, `( Q% c8 O$ {; y* l& T7 |5 `
- studioSplineBuilder1->SetPeriodic(false);6 i. H$ }1 B% L* N+ D6 `
- studioSplineBuilder1->; P( s1 K/ }/ P9 t: R2 K% Y& V
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);& x2 ]! j! {$ L; Z
- std::vector<double> knots1(0);5 i/ K: P/ k# o9 `
- studioSplineBuilder1->SetKnots(knots1);
/ A% b4 ~$ ]) H# C |4 U- a - std::vector<double> parameters1(0);+ Q7 ], T$ D! G% K4 B) }
- studioSplineBuilder1->SetParameters(parameters1); `8 B% O5 y% p2 I! j. S- {8 y: ~9 i
- Direction *nullDirection(NULL);, P! s& ]' ^3 D4 J
- Scalar *nullScalar(NULL);8 T; z3 t0 X7 T
- Offset *nullOffset(NULL);; _2 b. I" Z, k) e
- 8 P) N' ^# f# B) r6 V$ H
- std::vector<Features::GeometricConstraintData *>% G$ _/ F/ Y( r: v, b% o
- geometricConstraintData(thePoints.size());8 v; Z0 I2 Q" S8 a
- , Z% N* j' |2 V9 {) `' i
- for (unsigned int ii = 0; ii < thePoints.size(); ii++). }3 X, t" @- S- y% ^. C/ U
- {
" m) `0 |& O% e& H - geometricConstraintData[ii] = studioSplineBuilder1->: c* E% J2 c7 s* {3 ]+ C3 k( R' z( p
- ConstraintManager()->CreateGeometricConstraintData();
7 \. i s! \$ r6 L - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
: l; E( t5 X3 q. Z3 e% ] - geometricConstraintData[ii]->SetAutomaticConstraintDirection( G7 e, y7 h9 {0 r- H
- Features::GeometricConstraintData::ParameterDirectionIso);3 u- w1 @0 q& m) }
- geometricConstraintData[ii]->SetAutomaticConstraintType(
$ R1 L$ y* P: j' r8 }+ c6 p - Features::GeometricConstraintData::AutoConstraintTypeNone); M2 K$ n' A4 m }4 s1 T
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);$ C$ T7 T4 W% n
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);% y5 n4 s' L( T' M$ ?0 U( L
- geometricConstraintData[ii]->SetCurvature(nullOffset);. c) h' @! d4 t( T9 R
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);' i8 h+ K8 z7 B5 l+ M' a q7 c$ t4 J
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
5 {) k Z* ]/ F7 a% [ - }
. E8 v- }. O; O: ~
; ?+ }, n0 [+ F/ O- studioSplineBuilder1->ConstraintManager()->SetContents(5 t- n6 W* N/ g* P( o" p
- geometricConstraintData);$ m2 v: T M; }$ r% I
K1 j) f" c$ s- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
D" B8 a0 w( v/ Q0 p9 c4 k - Spline *theSpline = studioSplineBuilder1->Curve();* s% W- f7 ~, t% Y' c9 r
4 C4 r* k' m) Y& u0 g$ c- studioSplineBuilder1->Destroy(); I! W/ h, [ O) s) U0 m
- $ l: ?& X7 d( Z T6 Y8 u
- return theSpline;/ f- d& E+ ^& e! {$ b
- }
3 g$ j& o$ U9 A% v# x* `
. b% C3 X0 O7 J- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
' @+ Q' w5 {( p, g9 ]3 I - {
2 C. F. y! P7 K( o- O - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");6 q7 j) G# y: v( h
- if (!thePoints.size()) return;( M$ [+ J; C8 d& A+ S
( z7 u/ z5 { `2 L- X; d- Spline *theSpline = createStudioSplineThruPoints(thePoints);3 O3 l# k0 e) i% g, O0 x
- 2 |4 G( n, e' ^7 m& j) B$ S& A
- if (theSpline)
8 n, V4 G( S D. O( U3 N# B1 w - {
, b- `: c% o! E% w3 T7 j4 q - theSpline->Highlight();3 R; D! l2 |1 q7 R' d1 e. P9 F9 E, i
- uc1601("Studio Spline Created Thru Points", TRUE);
8 q( L; W& D! Y7 N, G9 J9 q% m - theSpline->Unhighlight();( I# d4 f5 Q# }9 ?; X1 d
- }
h! j* Y. t- S; E9 k) U6 W% E - }
9 l3 l9 O1 L( e) e0 i x. ]# W
复制代码 # M' w2 G2 s( A a
9 l# i/ t9 V& d9 C q5 G7 L
$ A3 z: R6 Y% \9 U/ J |
|