|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线' N" g/ v) ^5 Q s9 w
- #include <uf_defs.h>
- P$ V4 v: B+ [ - #include <uf.h>
+ w+ c# O7 @1 S1 c2 U7 p - #include <uf_modl.h>4 P$ r8 P% S( R5 X
- #include <uf_object_types.h>
' a0 m: v9 V& ^1 ^+ R, ] - #include <uf_ui.h>
9 B. |: b1 K# B, F3 _1 U - #include <uf_modl.h>
3 Y- S) v6 r0 l2 D" t c - #include <NXOpen/NXException.hxx>
3 o" O' U4 ^! x - #include <NXOpen/Session.hxx>
0 W' E: C ?2 N2 O: q: J - #include <NXOpen/Selection.hxx>
, K" D# h+ q2 s4 s% {4 K. d# s - #include <NXOpen/Builder.hxx>% V% n! R! R( V% ?8 N
- #include <NXOpen/Features_Feature.hxx>: L$ |# r l3 F8 [' D6 l
- #include <NXOpen/Features_FeatureBuilder.hxx>
0 d& k. p3 q1 V0 p - #include <NXOpen/Features_FeatureCollection.hxx>
' |% e1 ?0 m1 p+ A - #include <NXOpen/Features_GeometricConstraintData.hxx>1 S% q& v* w* Q* J, f: H& {
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; I: {5 O R# z- h# c0 b, M
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
2 W/ v2 W, k/ C8 u- j4 W" ` - #include <NXOpen/Part.hxx>; x g( H! h8 H& G8 \
- #include <NXOpen/ParTCollection.hxx>
8 }% H% X& @* I$ E - #include <NXOpen/Point.hxx>
' G) a+ ^$ F4 k1 i" u( ]9 F - #include <NXOpen/PointCollection.hxx>% f! } Z! x& q2 L8 g
- #include <NXOpen/NXString.hxx>8 S% z5 ]! X! K7 p, P
- #include <NXOpen/UI.hxx>3 g3 |' Q8 [ M3 ]6 t6 l
- #include <NXOpen/Spline.hxx>
: M& D: b" w% z5 Q5 R" p8 w+ ^( c - #include <NXOpen/NXObjectManager.hxx>
9 J: G3 o! q6 [7 V d" x* g
$ R6 Z( \2 O- y0 P7 d- using namespace NXOpen;( e9 Z9 T: R9 M. r
- using namespace std;
; j; j" D( h u# e2 K - 5 H! _! a4 c: x1 D( C
- extern "C" DllExport int ufusr_ask_unload()
) H; o. n. w/ o - {$ R% _" ~6 t0 M5 V. F$ f! y
- return (int)Session::LibraryUnloadOptionImmediately;
* W* I( A0 V8 O4 Z* ?! k0 [ - }8 ], q; w+ U* b
- - l* V- P \5 Z- P+ z" s) h
- static vector<Point *> selectPoints(NXString prompt)
# P1 ?2 a1 W3 H' o7 D - {
" z V$ X0 C" o Y' v' @7 u - UI *ui = UI::GetUI();7 l: N. X- X8 A" `0 G7 Q
- Selection *sm = ui->SelectionManager();" x- h4 O: x: A$ o* N/ I
- std::vector<Selection::MaskTriple> mask(1);4 `+ t4 f4 y4 L/ {+ M# i# g/ q$ S0 A8 P
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);) C& [+ f. G0 B9 Y6 T
- std::vector<NXObject *> objects;
& C: \2 s6 j; _4 c1 u$ |
[. N4 T/ J0 c7 z$ q- sm->SelectObjects("Select Points", prompt,
3 i# k$ E4 }2 L6 y& J - Selection::SelectionScopeAnyInAssembly,+ V7 |" z+ r1 y* x! J9 F& g& i: Y7 ?
- Selection::SelectionActionClearAndEnableSpecific,3 k; d; Y7 o; m* @7 X* ?( ]
- false, false, mask, objects);
* i$ B+ M9 w$ h* R b2 z- Q
# Q" G q3 O, ^9 A, {' ?* {, v, d. k- vector<Point *>selPoints(objects.size());
6 K! W, Y6 z" ] q2 Y! p - for (unsigned int ii = 0; ii < objects.size(); ii++), F2 ^ [$ q: A) N. |/ `
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
% e8 O1 b8 e8 O% G4 p/ b2 ?5 y - - s* y; L4 H+ L' @3 b5 I
- return selPoints;
% R" K2 {' M# m - }3 _2 K, I p2 L: J" K
) @: W* p' s8 q- v+ n9 n" \- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
1 ]0 h, ?- D O1 `' n Y - {$ \: M Q3 w& t
- Session *theSession = Session::GetSession();8 T* r# B2 Q! ^/ V. l0 t
- Part *workPart(theSession->Parts()->Work());
- v3 j8 c3 R4 m" f3 g
3 _! Q* i2 u/ \+ |* `, W- Session::UndoMarkId markId1;
' G- c' h* h' U0 x5 R. z - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
! K0 [# y5 u3 h1 ?5 A! `2 D5 C - "Studio Spline Thru Points"); p( S4 o3 b$ \+ c1 y& f: D' Z
- * j2 H7 _& I, _- I$ Y
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
, a# a! V+ E" J
4 e& c4 Q/ m8 f' F% G4 G- Features::StudioSplineBuilder *studioSplineBuilder1;
7 \# l+ l: |+ d/ A# h" q& ? - studioSplineBuilder1 = workPart->Features()->
: c+ K x; f$ b - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
' c9 s) c& [. b, c8 \# ~ - studioSplineBuilder1->SetAssociative(true);( s; [. c: i4 h- h/ R1 t3 u7 ^
- studioSplineBuilder1->) z6 y: C' ~% ]0 c* X- ]
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
' m7 V/ l. V% y. l- d - studioSplineBuilder1->
8 H! t" W8 E( h: ~ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 ^ `4 M, [. a9 y
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);' H/ k" v4 M! t" ^4 i8 g
- studioSplineBuilder1->SetPeriodic(false);. N# k! c, m1 Z3 a9 Y4 h
- studioSplineBuilder1->& P/ u% L" v/ N. u! N8 }, S
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);* l/ j9 } S- C5 i
- std::vector<double> knots1(0);
$ M2 t2 x, q( w8 C0 y7 | - studioSplineBuilder1->SetKnots(knots1);
0 o* q$ n1 v- @2 p+ v' G - std::vector<double> parameters1(0);; I9 O+ d0 Q2 E6 O! L. b
- studioSplineBuilder1->SetParameters(parameters1);
9 w4 g% A2 I# p: q( G - Direction *nullDirection(NULL);
5 n' G( \2 I3 o9 }& e4 X* x# O - Scalar *nullScalar(NULL); f# c4 @0 \' n7 ^8 a' X, i& G1 I* J j
- Offset *nullOffset(NULL);
; i- N$ R+ I8 `! }# V2 ]
; G1 N4 g) r1 ^* V) D$ @! X' d- std::vector<Features::GeometricConstraintData *>8 K P! A4 E5 R2 S/ C+ a
- geometricConstraintData(thePoints.size());% h$ A0 n) B- H3 C% }! V, S
- 8 h! @5 o p" i. Z* }1 x
- for (unsigned int ii = 0; ii < thePoints.size(); ii++) u9 M, R8 v B! h" L9 v
- {
: }1 j w0 K6 b. t0 @% u - geometricConstraintData[ii] = studioSplineBuilder1->9 }+ q; d! ^- g& r" b; K4 l
- ConstraintManager()->CreateGeometricConstraintData();
4 l2 K O0 N! \5 \5 H) k - geometricConstraintData[ii]->SetPoint(thePoints[ii]);5 y, v; F2 a% ?
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
- \+ m! g6 r; }( Q. w - Features::GeometricConstraintData::ParameterDirectionIso);
7 [. c( M- T2 Z2 c/ e - geometricConstraintData[ii]->SetAutomaticConstraintType(
6 S) K: |# J! X, [ - Features::GeometricConstraintData::AutoConstraintTypeNone);2 o& a/ y L" h- `0 S
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
* \% T3 a8 r6 x4 T1 s# X3 f& J! t - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
6 n5 G8 b" z7 s/ G - geometricConstraintData[ii]->SetCurvature(nullOffset);
- G; e6 b9 A- v) v$ M; q v6 { - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
. b" Z! F2 ?) }# u3 v8 C - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);$ |, T- \' H# k1 l9 R
- }4 x8 ^/ i: v" ^7 f8 I- s4 g9 z, |
- ! F$ Y) j I# p
- studioSplineBuilder1->ConstraintManager()->SetContents(
6 s; ^: e: d1 k* h' e5 {" Y - geometricConstraintData);* |: Y3 X5 O r. ?
- 7 j+ L9 r/ I. v5 r4 h$ o
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();; L/ P/ x0 n1 m7 ~# B: a8 R
- Spline *theSpline = studioSplineBuilder1->Curve();3 U5 O, ?% A4 Z, N% `
7 b2 g7 o! a& R! g- H( G5 I- studioSplineBuilder1->Destroy();
0 R/ B/ @3 Y, P' w w" r - 2 A; D$ |0 n; z" ^5 C
- return theSpline;% f5 F) S6 y+ h8 e
- }* w, o3 x1 M" S" O
; C; I, z A; e$ W$ k o- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
. q/ d. N' I# J! o/ f/ w6 ?+ K% [ - {% L, t+ P6 m2 _6 w3 S
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
) H0 Q5 i. E- J, v1 G4 o# U - if (!thePoints.size()) return;3 g( J# u' B- S( b) H
- ! W3 S! R1 ]+ M2 c
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
7 ^2 x0 T4 Y# K9 U- f
7 }' e+ Z/ n( k- b. t' |' O- D- if (theSpline)& Q: u$ E" |& W( g" h
- {; C6 v6 S9 |2 Y- P/ v
- theSpline->Highlight();
4 l# A! W3 g: A! ]. F+ u- m - uc1601("Studio Spline Created Thru Points", TRUE);
$ ?, T) C4 I, K1 D8 Z - theSpline->Unhighlight();
* g$ ^( e& h% {; {6 G - }
0 d. o7 O9 I8 C& s - }
% a# S4 x9 I: K) Z2 O
复制代码
3 f" h4 q! \" `1 o+ j* O, w. ^- H1 g7 ?1 o; x3 ~
' G" @! u; ?1 o |
|