|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: i |9 V8 m( v) J+ N8 HNX二次开发源码:通过选择点创建样条曲线6 u! c) N& L0 J8 N m5 J
2 T7 R* c6 u, \8 n' Z" z7 B3 C
, l4 z) K% u8 c, B" z( t8 B2 O4 {
6 k8 e( Q) y5 o1 D- #include <uf_defs.h>: w8 I/ N H1 }" t2 D
- #include <uf.h>% _8 M8 K- s m5 y7 I
- #include <uf_modl.h>* \7 ]- X: Q7 v* }( r, Z/ N
- #include <uf_object_types.h>
6 n2 o8 {% {) O7 b/ v& q& [+ S - #include <uf_ui.h>( ?( p1 m0 a' o B6 G
- #include <uf_modl.h>
# w9 m0 l2 ~1 P5 f, i7 K, V: `0 ~ - #include <<em>NXOpen</em>/NXException.hxx>% j0 s5 M& U5 X
- #include <<em>NXOpen</em>/Session.hxx>2 Z6 P3 j, Q% i6 P- |
- #include <<em>NXOpen</em>/Selection.hxx>
/ m% A4 c" \- M$ U# S, C - #include <<em>NXOpen</em>/Builder.hxx>/ C% A7 ~0 k% S- Q( y# c
- #include <<em>NXOpen</em>/Features_Feature.hxx>
- c6 i& U4 T8 P* y - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
; Z, U$ U9 S$ I0 ]- P - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
T; M0 F5 Z0 I. H - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
- z4 v: p3 n. R9 R - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
g0 ~0 g9 \/ h0 w1 s - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>5 O6 ]2 L7 G" P5 A& S
- #include <<em>NXOpen</em>/Part.hxx>
, U1 L& B/ s: f1 Q) C( j - #include <<em>NXOpen</em>/ParTCollection.hxx>
7 B% ?4 g0 e1 m+ M - #include <<em>NXOpen</em>/Point.hxx>
. ~6 p$ m+ T% j9 S5 e0 ^( G - #include <<em>NXOpen</em>/PointCollection.hxx>
: F0 f6 `# P9 ] - #include <<em>NXOpen</em>/NXString.hxx>
2 {$ A2 y N4 j4 z9 y6 R8 Y1 n/ N - #include <<em>NXOpen</em>/UI.hxx>
( J& I2 O1 ~1 Q c' n - #include <<em>NXOpen</em>/Spline.hxx>
! r( S$ M+ m2 i# n$ D$ u - #include <<em>NXOpen</em>/NXObjectManager.hxx>" m5 Z$ S8 u- ?# w' l3 @5 I
- * V% D9 X% C7 [, {% t; n
- using namespace <em>NXOpen</em>;) n. L7 N" I1 Y v8 g2 F- ~
- using namespace std;
& O+ o2 J) Q0 _. O# I - " t+ ~8 _2 _0 M. y9 { `
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
- Z) a! h6 L; H* [. X - {5 |0 V6 t, H! B, Z) o
- return (int)Session::LibraryUnloadOptionImmediately;
' p1 a5 I. S- v6 o/ D - }
* ^2 `" q- L6 v2 y! v, Q
: o- J+ q" Z8 a8 _6 d. u- static vector<Point *> selectPoints(NXString prompt)
9 S7 t! i! J* N. _7 M - {
% C! }4 b; G, W- l4 |9 r - UI *ui = UI::GetUI();
! \5 Z' _: H# H# e- B - Selection *sm = ui->SelectionManager();) I6 R; z& _: l4 n6 i# _- m2 k, s
- std::vector<Selection::MaskTriple> mask(1); i% G' A* S! s
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 E e3 E V8 F4 {) g) Z1 ]' R$ {
- std::vector<NXObject *> objects;
9 G f# @# I5 i. R Q& x" h/ @ J - ; l0 h6 F) E- k8 V, P4 H T
- sm->SelectObjects("Select Points", prompt,0 L* [# Q/ r' P
- Selection::SelectionScopeAnyInAssembly,- }- D! B) p& v5 d
- Selection::SelectionActionClearAndEnableSpecific,
- B+ {) v: D( P# F9 N - false, false, mask, objects);
7 n2 ~+ L" S8 s4 B; S0 e) \
2 \8 {: g7 \- I- vector<Point *>selPoints(objects.size());) X( R% v* m' Y& I! P6 Q
- for (unsigned int ii = 0; ii < objects.size(); ii++)5 i0 S1 @8 \: O/ T. y0 A* o) C
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 f& O. B# C7 ?. O, u- ^
- ' J, B; G! @ t
- return selPoints;
# W M8 _( t, @" A" V0 o - }
' b2 h% f5 |- X0 z2 w/ x- u) i# W7 v - 5 c8 @7 V. m' i- I
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
9 }$ X) `% z9 K9 s1 s: | - {$ V& W0 `' Q. y/ S5 w# O9 D! s
- Session *theSession = Session::GetSession();
: Z4 h7 ]" A/ }: ?3 r* W( l - Part *workPart(theSession->Parts()->Work());4 g% z- y4 C! G7 ?! ]# `
- ( j; H. g2 H/ _& M4 y# M5 M7 @6 I
- Session::UndoMarkId markId1;8 k1 _8 |) K2 \. x7 d; J3 f0 L2 S2 L
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, Q- M4 F, o# \; v
- "Studio Spline Thru Points");! Q$ v, n, t4 x. F* h3 t5 y8 t/ h: {
4 I& E k8 z5 }3 i9 `5 _, Z- Features::StudioSpline *nullFeatures_StudioSpline(NULL);3 d" a9 r3 G2 @9 K0 ~3 l
- ! ?: w3 Y* { }) l$ j! F( a
- Features::StudioSplineBuilder *studioSplineBuilder1;& G1 W8 p* x% Q6 `. l% ]
- studioSplineBuilder1 = workPart->Features()->! D; V8 f/ p5 D8 b
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);. u) b4 M+ e, r- @/ ?5 I+ R
- studioSplineBuilder1->SetAssociative(true);
. Y& J3 Q1 K7 O' l0 @ - studioSplineBuilder1-> {- t8 r0 W& `8 U9 v/ t
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
1 y) U. ]2 T) P1 Z! f - studioSplineBuilder1->/ @4 h4 n% ^/ V) O% h
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);; m1 A7 v2 O, `
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);" A3 C8 e" s! _' }7 q' u* t
- studioSplineBuilder1->SetPeriodic(false);
) U& B9 O6 F" W# h - studioSplineBuilder1->) H6 b- Y& O3 v2 N8 i$ w
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
0 b0 K k# j; w% y - std::vector<double> knots1(0);! {, F1 x( H7 [! x9 k4 l
- studioSplineBuilder1->SetKnots(knots1);
7 [9 P2 v+ w, [4 a9 `5 L0 O - std::vector<double> parameters1(0);
! @& W8 I! ?$ u, N: ` - studioSplineBuilder1->SetParameters(parameters1);7 m5 h& _% ]% s$ e% R
- Direction *nullDirection(NULL);/ K% M, Z# v; k. o$ |
- Scalar *nullScalar(NULL);
/ d( H4 T5 W; l, Y* L) B- _# @ - Offset *nullOffset(NULL);; s2 d6 ^# M2 N# D# p% y
- & {. W' F: o" k: M4 o0 f- C
- std::vector<Features::GeometricConstraintData *>. s$ v- u; k0 r
- geometricConstraintData(thePoints.size());$ y# i! |/ q* y7 q5 ~4 S
. n9 p9 B- S+ R; w$ H- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
3 F; |0 P7 z# Z - {0 M* y) n/ ~9 x5 I! t
- geometricConstraintData[ii] = studioSplineBuilder1->
" W" }" J3 _' n+ O5 p - ConstraintManager()->CreateGeometricConstraintData();- ?' Q) ?1 \0 _6 {! G( x
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
7 T$ ^. f$ M, O9 M3 g2 N - geometricConstraintData[ii]->SetAutomaticConstraintDirection(/ L( I! @9 D; o
- Features::GeometricConstraintData::ParameterDirectionIso);
' G; z5 J2 T3 k - geometricConstraintData[ii]->SetAutomaticConstraintType(9 r' D- [. x( _; m
- Features::GeometricConstraintData::AutoConstraintTypeNone);
6 S- E5 ]. R( h - geometricConstraintData[ii]->SetTangentDirection(nullDirection);/ }4 R3 y/ w+ }0 Z5 X6 F
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
) y! U: x# H/ j6 a - geometricConstraintData[ii]->SetCurvature(nullOffset);
7 m. c) j8 Y2 h4 n, P K - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
9 z4 D6 d8 I3 Q7 ^4 f9 @ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
9 x: q* q/ B- J" y5 @9 I - }
. v$ Q& b$ q& V$ B0 U* i9 x/ z0 Y/ c - ) z& r; l- D3 B) U3 u0 B1 Z/ e& r
- studioSplineBuilder1->ConstraintManager()->SetContents(
2 c$ |7 w3 m2 U1 B) T - geometricConstraintData);, H2 S5 d6 K/ W0 F( c) d' {) }
1 y, W. X7 P2 |7 e- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
$ ^$ u8 A/ ~( q5 s7 j, n# d - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
\: X) @0 c% l. g) T/ J- | - % D) W2 t x$ V# b/ q
- studioSplineBuilder1->Destroy();" G9 D: E/ K9 @. S
- ' R) i+ k8 q' q: B* P) t
- return theSpline;: i+ ?, S( j6 r) [
- }
. d4 U2 a; C3 f9 U - 9 z" R! z% U% |8 \
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
9 I1 B( x ?1 [1 N3 @( d - {
U: Q* V9 Y: ]& E6 i0 T - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
/ v( k) E5 K/ R# e3 h - if (!thePoints.size()) return;! J$ A. `6 ] z8 `
9 x5 H" |1 ?; @1 L o# ^# B- Spline *theSpline = createStudioSplineThruPoints(thePoints);
- h5 [) M" N2 k - ) J' c0 ]2 i0 J" ]: ~% M# ?( a7 w
- if (theSpline)8 L! w+ l+ R; Q
- {* H" b4 Z6 g9 H6 v* T
- theSpline->Highlight();
+ t1 ^; F2 r" P6 S9 S - uc1601("Studio Spline Created Thru Points", TRUE);
4 t9 K5 d+ k4 {& U; E, Q& B - theSpline->Unhighlight();
# f5 X2 P' T2 Z, w d2 d - }
& u& ]& u6 u# F: d/ w7 X; ]% Y - }
5 t/ C% U: o: {. ]5 Q w - <p> </p>
复制代码 0 l& x6 e' g: p% ?
|
|