|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
p4 [( D" C9 A" i% o9 {& D4 L, H
NX二次开发源码:通过选择点创建样条曲线
) i% }9 U# M" a. t8 o8 q. e ^4 s
Q) |: T& V% i X7 {
! o# g: R, w9 D) n% E* G- r; y0 E; A; t- #include <uf_defs.h>2 N; b* k3 r0 z9 [: o
- #include <uf.h>5 Q4 U+ l7 y" D7 a$ [ w
- #include <uf_modl.h>
# B; a. n8 v& A' G5 B { - #include <uf_object_types.h>
! M/ v6 @$ C$ l: R$ q( F - #include <uf_ui.h>
; B4 P1 c3 J: T! f - #include <uf_modl.h>
2 m Z: e6 i. D - #include <<em>NXOpen</em>/NXException.hxx>
9 J1 X' k2 D$ N, L! \ - #include <<em>NXOpen</em>/Session.hxx>
, Y V% [$ N9 Y5 c5 A - #include <<em>NXOpen</em>/Selection.hxx>
m, n5 _, F0 d3 s; C; b- h, L. T - #include <<em>NXOpen</em>/Builder.hxx>
) y$ u1 h; z2 r4 d; V3 R: \3 w - #include <<em>NXOpen</em>/Features_Feature.hxx>
9 |& @1 ]6 L9 N% E# C# |- z' m - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>
" k9 Y2 z2 P2 w) y - #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>8 ]% h& Z2 f' k- d( m% z/ H
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>1 }& b% B; ^ P9 m% B9 l
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx># X4 w$ _6 _* g( q: N
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>
3 ]: O5 Q2 H5 g - #include <<em>NXOpen</em>/Part.hxx>) G {5 o; G+ N
- #include <<em>NXOpen</em>/ParTCollection.hxx>4 q" e: w( ^" c
- #include <<em>NXOpen</em>/Point.hxx>' N: }: S2 s6 [% k) @
- #include <<em>NXOpen</em>/PointCollection.hxx>4 D" X9 z7 i7 E+ e8 u5 n6 o2 M8 _8 R1 O
- #include <<em>NXOpen</em>/NXString.hxx>
- x$ i' Y5 v8 H" ~6 i9 g2 U V+ U" n1 A - #include <<em>NXOpen</em>/UI.hxx>
# B( f$ X* \5 a9 `; |8 v( v- n - #include <<em>NXOpen</em>/Spline.hxx>
0 }. J ?7 u( ^/ x - #include <<em>NXOpen</em>/NXObjectManager.hxx>0 E6 S% Y9 j/ _) }9 x
) a O: f" k5 W/ v) Y- using namespace <em>NXOpen</em>;
( J8 b* o2 Z- ^ - using namespace std;% `6 U4 v4 |0 A
H7 U. c. g1 u( d: n+ H- extern "<em>C</em>" DllExport int ufusr_ask_unload()3 c3 Z$ S/ L- E s, k, H
- {
7 Q# Y5 G7 ?$ `; E4 L+ v2 m - return (int)Session::LibraryUnloadOptionImmediately;) i% j3 | O+ x. ~" q7 ~
- }' ?0 g0 R5 t: {+ |
- 9 h" V, h5 V' l9 V1 q5 A! H/ _
- static vector<Point *> selectPoints(NXString prompt)
. F# n/ J; X' S+ c' U& R; b - {
5 l8 i$ \4 ^# A7 G; m* V - UI *ui = UI::GetUI();
* X' f- l* y8 v/ N( y, e - Selection *sm = ui->SelectionManager();7 g3 h3 G! B+ J& s+ M
- std::vector<Selection::MaskTriple> mask(1);
) { z; `' V+ Y) [. U# g$ r - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);$ K4 P/ [+ h( {6 @
- std::vector<NXObject *> objects;% s' A/ i; d) S8 Q
- # s- u4 M1 {! |5 T4 ^4 i" H
- sm->SelectObjects("Select Points", prompt,
[" X4 X G% ~3 m0 T4 a - Selection::SelectionScopeAnyInAssembly,$ k% C+ {) r& \) d S7 `0 D$ P6 U" X
- Selection::SelectionActionClearAndEnableSpecific,
" n* g5 ^5 h; q! T$ G6 A! Y - false, false, mask, objects);& B) P% S0 h$ d
- ( Z# ^! s( m- E! D1 W' h& x
- vector<Point *>selPoints(objects.size());3 v* E& e! ~# {! K
- for (unsigned int ii = 0; ii < objects.size(); ii++)- b$ Y* \ }5 F3 U+ \/ _6 H
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);* Z( N! l$ K. f, j# [/ S
- 6 s$ F, m( S% R2 ?1 t' c
- return selPoints;
$ ?0 ?" |0 l1 S - }
: B" d" z- f/ ^0 v; g - 0 @2 D/ b0 C# h0 M% H1 X
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)6 [3 z9 j C" U* f, [
- {
) c8 a+ k! C, R! X% o: S/ o - Session *theSession = Session::GetSession();
* e! ` G% b/ c+ Y - Part *workPart(theSession->Parts()->Work());
* \$ t$ \2 z1 z2 {: J: D - ; E/ s, b, S p
- Session::UndoMarkId markId1;
" L( ?$ F1 Y0 _. o4 Q - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
9 k+ F3 T" T4 e) F3 v - "Studio Spline Thru Points");
# {5 g* S$ `$ j4 E1 ~) t+ l5 j - - H5 ]3 W# Y2 X
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 R- n. [( x& p7 o
* }& T3 L0 A" M& ]8 d R- z- Features::StudioSplineBuilder *studioSplineBuilder1;& c! e" {. P3 x8 c* Q5 i
- studioSplineBuilder1 = workPart->Features()->
% V/ T, o' d/ j1 w6 C/ X - CreateStudioSplineBuilder(nullFeatures_StudioSpline);* p9 @8 a& y$ F w, G
- studioSplineBuilder1->SetAssociative(true);
- Q# |+ K1 z! D% E' j - studioSplineBuilder1->
/ _3 x5 Z+ q! z! q - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
- X9 @" Z% p. }0 F' { - studioSplineBuilder1->
. P$ H# `$ }. q3 H2 d' T' u/ f - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
3 }; F U+ `' b9 N0 \$ O5 c - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
; U. g4 z" Q- F - studioSplineBuilder1->SetPeriodic(false);
7 G' S+ }$ N& Y4 z( c - studioSplineBuilder1->
7 L. D. i5 x/ n' w/ A4 J G5 t - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
6 p2 M/ p; s$ M* M/ U - std::vector<double> knots1(0);: l& m/ Y7 w6 G
- studioSplineBuilder1->SetKnots(knots1);* L4 @. D2 z8 A+ N
- std::vector<double> parameters1(0);
+ v, O2 k% c" s; L3 p$ \: b' x - studioSplineBuilder1->SetParameters(parameters1);$ C/ S- g* H+ a; r7 w+ o5 i7 C! @
- Direction *nullDirection(NULL);
" e2 M- ]* z0 _* j3 U/ x9 r) n" l - Scalar *nullScalar(NULL);, H4 a& R p* \9 H- P
- Offset *nullOffset(NULL);
7 X- k- j0 C) T7 X! c, |/ ?1 w
$ u4 Y( J$ G. I0 Z- std::vector<Features::GeometricConstraintData *>
; Y4 u' Q3 c" H. b$ D( s7 |1 T" Q5 x - geometricConstraintData(thePoints.size());
5 K. J( W3 a5 U! l! S
' e$ {' `4 f6 f. F2 _0 D0 @- for (unsigned int ii = 0; ii < thePoints.size(); ii++)* w. x; |1 c9 I: F. D
- {9 n: `/ F7 Y1 c+ E# ?: w2 H
- geometricConstraintData[ii] = studioSplineBuilder1->
9 j1 I3 R1 z5 A* z - ConstraintManager()->CreateGeometricConstraintData();
L6 I7 p- W$ Z* @2 j4 r - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
0 U/ m4 J i) O% h0 F* Y2 u7 b+ Z - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
. e& E0 f5 B9 X - Features::GeometricConstraintData::ParameterDirectionIso);
1 k% R$ |; a: S - geometricConstraintData[ii]->SetAutomaticConstraintType(& r; T" k4 R' n
- Features::GeometricConstraintData::AutoConstraintTypeNone);4 s% G! m& k8 _# g
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);3 ]3 q! X) [, r
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
M# d7 v5 P7 j4 h - geometricConstraintData[ii]->SetCurvature(nullOffset);
. Q$ A9 H+ ]% E1 ?+ v; G( h0 [7 x - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset); n$ P4 W! @$ }3 C/ X, {9 k6 x
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
3 r) n* z2 ^1 ]1 E# v' p$ x - }& Y! f. v+ S3 O) A2 |
% \6 {% ?9 r) s5 N1 e' ~) @- studioSplineBuilder1->ConstraintManager()->SetContents(
) W. A. A3 w# a" _ - geometricConstraintData);5 i) h5 R" K* m- v
9 `& e7 L4 L; Z$ M7 [- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();7 v3 ], T/ u# C8 b
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
( h# N. Y) i0 u3 j8 p' j, ~
, J! q4 M# S7 n$ c5 P. ~ G, C1 s- studioSplineBuilder1->Destroy();
|3 {7 S4 w9 G, t: D
. C+ v1 ]/ e4 r+ F- return theSpline;
0 k9 x+ I1 \: \, d8 r/ M$ k - }
! Y' B8 B" b% Y S- C% q/ j1 D
7 C7 S/ u, Y; W8 Z- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)3 { _& M9 X- P1 o( ^
- {/ C- i. H+ W4 d" C& H
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ {. Q) |* x1 ^, m5 }7 b; I% e
- if (!thePoints.size()) return;
. l6 C' @: _$ z; a# a& e - / [9 C* t% Y. k9 {
- Spline *theSpline = createStudioSplineThruPoints(thePoints);: z1 P" p7 W1 O
. r/ d+ P, _& @0 N; i$ G& G3 P' |- if (theSpline)
/ ~5 g0 T8 q4 A& P% k+ A& H- X - {
& b( Q0 `# |/ c S" h: t - theSpline->Highlight();6 g% x. Q! ~7 n/ x8 d& S7 R1 [
- uc1601("Studio Spline Created Thru Points", TRUE);
: s7 d3 |: S$ Q b! B- `5 @8 f; f - theSpline->Unhighlight();! g1 w0 T# B( v
- }
0 J0 H7 w, N7 y$ Z - }
3 B$ Z4 g5 Q+ i6 I - <p> </p>
复制代码 % O* N' o) b* s- Y- O0 ^& P: ?: q5 b
|
|