|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
1 ^: q* c4 R5 S: a8 r5 a& W, c9 v& ]( rNX二次开发源码:通过选择点创建样条曲线
: r5 Q5 y# z, }( }$ }; \7 o4 g
- j. j9 `: N1 F0 {/ I& p8 {/ ?2 V, h" ^- k
, n& s# p `/ F: }- #include <uf_defs.h>
`# ?& I: n+ J - #include <uf.h>" l! j3 }3 S9 p
- #include <uf_modl.h>
9 B2 K# s7 n+ V8 y3 A - #include <uf_object_types.h>
2 s6 F7 d% W6 p5 ]0 z% S- ]* `) x, D - #include <uf_ui.h>
x, r1 @/ Q2 T8 { - #include <uf_modl.h>
8 M" h+ u& _3 J+ w - #include <<em>NXOpen</em>/NXException.hxx>$ n( }9 `+ o! h% Z
- #include <<em>NXOpen</em>/Session.hxx>, K% C. x3 \* c1 l$ J
- #include <<em>NXOpen</em>/Selection.hxx>* u: a+ U9 H( i2 D
- #include <<em>NXOpen</em>/Builder.hxx>
" @) f6 M8 _, A! T3 a! G( Q - #include <<em>NXOpen</em>/Features_Feature.hxx>
, u7 N: ?' H/ [1 R/ g4 X) D - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
J1 k0 w( f: v: T: w6 z5 U% g - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>
. x! k" m5 g+ ?" s( g& @ - #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>
# `+ ?, s' a, }8 \) }0 S - #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>1 {, s+ Q( v. j2 t
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
. S/ P* D, @5 G# P% t- } - #include <<em>NXOpen</em>/Part.hxx>5 ^6 K" F( q" n$ q
- #include <<em>NXOpen</em>/ParTCollection.hxx>
* t7 a' F9 E: B# V O! P$ I( f& F8 J - #include <<em>NXOpen</em>/Point.hxx>9 G$ m, L# R: ]" d0 d- N8 S* D; d. H& l
- #include <<em>NXOpen</em>/PointCollection.hxx>: q6 G& p' Z+ e7 v' L% e
- #include <<em>NXOpen</em>/NXString.hxx>
, R) ^3 A8 X6 `% y- A - #include <<em>NXOpen</em>/UI.hxx>
! n( [; H7 @- W$ _" e - #include <<em>NXOpen</em>/Spline.hxx>
5 e/ N( b3 c) [4 O! S - #include <<em>NXOpen</em>/NXObjectManager.hxx>- A& u/ E! T& |' m
$ r* J" ?& [7 w2 b& d# H0 Z$ x- using namespace <em>NXOpen</em>;; y- K: O; N, _! X
- using namespace std;6 o3 ?3 |' R6 X
% ~( W6 x2 V& c4 i" x/ d- extern "<em>C</em>" DllExport int ufusr_ask_unload()! C: i I! P7 z$ ^& y, q
- {
5 i8 W# D+ K2 k2 |) k* h - return (int)Session::LibraryUnloadOptionImmediately;
. Y0 i7 A) z X+ m% Y: ^, V, B - }
! d; Y$ n2 z3 f) n$ }/ N+ d$ h4 o3 \
* ~' [2 I; u3 _% h5 g- static vector<Point *> selectPoints(NXString prompt)
; U4 k0 a+ H: B' I7 n - {
9 P. @ B7 n7 d; }# `/ d - UI *ui = UI::GetUI();
" o, {% `/ z7 U4 H5 d# j - Selection *sm = ui->SelectionManager();
: D9 c/ U* E+ P: H6 ]& l - std::vector<Selection::MaskTriple> mask(1);
5 N/ }) N, d. Q* b7 d! r - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
N5 G# ?; X1 R! E4 T/ F$ I - std::vector<NXObject *> objects;- n3 r3 b8 U3 u3 s
! S+ u* X$ j( M4 |, ^0 [- sm->SelectObjects("Select Points", prompt," s7 o% C# k. b/ U9 e+ z6 }
- Selection::SelectionScopeAnyInAssembly,
$ `" q+ Y2 V# {' r - Selection::SelectionActionClearAndEnableSpecific,
) ]! S3 [. d% b1 Q2 f5 ~. I# A - false, false, mask, objects);
% |" p1 A$ X+ H9 p, U
& R. L8 r5 i; r- vector<Point *>selPoints(objects.size());9 ?! Q- s8 L3 O
- for (unsigned int ii = 0; ii < objects.size(); ii++)$ S( R6 A* r( U: i" M
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
( w9 L$ {! Y3 P0 y7 n
4 M: }6 e& ^/ K- a. O- return selPoints;/ C K, I9 X( y5 f2 c" k8 a
- }& e* j A" Y: P* {2 |; r ]
5 p$ p9 V3 a% |1 f$ ^' C- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
9 F/ S' [+ z1 y' s1 Q. j1 @% ` - {
. G) q" m! h4 \" V t - Session *theSession = Session::GetSession();4 Z" I/ Z1 P; Z' E
- Part *workPart(theSession->Parts()->Work());6 @1 W3 R, ^+ E- O
+ |9 g: g2 ~3 F2 i) y* n# e {- L' C- Session::UndoMarkId markId1;
$ Z/ u" H" A6 E$ I - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
. u8 r1 L! J; W& a# J - "Studio Spline Thru Points");
: w: h; _4 @# H6 }/ p! G7 w0 G - 0 i; @% c, o! ~- _ c
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);, R( S0 @" o+ R( |9 _" Z- K/ u0 ]/ ^
3 b! ?7 z3 a) l. w- Features::StudioSplineBuilder *studioSplineBuilder1;
- d) p3 t8 ]: {1 U) V - studioSplineBuilder1 = workPart->Features()->
4 X- }- G1 I) Q2 D* s - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
- O% d7 c! h1 _7 ]5 W) C8 \ - studioSplineBuilder1->SetAssociative(true);
0 j- M6 c0 `/ }- R- \6 g - studioSplineBuilder1->
2 |$ ?2 j" Z; d' y/ B - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
5 Z8 O1 \8 r" h& W7 Q5 W1 v/ \% K - studioSplineBuilder1->
$ z4 e0 F5 k9 y8 c9 U+ i - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
' W8 g0 |+ w& x. ] - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; B) y) H; M/ R7 G- Q- ^
- studioSplineBuilder1->SetPeriodic(false);
v/ d- Z+ S h$ O+ q+ a- Z - studioSplineBuilder1-> ]4 {6 p) j, R( f- [
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);( f# H4 d' Q7 K* |) D9 v
- std::vector<double> knots1(0);
# q! l' r5 V" {" k - studioSplineBuilder1->SetKnots(knots1);3 l3 X. h; s. l( h1 I4 y
- std::vector<double> parameters1(0);
$ V) O6 {' S3 L) M - studioSplineBuilder1->SetParameters(parameters1);
9 b* c& z9 v' P. q' W, q - Direction *nullDirection(NULL);
/ w3 ? D8 g; z* E6 p0 Q& i - Scalar *nullScalar(NULL);: c# }: P5 z" @5 @
- Offset *nullOffset(NULL);9 N0 K! _2 D9 x: S' o
0 x# t9 u* o# o8 P W9 p- std::vector<Features::GeometricConstraintData *>
7 N. b5 @ {% {7 K; F- ?" d - geometricConstraintData(thePoints.size());: `7 u& @" }3 H: P- {1 h3 h) y9 Q
- $ C2 }# @, u4 N& u( c/ ^6 X
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)- u# P; Q- d8 W, e! T
- {/ s+ z/ O- Y: n& r6 x7 t+ d
- geometricConstraintData[ii] = studioSplineBuilder1->
/ `" w. Y, O: b& T% r7 N - ConstraintManager()->CreateGeometricConstraintData();1 R- j4 u" r- i; q3 }8 c
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);# Y( W" [* Y8 U
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(" l% @) D- e ^
- Features::GeometricConstraintData::ParameterDirectionIso);
# s2 @. Z! ?. e, L: z - geometricConstraintData[ii]->SetAutomaticConstraintType(& P5 R( J; T& {
- Features::GeometricConstraintData::AutoConstraintTypeNone);
4 c% h" w/ c' L- P5 V1 Z9 ?2 B9 s - geometricConstraintData[ii]->SetTangentDirection(nullDirection); w( k5 D. O5 K9 ?, a1 \2 E/ j/ M
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
/ l! R- f! z$ d$ I" P - geometricConstraintData[ii]->SetCurvature(nullOffset);, p0 S6 l2 r, K+ \
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
7 I2 _9 d% t. x. c# F6 d7 C - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);/ q$ v9 E% o: \+ [6 \! |
- }+ O9 w# ]% Q$ K. k
3 `% T7 f# Q) ]! O' H; [9 S- studioSplineBuilder1->ConstraintManager()->SetContents(& r% O8 M1 Z0 h: m
- geometricConstraintData);
2 `0 o/ { S& j% K. p @ - . X5 r. h S- {' o$ j% h
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();6 q/ |& N9 N" v0 p& m4 j
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
* U. [# B( l+ L5 i
! \7 ?' e+ g: e) }; @6 m- studioSplineBuilder1->Destroy();
7 e+ o. c4 v {9 ^2 c/ k) \ - 8 [1 F# n; B& u4 }" H2 p- w# b
- return theSpline;
) g+ v" e6 w6 d7 V5 N. F - }
: {: b1 F; C9 Y, L& t
/ H2 S8 Z# A8 i- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)
' c! }2 m; V: U" k) S8 K# r - {8 b1 y; Q; D; L" G; m
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points"); l* U& N! v; q3 m- C
- if (!thePoints.size()) return;
8 A$ U: `" _3 I/ a3 d% f% P* |) R
$ k" Y* z( K) p* p- Spline *theSpline = createStudioSplineThruPoints(thePoints);
! S( |# J, J" q5 l/ |5 K9 Q! O - - S3 M5 T/ N, U0 K
- if (theSpline). b' D/ v1 Z3 Z2 S h' A0 P8 A/ g
- {: j$ v+ e1 A6 K3 g7 j4 w2 ?+ g
- theSpline->Highlight();
7 U' Z( j V& H% G$ S - uc1601("Studio Spline Created Thru Points", TRUE);
F# l: M3 e# j4 Y - theSpline->Unhighlight();) i- m4 W* b. a3 ]4 j1 h
- }0 o$ u5 k/ ^0 Y% i3 [! V; [
- } P+ t& d9 c, O' G- j6 F% u/ O9 ?; B
- <p> </p>
复制代码 % L+ ]7 X* L: i# Z7 D
|
|