|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) w2 G. Y9 |# ?$ t, j8 GNX二次开发源码:通过选择点创建样条曲线
: `+ f/ e& ~ L) E( S- B* _( k. D4 s6 G2 n& I* H# I0 G! t+ C
0 b5 W1 m6 G- T6 M' b$ m7 m
; ^# d- ]1 ~7 G) O' @2 {- #include <uf_defs.h>
- V0 {% W4 i* I* b3 u! W - #include <uf.h>
, Z I0 F' t. D - #include <uf_modl.h>
, J! B2 g% G3 y2 t# M& z - #include <uf_object_types.h># c, a2 j" k) q6 }0 P- x
- #include <uf_ui.h>
! Q8 b; c+ n2 H5 k - #include <uf_modl.h>
6 g: l( \/ j0 \1 L8 M0 }/ l6 Z7 d - #include <<em>NXOpen</em>/NXException.hxx>) _7 _. z5 l! ?0 B7 d. u0 o# S
- #include <<em>NXOpen</em>/Session.hxx>0 b2 `! M' o$ {& s8 o' z) L
- #include <<em>NXOpen</em>/Selection.hxx>+ m7 W b; e2 ]* D* \
- #include <<em>NXOpen</em>/Builder.hxx>4 x, {: _* u* H8 a& b. ~( Y! _( R
- #include <<em>NXOpen</em>/Features_Feature.hxx>
U3 a2 }' L3 }" t/ ]2 m# p ` - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
0 t; ]' N/ r7 T% K - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx># x( k6 a) g" F0 X/ b' d" c4 m# M
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
B, O3 _- d1 G, {7 c/ W: J - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>% C1 z. i3 r H9 i. a
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
1 a2 u1 U4 M0 A- f" ]. v - #include <<em>NXOpen</em>/Part.hxx>
. k# d- p' W8 \( n2 w - #include <<em>NXOpen</em>/ParTCollection.hxx>4 d- |3 ?/ O" Y$ }" M n
- #include <<em>NXOpen</em>/Point.hxx>; }) z5 s% P. N& R
- #include <<em>NXOpen</em>/PointCollection.hxx>
' o3 P0 h; l4 F% [7 { - #include <<em>NXOpen</em>/NXString.hxx>
- J# g! \2 F; k. M& F1 } - #include <<em>NXOpen</em>/UI.hxx>
/ Y5 C! c; x6 V$ K$ y - #include <<em>NXOpen</em>/Spline.hxx>
2 b/ U# t$ i" u& V - #include <<em>NXOpen</em>/NXObjectManager.hxx>
3 x$ x2 q3 P0 g- q4 X! Q @) }
. E; ~! `* q& k% t- using namespace <em>NXOpen</em>;
7 f2 {, }' a8 B) v- K5 J4 B - using namespace std;! o" s0 W+ ^' p9 `
- 9 j8 a8 @* s! P" E, ?# X1 k
- extern "<em>C</em>" DllExport int ufusr_ask_unload()
$ _8 z4 E6 d3 w, T* H( D - {7 z- Q W: B" Y
- return (int)Session::LibraryUnloadOptionImmediately;
1 Y! t% d' S/ }. w f! t - }
5 Z5 t( b( U' m - 8 v% S+ D5 d4 u% ^
- static vector<Point *> selectPoints(NXString prompt)
8 Y" ^% Z/ q: J1 v! x9 s6 ] - {
0 U. T$ c7 f( a - UI *ui = UI::GetUI();! n2 J7 o3 _6 A0 m+ C" G( F4 |4 F* o
- Selection *sm = ui->SelectionManager();
, r4 G+ z& k) U0 N - std::vector<Selection::MaskTriple> mask(1);$ X3 F# T: ?6 s: `
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);% t$ I& E! Q# W. s9 f, S# u5 f
- std::vector<NXObject *> objects;
$ K( y# L: c# A& J - . d3 J6 C' L" y% |2 @
- sm->SelectObjects("Select Points", prompt,/ K" @/ {& Z0 Z/ d8 {
- Selection::SelectionScopeAnyInAssembly,
0 A' C& X- N8 ?: t( R. U2 K3 G; L - Selection::SelectionActionClearAndEnableSpecific,8 h: e% S/ F! ^# f: z, D3 X: O6 Y$ I2 m
- false, false, mask, objects);# `* E3 K$ R3 l. \
9 X1 r8 J. ^5 f/ ?, m- vector<Point *>selPoints(objects.size());0 `4 S& }! ]: h/ u9 O
- for (unsigned int ii = 0; ii < objects.size(); ii++)
5 ~0 F# H+ ?# i- q0 d. p - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# ?' { q, u9 x. W. j9 r7 g# d0 H9 M4 M
- $ w, r- a8 H) R
- return selPoints;! v/ D- j! g* }+ M" Y- ]
- }
& l# T+ O T/ ?) r8 H' t0 i
# t- [5 u% B7 z) |- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
- b( U: E5 t9 S& B) f9 c - {
$ s' h$ H0 r6 `9 k+ z3 U c" y - Session *theSession = Session::GetSession();7 q) \/ f) J; `8 V$ x
- Part *workPart(theSession->Parts()->Work());! Q. S1 u9 B/ q' \) U8 D2 e
/ E3 H" n. k$ D, C& S; ^- Session::UndoMarkId markId1;5 |8 }: k: x& D9 h: b( W0 A6 R
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
" m8 K4 n3 g$ _! ~3 i' g - "Studio Spline Thru Points");& u3 x' N( k6 k
) F3 E5 N# f7 F4 P6 r3 |- Features::StudioSpline *nullFeatures_StudioSpline(NULL);# K$ N: n) C% H2 _) @2 @
- # p; I/ U2 u4 a8 X. C$ J
- Features::StudioSplineBuilder *studioSplineBuilder1;
3 ~5 l/ `# _; q+ t7 ~: G - studioSplineBuilder1 = workPart->Features()->
$ y" o5 V& X! g% M7 \( w7 ` - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
/ I. P* k- m# h8 t0 L - studioSplineBuilder1->SetAssociative(true);# r+ [' w+ V3 r7 }3 Y
- studioSplineBuilder1->/ H3 t1 b% h, N1 e
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);+ l8 J# p# |+ D$ H" U
- studioSplineBuilder1->) @8 L* G& [8 E+ w( n% y
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);# @( Y8 y$ I( F ?( j9 d
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1); {/ P# e+ i6 A
- studioSplineBuilder1->SetPeriodic(false);4 e, }3 z |! j6 i1 s; ?
- studioSplineBuilder1->; m, U+ [. \5 T
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);, j, K! q" h0 l3 e6 H1 a2 @! p9 J
- std::vector<double> knots1(0);$ k# k% Z& y+ o& m
- studioSplineBuilder1->SetKnots(knots1);+ O( m- T: r& O1 J2 s
- std::vector<double> parameters1(0);# Z& i; b) }& A) K3 \
- studioSplineBuilder1->SetParameters(parameters1);
( ~, f7 w$ u2 j5 T$ D! K - Direction *nullDirection(NULL);: m2 D# A: _/ J4 t" q$ V
- Scalar *nullScalar(NULL);" I- D9 K9 f' z, X/ f: \( e
- Offset *nullOffset(NULL);# O5 h/ z {5 w* x. y
% A4 ]# Z. V6 @* h- std::vector<Features::GeometricConstraintData *>
7 p! f" `1 }% {& M" ^3 P/ K - geometricConstraintData(thePoints.size());- v" s$ B( [) M) K+ {
- 3 }, d! R! J8 x) m- l R# \
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)" a4 q7 ] i$ U) ]6 d2 u
- {! o- A0 ~$ s/ M* X' \* J
- geometricConstraintData[ii] = studioSplineBuilder1->
; g; `7 Q- k V H: i - ConstraintManager()->CreateGeometricConstraintData();
+ F6 M' E; c W0 s2 ?- n - geometricConstraintData[ii]->SetPoint(thePoints[ii]);1 U2 H2 @' x- q o: G
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
j+ B0 T0 l: i+ W6 z3 B - Features::GeometricConstraintData::ParameterDirectionIso);
7 }6 D/ a4 o+ S3 F; i' f - geometricConstraintData[ii]->SetAutomaticConstraintType(2 j n8 o) m, H/ [% A
- Features::GeometricConstraintData::AutoConstraintTypeNone);
. e- z. H* @; V5 w9 L( S1 T) I - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
- F* F7 r% d7 i7 N2 {/ Z3 u - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar); U5 @5 G. S0 r1 y j/ v
- geometricConstraintData[ii]->SetCurvature(nullOffset);0 y5 |7 f( S) z/ }/ `- B- d
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
. n( ]* ~0 N5 x7 k) X4 Q( c - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
1 F V. r7 u5 n7 ~ _' G6 R- v - }5 K; o) m2 G5 \0 D) y( t
| F/ V8 ~' z; b& P, t/ |( a- studioSplineBuilder1->ConstraintManager()->SetContents($ v% |; {. \, {& u8 ~* E6 f1 _3 J
- geometricConstraintData);
/ G2 C# v: F1 I1 c
% X/ H1 Z/ x2 A( B; t, X; ^- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
: N7 X% j7 y4 C( ?* H+ {5 v* A1 g - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
% l6 K6 h! u% @
" P/ V6 r7 x8 E: O% W; @- studioSplineBuilder1->Destroy();4 ^% t7 a' l- q+ W
$ w- Q# x& ?; T. Y- return theSpline;
4 L- I* Y8 |. f8 T1 R - }
8 {9 H+ _8 q) ?
+ l: X4 m4 p) Z x- ?% b& ^- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)+ a$ u! z8 i+ c/ N' i
- {
7 ?8 q4 p8 R# y# ]8 z& [' [" z$ m - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
+ \9 c/ N: `: V - if (!thePoints.size()) return;
5 z! o" ]! i* @
1 h) m6 T6 |: h7 g# Y0 Y$ c- Spline *theSpline = createStudioSplineThruPoints(thePoints);) _) N# |/ R2 {8 c% X+ i
: n, U# e$ T! f C# h _# H* T- if (theSpline). I! I |1 c1 Y& K+ f/ Q
- {4 [* v9 z) Z- N9 @6 S! G6 C6 t8 S
- theSpline->Highlight();
3 `' E1 X7 Y8 q& x/ \& z& ^ - uc1601("Studio Spline Created Thru Points", TRUE);$ i( y# G! {. f0 b
- theSpline->Unhighlight();
, }; }; x* X, ?, L' ]7 A% \ - }4 r. @4 w6 j9 a/ O7 r
- }
' e- g, ^# Y% l q- R0 E - <p> </p>
复制代码
% H$ e: c/ [" X) y5 V |
|