|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 M1 E: | {3 @NX二次开发源码:通过选择点创建样条曲线* s; Q; P& b1 }' [5 n; \
* Z3 w) K+ ?9 v( b
! V% ]! A2 l+ x/ Z, |2 @0 ~6 ]
- % H$ o( n+ @- B: V% Z+ s8 |+ B7 n4 Z0 z
- #include <uf_defs.h>
; V1 J+ S& e5 ~ a C - #include <uf.h>
$ `7 S9 M$ X$ ]! N- c8 i4 h - #include <uf_modl.h>
, m0 Q: l5 x6 P6 Z" h5 l0 H - #include <uf_object_types.h>
0 h6 H X* }# n0 I' d2 o7 k+ ]3 j. ^ - #include <uf_ui.h>
: m/ Z1 b" H1 V7 ?- y! Q - #include <uf_modl.h>
( Y4 l" E( U. ~ - #include <<em>NXOpen</em>/NXException.hxx>4 q9 {9 a( ~* b# }
- #include <<em>NXOpen</em>/Session.hxx>/ I2 |# P+ Q7 B0 j) A1 g" A7 \
- #include <<em>NXOpen</em>/Selection.hxx>
' X: D! [! I7 e! N& p$ c - #include <<em>NXOpen</em>/Builder.hxx>
4 K( q2 K, `6 ?6 K) g: A2 [ - #include <<em>NXOpen</em>/Features_Feature.hxx>. o) N& W. I5 j" V
- #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>9 z* T3 {) a. ^! m1 `) |* o; K. x
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
# R4 f- p2 B( G. u - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>' n V; S7 D- M
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>
6 B. \5 N& T6 {, W( g) U- w( R% k - #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx> a' V3 t8 ~" f+ d* }% t
- #include <<em>NXOpen</em>/Part.hxx>
/ z* a2 d. m! r3 a3 Q - #include <<em>NXOpen</em>/ParTCollection.hxx>
# x+ {, d. w. T" k8 Q% ` - #include <<em>NXOpen</em>/Point.hxx>% a0 w6 f8 Q: X, D; Q% r! I+ p
- #include <<em>NXOpen</em>/PointCollection.hxx>6 d/ ~) `; C3 z; g# ^2 @! C# }
- #include <<em>NXOpen</em>/NXString.hxx>
# a; \. Y3 s. |9 K - #include <<em>NXOpen</em>/UI.hxx>
* \2 d) T- k! \4 I* n2 N8 k - #include <<em>NXOpen</em>/Spline.hxx> S! _9 U J! L0 e
- #include <<em>NXOpen</em>/NXObjectManager.hxx>
. Y$ }- b. h5 \4 j' o, X
( |2 ], U0 ?; l3 B1 t/ ]2 {- using namespace <em>NXOpen</em>;
. P. ~9 g9 p5 f& [' h - using namespace std;! r! [, N) O' W6 R
; B! e; f! C+ M- extern "<em>C</em>" DllExport int ufusr_ask_unload()
8 D0 x- l0 S) v' G' g9 ]( d3 t3 i$ [ - {' M( G/ x8 s% S, k% z1 ~: ]$ x
- return (int)Session::LibraryUnloadOptionImmediately;
: t7 Q' }6 G/ E$ T' I/ s7 f$ { - }
! Z' \* T( V, T: r" [9 G - " O" `0 a* V* s( a: [
- static vector<Point *> selectPoints(NXString prompt)
+ ~: D" t: E& r3 t$ ~ - {
7 B6 o* r5 I# F3 F" y7 ]) l0 U - UI *ui = UI::GetUI();. P* m& p3 |& O* d# Q! G
- Selection *sm = ui->SelectionManager();4 M/ I- \2 P2 y' n6 I# q* `/ r) m
- std::vector<Selection::MaskTriple> mask(1);! ^9 i" ~* s; {, Q# K
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 p! X* g* ?; s; W, R2 t+ S
- std::vector<NXObject *> objects;
7 h5 a- \: t& u, C - ! ?# a9 x m2 L& M: q
- sm->SelectObjects("Select Points", prompt,
! n* x- @) v6 I% ]0 [3 |. } - Selection::SelectionScopeAnyInAssembly,- t0 C# |! v' L! f( O- D, @
- Selection::SelectionActionClearAndEnableSpecific,
* ^, T3 D/ t; z5 f - false, false, mask, objects); z8 ]# }" x8 B: O6 G7 i1 C
- 6 W+ ]" M% ~; {! S! O0 s
- vector<Point *>selPoints(objects.size());
( C* w, p, h* r' A9 r - for (unsigned int ii = 0; ii < objects.size(); ii++)3 {3 L+ A% @; d" H, T. a
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
+ g) p! a7 Y. c6 a - ) G7 \- k" x/ K( s. ]: |$ s7 H3 Z1 j
- return selPoints;
& R, i; _3 U0 Z# H9 p! a - } K# A. \! m' f. G: X- O2 a z, S
- ]* ?# E$ W- O- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
" i0 \& W# F7 C& E - {+ Z( [* U6 [6 i( S: T
- Session *theSession = Session::GetSession();6 G7 w* D. `9 B' y. S
- Part *workPart(theSession->Parts()->Work());
; x+ R' Y8 ?& s# ^- p' ~3 U
- a [ J9 Y$ E5 ?5 Q9 `2 W- Session::UndoMarkId markId1;
* g F, k: t$ e. E9 b- D - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,1 D: w: V3 H9 R7 O w% W
- "Studio Spline Thru Points"); H3 |3 q$ H, C9 {
- F5 K& D7 ^. t& b4 G* M
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
0 {7 W. S' y) Y5 X- W0 C
0 t" O6 v/ I! P2 E" q- Features::StudioSplineBuilder *studioSplineBuilder1;. r) ?2 R& ?# \7 _: V+ _
- studioSplineBuilder1 = workPart->Features()->
) Z w& Q* n6 H& k4 ? - CreateStudioSplineBuilder(nullFeatures_StudioSpline);5 z* g( k) y8 X- d5 M) p- g
- studioSplineBuilder1->SetAssociative(true);5 ~9 M+ Y& j1 I
- studioSplineBuilder1->, Y: E) _3 X0 m! F
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);- Y1 n6 |% _+ s2 w
- studioSplineBuilder1->
; `( [7 g1 x9 H: S, G7 L- j - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 c8 b6 q- S# S N4 V( `) X
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
# ?0 }+ T6 E7 \ - studioSplineBuilder1->SetPeriodic(false);' r9 ^- f5 O [ N6 s# _- t8 q
- studioSplineBuilder1->
$ v% Y8 d+ C8 A* i0 e! c3 R3 G - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
8 s) _4 l. u7 M - std::vector<double> knots1(0);
2 t" c3 E9 r8 s$ J* K - studioSplineBuilder1->SetKnots(knots1);
c; Z9 u* s& R/ |! U9 ] S - std::vector<double> parameters1(0);3 C# g. e: v8 `" N- H
- studioSplineBuilder1->SetParameters(parameters1);
, Q" i3 ^! L, F Q: f# h F - Direction *nullDirection(NULL);" h- B4 w/ c+ n, q6 }
- Scalar *nullScalar(NULL);
* g4 M, v8 Q2 K0 U - Offset *nullOffset(NULL);
( J+ |6 e3 u; v6 D
* y9 k8 S6 i a5 X- std::vector<Features::GeometricConstraintData *>
1 m4 ~. Y% K+ @' H0 [3 P O - geometricConstraintData(thePoints.size());( c, j& X8 `! m3 Y
; H4 p6 f6 H* P- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
7 ?0 [" Y9 Y3 \2 D* V2 A* m - {' T& `* z% F R% b3 l
- geometricConstraintData[ii] = studioSplineBuilder1->
0 U) u1 [1 C$ A3 v - ConstraintManager()->CreateGeometricConstraintData();
8 ~: ]' j' a) [: G | - geometricConstraintData[ii]->SetPoint(thePoints[ii]);+ g( J1 s$ p5 X5 L* e2 e$ ?; F
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(; g, N) G3 c, u4 B3 ^
- Features::GeometricConstraintData::ParameterDirectionIso);1 L6 V; {$ Y9 B; L
- geometricConstraintData[ii]->SetAutomaticConstraintType(: [) `# H" O$ u1 L9 K: ~8 v
- Features::GeometricConstraintData::AutoConstraintTypeNone);% M$ p: k: v5 G! I
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
7 x: R) o8 A- f# b7 j9 V - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ @- X; w9 x' m1 r4 X
- geometricConstraintData[ii]->SetCurvature(nullOffset);! J* L0 f' {) F/ t, A- B, \
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
- h7 d2 ^- J" P - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
' D- U. k: i* c7 v5 `1 { - }8 o1 O: k. a% p% M8 V# l' ~: S
# r! e6 p) k1 Q6 W+ F1 N3 `# X; _- studioSplineBuilder1->ConstraintManager()->SetContents($ Z4 q* Y& [; L' i5 D) J
- geometricConstraintData);$ I/ a( {) M! J+ s* K
3 A- P. {5 \* f$ ~% o- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
7 L$ Q! s6 y7 f1 ?& E - Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
6 L- W/ u& W) R# D - 2 ~7 `8 S* `1 l, G% t6 \; Y
- studioSplineBuilder1->Destroy();
8 p; r5 t& Y* `. j- X2 ^
& o8 C; o: f6 J" |1 X7 T& u- return theSpline;
9 g/ k; O0 K: P" z* p I* M4 e) Q - }
7 Z _9 I' ]# Y' I5 e - ! x: X/ G0 E7 s( f' G% z# P
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
9 M; x. b5 e8 }2 z) \) w% G: V( s! ? - {
( _7 |( L7 C( | - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ v5 B6 ~! D8 V$ i3 b( K% A
- if (!thePoints.size()) return;
# L- h# W6 r# k1 @* ]3 i4 A - 7 f# e5 I3 L$ W [' U3 x
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
0 D( R0 d& v$ C) Y2 U- R8 v+ w - P& D4 w q( b1 {: t* t
- if (theSpline)2 [/ {9 p* e6 N5 A4 s m" `
- {
1 ~/ K1 ]/ ^4 I- z* t- r - theSpline->Highlight();8 E% r' ]+ u9 H! l0 j* o
- uc1601("Studio Spline Created Thru Points", TRUE);
) k. _% B0 H: \" [) K6 X4 d - theSpline->Unhighlight();
2 d7 w: r) E1 i5 h3 X$ M f0 u - }9 `( ~; n6 ?; l% Q
- }4 M/ f# V n6 ~
- <p> </p>
复制代码
4 Z' p2 M9 \9 U( f3 ?! R' c# @ |
|