|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线/ G! ?4 I L+ y4 }' z
- #include <uf_defs.h>8 H* n9 q. ?. P9 S7 w% V3 u% q: ]
- #include <uf.h>+ A# |- v9 L# I3 X% Q5 v% v
- #include <uf_modl.h>! Q% z; }5 B1 A
- #include <uf_object_types.h>% u, S+ B7 S% l8 _
- #include <uf_ui.h>
' e: @: U) @( D0 C9 q* S E - #include <uf_modl.h>
( u) {1 o; e& q1 ~3 V, ?+ R - #include <NXOpen/NXException.hxx>
+ l9 t S5 m; E* m2 u0 Z$ V2 D/ e - #include <NXOpen/Session.hxx>
% ]6 N) e: v! { - #include <NXOpen/Selection.hxx>% S0 M) r& Z) w
- #include <NXOpen/Builder.hxx>' r) a7 z, T ~# \6 T
- #include <NXOpen/Features_Feature.hxx>
$ k; I- q/ C' ~ - #include <NXOpen/Features_FeatureBuilder.hxx>
9 g3 x! M R" n( n& v - #include <NXOpen/Features_FeatureCollection.hxx>9 t- v! \3 r# \. C
- #include <NXOpen/Features_GeometricConstraintData.hxx>( \( q; y* t) o' v$ Y; T6 V
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>1 F% g/ u4 i; K0 G9 e
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
* Z7 h: i. C8 T! `5 W - #include <NXOpen/Part.hxx>
) A2 \' ~( q7 r$ V& _" q+ T) t* w - #include <NXOpen/ParTCollection.hxx>8 z) t- K+ Q0 B3 z
- #include <NXOpen/Point.hxx>) h% O: q% ~% I3 a( _7 R- d5 N" e) m
- #include <NXOpen/PointCollection.hxx>( w7 a# i% ]: Q/ s/ b5 P5 H' d
- #include <NXOpen/NXString.hxx>
5 t* ~& T7 ~ n' W! K7 ~ - #include <NXOpen/UI.hxx># p- n+ Y/ E6 t2 n
- #include <NXOpen/Spline.hxx>, F6 s& @% K: l/ t5 F
- #include <NXOpen/NXObjectManager.hxx>: L3 F7 k4 [( p: I2 `
; ?* k$ C! W7 U q/ J: l3 H- using namespace NXOpen;
: {) K% ^9 {% O - using namespace std;
; g' y5 f2 ]: L3 ?
7 b* ]6 |5 \$ w& H( d- extern "C" DllExport int ufusr_ask_unload()
) v2 [2 g! S) ?( p( F1 P1 Q c5 v - {
1 Z' `: W0 q# N8 J - return (int)Session::LibraryUnloadOptionImmediately;
) d, r( l7 q( G* f4 ^3 e+ {- { - }
+ O7 K0 K' N3 \% p - 5 T1 e$ x2 h! r( n
- static vector<Point *> selectPoints(NXString prompt)
" f7 S( h' P8 M) Y% {. M - {/ E/ i7 h6 b0 |/ h' P( P0 }0 c" s
- UI *ui = UI::GetUI();. a0 }2 y9 O7 }4 p
- Selection *sm = ui->SelectionManager();
% M+ y, K; ^7 i0 m; E2 Y0 `6 H - std::vector<Selection::MaskTriple> mask(1);9 `, z0 [3 T# U9 a& F% a
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
) }7 `4 n: r/ d$ o( B7 d$ q - std::vector<NXObject *> objects;
, [; h" s7 l! _2 V, W
+ f) c9 s9 b/ C W; K- sm->SelectObjects("Select Points", prompt,
, J& L" v( n8 q" n - Selection::SelectionScopeAnyInAssembly,0 p- y/ [$ p& d! _9 k
- Selection::SelectionActionClearAndEnableSpecific,7 Z3 \3 C8 {5 @6 ~+ F3 V( g8 `
- false, false, mask, objects);! ^# C6 d: X, |2 m2 k0 z4 w
- ; Y" b( X# V- |" h
- vector<Point *>selPoints(objects.size());, |) Y" P# G; p# u% z
- for (unsigned int ii = 0; ii < objects.size(); ii++)
1 s$ C8 Y0 n2 v; Y& r3 S! n - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);2 d6 n: G) N' j6 o6 _# t6 C
- , g) J' f* v4 @! [! Y* R; C
- return selPoints;
& _: M9 X4 t- C' E, C6 d - }# I+ _, B# c$ z; b2 x
" }; W8 N- l8 e1 ?! ]& L( k% p1 {- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)5 l$ [$ G | ?* R
- {1 t7 s- N" M7 j' y0 } q! t
- Session *theSession = Session::GetSession();
- ~+ r4 E5 Q) a% `% _! {+ | - Part *workPart(theSession->Parts()->Work());, m2 }; U0 l- b& I' `
9 F' P; S. _) Z% {9 |( |- Session::UndoMarkId markId1;$ U$ z* M! r% F: h$ W
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
8 q/ r" d$ B* ^9 ^' W [ - "Studio Spline Thru Points");+ k& S4 x% w5 ?0 Z8 c \% F% \9 e8 d
- : w$ }/ w7 I% r
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
( }; Q0 G0 d4 F6 p: z
# [$ b4 Z) J- C( i- Features::StudioSplineBuilder *studioSplineBuilder1;
% e; Q5 g# H4 i. X0 F& L# ^& }' M - studioSplineBuilder1 = workPart->Features()->
% b% ^, z Y7 Z - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
/ U: B6 ]/ y3 N8 l - studioSplineBuilder1->SetAssociative(true);
9 j1 d: g0 I R! A* K - studioSplineBuilder1->
; X/ k3 c+ ]7 w; S - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
[) s) p- L) Q/ _& j - studioSplineBuilder1->
0 @# N+ i/ B+ x" E- D8 w8 I - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
; M Y: M r3 w4 E - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);1 A9 W$ O/ T3 h0 S1 ], M
- studioSplineBuilder1->SetPeriodic(false);
1 U5 q$ i s. i0 y: C - studioSplineBuilder1->4 ^2 P, E( U' l. m* K# N
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
- V6 K- D: k! d - std::vector<double> knots1(0);( \) N1 T- |3 \" H
- studioSplineBuilder1->SetKnots(knots1);, f4 y% r! m3 n& j; L- B
- std::vector<double> parameters1(0);
- z+ `; Z7 _9 |4 A8 e - studioSplineBuilder1->SetParameters(parameters1);
& X. \) I! |4 G4 [5 P$ W9 ~ - Direction *nullDirection(NULL);+ Z& S- [% r- _+ x8 A
- Scalar *nullScalar(NULL); K* V: O: P( j9 m1 Z& ~" c% T6 @. q
- Offset *nullOffset(NULL);$ i( O- T9 I1 U: e g+ U
, q3 m6 J! C- u0 E+ }* k- ^- std::vector<Features::GeometricConstraintData *>
/ g b! Z8 r, C. Y3 t7 }& f; H3 b - geometricConstraintData(thePoints.size());
$ r" V9 E- C4 c( r
5 H8 |5 Z7 e! D3 V- k3 S, Y- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
+ J* o* V0 n2 F9 O - {
1 w1 _+ F, T9 `6 k - geometricConstraintData[ii] = studioSplineBuilder1->
6 L- Z/ q2 N% F- O2 |& Q; v' S - ConstraintManager()->CreateGeometricConstraintData();2 a; t& t8 w6 e6 P3 n7 j2 D9 g
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
9 u: E- O/ D( t, Z( _; D8 \9 H - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
' Y4 @& Y( J9 W$ W u - Features::GeometricConstraintData::ParameterDirectionIso);
3 W/ r9 N, m& _/ ~6 L5 P( X+ k - geometricConstraintData[ii]->SetAutomaticConstraintType(
0 J. x6 q- F ^. O - Features::GeometricConstraintData::AutoConstraintTypeNone);
' W( x$ C# Q: k7 @$ V - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
' K j: E$ U2 _( R5 {4 k - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
; U8 Y! C- e. o$ ^# w+ n* m - geometricConstraintData[ii]->SetCurvature(nullOffset);8 m3 z6 P# g: s0 ]: J. {* f
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);4 d, O: L1 g1 j" i
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
$ ]! I t# @$ Y- ~% j! Q - }
; c- @# x3 T3 F+ h/ F K* q
0 f! k% { c; w( t( x) o- studioSplineBuilder1->ConstraintManager()->SetContents(
. {0 q/ B% i2 W J( Y - geometricConstraintData);
7 y1 x9 C! Y! {3 P- N+ L6 t - % \) g6 ?- a g( q/ r- T; w
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ _' ^" s/ K; Z& F, o4 U
- Spline *theSpline = studioSplineBuilder1->Curve();
$ A1 k' B* a) L; A - % Z5 L- E: f2 R; ?1 W9 U
- studioSplineBuilder1->Destroy();
$ i# ^; g/ `- j' l6 u& t7 \
/ K9 n/ r3 N& B- return theSpline;
% }% {0 W" \" Q7 T - }
8 R6 H8 T, f+ h" t+ F
2 j* k1 @% O0 X! ~; k- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
, E- v3 i5 }+ X+ z - {
) |* e0 g3 r6 c2 C - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
3 o$ z$ t, d x - if (!thePoints.size()) return;
7 ?7 A* a! t6 D- I
3 U# w' d* N/ u$ Q- Spline *theSpline = createStudioSplineThruPoints(thePoints);" ?* s* M/ f% X! F0 z1 `1 m! @4 Q
' H8 E6 Q) e1 y$ F- if (theSpline)' O+ h6 N4 W" f! L- M8 R' d' s
- {+ R& ` G3 g8 h6 U# e
- theSpline->Highlight();
0 @# b+ l1 v6 {7 b' \& k+ w( Y - uc1601("Studio Spline Created Thru Points", TRUE);
* u5 P! y2 S2 x# m) a5 O: w3 | - theSpline->Unhighlight();4 g }) L# e$ ?* U& t: O" [- `
- }
" |9 a- c! `% Q0 k. ^! Y7 |5 o - }
! o2 b1 k$ R, T- H
复制代码 " _+ _' P, E( o; |' H9 c
' E& [ B# W3 F
' ]9 N) `. K2 K0 I |
|