|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线* e! r% [; ]* @$ d, l
- #include <uf_defs.h>5 w" U0 D5 K2 E1 F0 s H0 z
- #include <uf.h>, y' x9 x8 H5 A9 E( s" W
- #include <uf_modl.h>
) p4 I% I' O2 x3 v4 x - #include <uf_object_types.h>
% \" L; P6 E4 |! {* B2 s u. G$ \ - #include <uf_ui.h># Y8 m/ o% \& b# c9 F* U2 S
- #include <uf_modl.h>' G% W/ Z7 w) K2 [: m. {' E1 \8 P
- #include <NXOpen/NXException.hxx>; ?+ m0 i- u5 g5 |7 ~& v
- #include <NXOpen/Session.hxx>5 b/ n% Y4 K5 F7 e
- #include <NXOpen/Selection.hxx>, M# \; \( B$ J- h3 b
- #include <NXOpen/Builder.hxx>4 a+ t1 _( V+ a5 p4 W- F
- #include <NXOpen/Features_Feature.hxx>
p# M0 ?# o! I4 g# Q# q- D - #include <NXOpen/Features_FeatureBuilder.hxx>
6 s) A! E$ g; q0 l0 z" P+ d* a - #include <NXOpen/Features_FeatureCollection.hxx>
; b5 f( z* A* y& ], R* E( n3 C - #include <NXOpen/Features_GeometricConstraintData.hxx>
! G) w9 I$ n3 y+ ]; J, O' o - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>; C3 m. O4 ~8 E0 ^) G
- #include <NXOpen/Features_StudioSplineBuilder.hxx>6 X0 M& ?( c! z
- #include <NXOpen/Part.hxx>
& u4 |* I; q: e) Q' Z) }# D! i - #include <NXOpen/ParTCollection.hxx>. j4 L' c7 {- }8 \/ \* `: H
- #include <NXOpen/Point.hxx>8 k: ~: ? o! H3 g6 c& Z
- #include <NXOpen/PointCollection.hxx>8 K" ]1 \! p, W B \- Z O6 W% g, J
- #include <NXOpen/NXString.hxx>2 E9 c4 f( E' O: R
- #include <NXOpen/UI.hxx>8 X; \: A" b3 E
- #include <NXOpen/Spline.hxx>- g! ]0 I" M: b% H
- #include <NXOpen/NXObjectManager.hxx>5 f/ D3 _7 q# `! [
- r7 V m k# N; i! r- using namespace NXOpen;# `( K& `) e0 r7 \% J' Y- U
- using namespace std;, U! Z) n* K6 }2 i4 ?: m
- , G: y0 [3 O5 u) D* H
- extern "C" DllExport int ufusr_ask_unload()6 V4 G- Q8 s9 G% B* j
- {' G1 x& f) ^* \/ h
- return (int)Session::LibraryUnloadOptionImmediately;. X' q& l; B, b- F2 j5 D
- }
3 A% S5 q, |; ?7 Z/ S a - / v" T, \" ?9 j) d- x3 D
- static vector<Point *> selectPoints(NXString prompt)$ k: b) K/ x: d/ `! t6 W4 y; \, M
- {
8 ?3 N; y6 D( r3 U6 O, e( ]$ N - UI *ui = UI::GetUI();- r+ n- m7 Z( [
- Selection *sm = ui->SelectionManager();
# ]) q7 U/ a: u+ p - std::vector<Selection::MaskTriple> mask(1);8 J$ X6 r) M' ?, T: n
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
, e' m* B+ f4 N - std::vector<NXObject *> objects;
( n( {6 J* I; G/ y - $ k0 s9 ~- e! A `
- sm->SelectObjects("Select Points", prompt,: G( P9 O O% _1 u1 `
- Selection::SelectionScopeAnyInAssembly,7 v: K- I' J4 x h
- Selection::SelectionActionClearAndEnableSpecific," B8 [% I( i, l* ?* b
- false, false, mask, objects);" B% d% y% \- {) T. }
+ }( ?$ O2 W! U! [- vector<Point *>selPoints(objects.size());
8 E# Q5 y" s' V/ v) V6 k0 S - for (unsigned int ii = 0; ii < objects.size(); ii++)7 f" m+ [7 ~/ ?: i5 \
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
9 x1 P( m7 L: q* g3 G5 p+ r7 T- A - + X1 {% L+ u& \+ L( b9 A
- return selPoints;
& A% z$ }% y) x& s3 G D - }
5 ?7 f* U/ w( a: t/ Z: N+ ^: y# j6 P
; I, }7 \. Q: ^4 |- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
" z5 w2 i6 q2 O4 ^4 Y. P - {
2 M8 [3 o2 ]4 Q6 l - Session *theSession = Session::GetSession();4 x* H' R9 `9 d( N$ e3 R
- Part *workPart(theSession->Parts()->Work());
! S. g; g- E3 n" j+ P
. D8 X9 p% A/ {5 _; {- Session::UndoMarkId markId1;* _8 |6 S' A9 S7 P/ V) Y
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,3 o# }- U+ y8 V$ M0 H
- "Studio Spline Thru Points");
5 b, c: `1 I; U) t% B9 D& s& K3 ?" Q
1 _( U: ^' t `# m& f- Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 k* W% O" b# \! u; m7 L& H
- , ?9 t3 w4 s8 a! W0 B
- Features::StudioSplineBuilder *studioSplineBuilder1;
3 _; n7 W) ?# K( v - studioSplineBuilder1 = workPart->Features()->; j1 c6 a$ r' }1 g" s; D% |
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
% i% Z% [& ]: E" o' ~$ o - studioSplineBuilder1->SetAssociative(true);* {3 b. w3 t y
- studioSplineBuilder1-> k0 s7 c6 K% H# s7 p7 c
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
0 T4 B! k2 n# ^& | q - studioSplineBuilder1->
0 [; c! h7 @/ r9 Z' p - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);, n! U2 W6 x0 m
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);2 g& [6 t1 J6 |7 E
- studioSplineBuilder1->SetPeriodic(false);* x) Z1 F7 X& ?
- studioSplineBuilder1->
9 M% b6 q- ~8 X. V) ]5 n( y. i/ z+ m - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);, K/ X' j- h& p+ r
- std::vector<double> knots1(0);$ f/ B/ t: }$ E# E/ g& \
- studioSplineBuilder1->SetKnots(knots1);
& n+ q) p8 J5 [+ S1 c$ Q - std::vector<double> parameters1(0);
7 g1 S+ @6 n, z% W. B- O: R! b* ^ - studioSplineBuilder1->SetParameters(parameters1);- h& [% h3 r" ]
- Direction *nullDirection(NULL);- _2 E' }5 a5 \
- Scalar *nullScalar(NULL);) O. n. K( e& }
- Offset *nullOffset(NULL);
5 {( V0 T( U& v6 c0 J* O5 m) x - $ m3 ~4 I8 T- T m& j$ d5 ?
- std::vector<Features::GeometricConstraintData *>
* U! ?2 p; a. Z8 r4 [/ P9 |6 h8 c - geometricConstraintData(thePoints.size());5 Q3 H* B# O$ ?2 b$ {" ^9 c
+ c c+ G T( P& ^) u9 b- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
, v M! P9 H" j, m6 ~1 n* s - {
5 B8 G. q* m0 O, D - geometricConstraintData[ii] = studioSplineBuilder1->
: `! i' h6 V( V& t8 Y( d" V5 ~3 r. \ - ConstraintManager()->CreateGeometricConstraintData();% q( y, |0 w( C3 _
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);( H3 i+ o0 `0 G
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(. R, P- H6 |. v" P Y
- Features::GeometricConstraintData::ParameterDirectionIso);% t; S' R1 c" G& r0 }9 M) K6 n
- geometricConstraintData[ii]->SetAutomaticConstraintType() O% R* Q+ i, b- G, |% k& G
- Features::GeometricConstraintData::AutoConstraintTypeNone);% f0 g g$ W7 H
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
- h8 }6 M4 s+ I6 O7 j1 S - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
5 V# |( g& x$ o% ?! o - geometricConstraintData[ii]->SetCurvature(nullOffset);6 d' z& o/ A" P* v+ N
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);0 i( Y7 M9 ^% y
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
2 q6 m6 ?; T- w0 l0 d; |- n% J J - }
' C/ |0 D3 t4 m - # T8 E* [0 h+ a9 C1 E" U$ ?% l
- studioSplineBuilder1->ConstraintManager()->SetContents(9 Z9 C2 W. H' J* i7 n8 }8 B+ L
- geometricConstraintData);9 X6 ?, |: Y, s9 I
- * R* E0 t/ Q& a! C2 i9 f2 c
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();& Y5 M+ g, Y6 Q1 c: u
- Spline *theSpline = studioSplineBuilder1->Curve();
5 E6 s3 R" L/ C' S' _ - 0 d8 G$ O5 C3 H$ {* T! ~
- studioSplineBuilder1->Destroy();
7 ~ x) E: c" c3 J% W% c4 e
" F1 h6 d& z8 `9 j7 X- t) e- return theSpline;; T4 @8 | |2 x6 B
- }. @2 r" D+ ^$ z6 U7 Q
4 b! n0 X/ k" b3 ~9 y2 X6 y- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
k$ a% v$ T) q3 }- l3 ^+ r - {1 d7 r; V% g6 ?+ g; @" B
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
% I0 O* w3 L+ S8 ~6 E) B. K - if (!thePoints.size()) return;
* D! F9 Y! x9 W - 6 L3 a3 @7 o$ f6 s/ P' {+ [# D
- Spline *theSpline = createStudioSplineThruPoints(thePoints);8 `0 N: z( C) @, H2 b
2 `9 X) ~! W% z4 u# K% i* R+ l- if (theSpline)
n5 d- Q; v- |) ~ - {6 ^6 O, X( B( j# Q
- theSpline->Highlight();
* b& `+ S' b ]4 t - uc1601("Studio Spline Created Thru Points", TRUE);
5 {; k/ d) i `2 f/ t' i( Y6 a. P; |3 n# f - theSpline->Unhighlight();% Y' H4 V/ \% ~5 G* `2 Y
- }
# M% s$ p A8 f2 A - }3 V( P* T& O& t0 _8 {
复制代码 / \* w. c( @, B( J1 n
. r) o1 w* Q$ U
; F; w7 s# {! I3 K$ C9 p: p3 q
|
|