|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
/ S# j1 B: ? P8 J: \6 a- #include <uf_defs.h>
, W) O; b( l: f* n2 v; l - #include <uf.h>
, H+ n/ z; U. Y& m; Y2 d - #include <uf_modl.h>
) R& x% v( V. o/ k - #include <uf_object_types.h>( Q5 q i7 {# s1 z( D& c( V9 b
- #include <uf_ui.h>: ]& v! c7 a5 S" J( `7 v4 X/ \- K: j
- #include <uf_modl.h>
0 K6 o4 E5 M" g1 h7 Y( |7 p - #include <NXOpen/NXException.hxx>, ~2 Z: O$ {2 ?, \. K# Q1 p' R
- #include <NXOpen/Session.hxx>
& p4 `) Y0 f; k- R2 H2 {9 l* N6 G - #include <NXOpen/Selection.hxx>
5 D: }# C& L1 U! r4 }: u7 ? - #include <NXOpen/Builder.hxx>) z* u) {& X" V! S8 I/ _ @ ]- [
- #include <NXOpen/Features_Feature.hxx>4 W7 a( F# i5 }. M e b8 M' i
- #include <NXOpen/Features_FeatureBuilder.hxx># k. ]1 L% `- d
- #include <NXOpen/Features_FeatureCollection.hxx> X" }+ r$ [5 Z- I% e* E+ }; Z
- #include <NXOpen/Features_GeometricConstraintData.hxx>) t8 o8 c; O/ p6 i5 p
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
* R% Q/ U4 D, M - #include <NXOpen/Features_StudioSplineBuilder.hxx>8 C W' m) |0 k7 n/ ^) W) I' _
- #include <NXOpen/Part.hxx>' s8 H( f; S5 R$ }! C
- #include <NXOpen/ParTCollection.hxx>* X5 g- V* \& v6 c4 S& [
- #include <NXOpen/Point.hxx>( W2 Z! @0 W; M" y( ?8 r8 h4 |" h
- #include <NXOpen/PointCollection.hxx>6 |2 `+ U, V* T9 i, z2 H6 f+ r
- #include <NXOpen/NXString.hxx>
3 a: {- G) ]+ v1 x' Y - #include <NXOpen/UI.hxx>
* M, O! g: W+ ?7 I8 R- Q) n - #include <NXOpen/Spline.hxx>
) T4 }8 A" L+ u0 |/ D8 S - #include <NXOpen/NXObjectManager.hxx>
# ]& R8 A5 o- L0 b8 z9 `* w
, \. r/ \+ Q j3 o! x9 B2 F* T- using namespace NXOpen;2 E/ {' f* V6 L- F
- using namespace std;
& i7 ^; B2 ~; ^
3 n. a* n1 t9 h( S0 e- extern "C" DllExport int ufusr_ask_unload()8 J8 {8 g+ J% n- E% |$ Y$ r
- {4 O s0 j+ Q) p3 z# A. M
- return (int)Session::LibraryUnloadOptionImmediately;
x7 ]! q4 j6 a4 _$ F& r - }: w) Y- _' e. d& F$ W/ T2 g: Z
- " f* O3 l+ D' z7 X7 |9 G6 Q" }
- static vector<Point *> selectPoints(NXString prompt)# m- _( ~) c9 W8 k" B
- {- B% x# K& m( W0 e
- UI *ui = UI::GetUI();4 y7 e! m: X$ d% D- I
- Selection *sm = ui->SelectionManager();
) \" o* g4 b% H8 {0 D - std::vector<Selection::MaskTriple> mask(1);
$ ]! i4 m( Y0 Q - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);' L5 k4 U M; A
- std::vector<NXObject *> objects;
* W1 G7 l+ ?9 X5 G5 i$ G5 ?
0 j( J6 l3 g5 k% ?# U# _# I- sm->SelectObjects("Select Points", prompt,* e# k* [+ @! _+ l7 h. u* j
- Selection::SelectionScopeAnyInAssembly,( y! l9 n: ^! F2 j( v6 Y* `
- Selection::SelectionActionClearAndEnableSpecific,9 J0 f% a2 n" c
- false, false, mask, objects);
$ r/ w( P: |* v9 H( k9 b
! L1 L( Y, r3 w6 O4 N! v- vector<Point *>selPoints(objects.size());
, A4 D2 Z6 Y8 {1 B' A. t - for (unsigned int ii = 0; ii < objects.size(); ii++)
/ A. @/ N) `* o) X - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
2 p( P7 Q+ o& K; L1 } - " i8 b+ L% {3 I; G: {
- return selPoints;
6 {9 a" Z( {0 z' Z - }
( }( S# V$ f9 g" R4 c
6 m& h Z B5 _; W- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
( Q" i' c0 p# V: K. a$ q - {
+ M7 L6 r% D5 W, g - Session *theSession = Session::GetSession();/ k; _" B5 s+ ~; I& p
- Part *workPart(theSession->Parts()->Work());
4 }% o# p* h( [1 J - 2 t! ]" B8 ~/ b# {6 F
- Session::UndoMarkId markId1;, j& I, s% E( U3 }9 m
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
+ Y. M3 F' c2 T9 U R - "Studio Spline Thru Points");# \' M |8 ]* g4 }0 r* |, F$ T) v
- 8 z4 q* M5 j, }
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);" e7 K2 d. ?$ h; V2 e) p/ L9 \% o
# F( w' C% ?: }- I2 P& ^0 g- Features::StudioSplineBuilder *studioSplineBuilder1;
( p% W$ T; Y4 r# f2 J9 q - studioSplineBuilder1 = workPart->Features()->4 l/ u5 V H! V( v1 F
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
; X/ @; n, `2 p1 ]/ Y - studioSplineBuilder1->SetAssociative(true);( A! @9 o6 c1 t
- studioSplineBuilder1->
; r& V) h" D7 A* u5 s. q' }* I - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);3 d& L: Q7 r0 S n
- studioSplineBuilder1->/ i S! s+ j, w+ @: _3 O
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);* `: h; y& G/ b5 ? ^2 T
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
0 ?: d/ n+ O8 a4 t0 L4 `; b. ? - studioSplineBuilder1->SetPeriodic(false);/ b; \$ V) ~* E5 ]( c* T4 o" d7 u
- studioSplineBuilder1->
; v- A) i; I! J- p! W - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
0 g9 p. k/ g7 Z! e% n - std::vector<double> knots1(0);
( V2 H/ T6 b3 Q. |0 M8 r2 e6 I - studioSplineBuilder1->SetKnots(knots1);
, ]9 j9 c7 N+ ~4 F& E3 y - std::vector<double> parameters1(0);* b3 E* E6 | ]
- studioSplineBuilder1->SetParameters(parameters1);
9 t; ^5 ~. ~; l- R- q - Direction *nullDirection(NULL);! R4 q/ _7 d: G. {- K
- Scalar *nullScalar(NULL);5 }0 l2 Y ]! t A7 g: t
- Offset *nullOffset(NULL);
0 ?, l0 n/ K. [4 L7 u! x* k+ S/ z
- ~/ i& x% e! i! |. v* R) I; [: b" y- std::vector<Features::GeometricConstraintData *>
. u M% T! c/ g9 H3 k1 A - geometricConstraintData(thePoints.size());
' r. n5 T9 T4 x' `5 V - 9 x0 H0 y! O" |
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
9 @# w& O, p6 z - {9 t r1 Q; V$ M8 a) z
- geometricConstraintData[ii] = studioSplineBuilder1-># ^: H Q8 k3 p% I/ X
- ConstraintManager()->CreateGeometricConstraintData();3 u' {* A) n6 S$ T/ e
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);7 Y" Z- f- ^% s
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(# S& j# [- W1 c6 l: {; H
- Features::GeometricConstraintData::ParameterDirectionIso);1 E7 l: j* t/ a5 _! D' S- ]
- geometricConstraintData[ii]->SetAutomaticConstraintType(
: T3 D0 h9 }5 w& Z1 h; K: X - Features::GeometricConstraintData::AutoConstraintTypeNone);
2 N$ `: E( e4 `) D3 M( p) ^+ q - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
/ g6 i; M- k% A# V2 h- Z9 ] - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
0 m, Z3 ~" e. q. N5 S6 y - geometricConstraintData[ii]->SetCurvature(nullOffset);
" b9 @" }% @0 c - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);6 F, @/ s% p3 e" j L9 s3 g
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 Z5 m$ c9 s" Z6 [' y5 ?0 ^, T' n
- }
' B7 f# }3 j" D" ]" \# Y - w) B1 I- j6 T! y, \: K8 `
- studioSplineBuilder1->ConstraintManager()->SetContents(
" ?5 v S" }# m! D9 J - geometricConstraintData);: }1 n" g& |3 ]1 @; z) Q
* t/ b% _" J+ j4 a$ {" I- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
5 b' ?" z g9 N2 p - Spline *theSpline = studioSplineBuilder1->Curve();. a1 z# t# D( i8 U! A* b
/ f# a4 u, q; G% t- studioSplineBuilder1->Destroy();" g0 B+ R# x7 b2 L
- , e' E# [7 C; U9 L5 T; g/ _
- return theSpline;
( |0 O# O P) ]5 H0 @ - }) q* T: e4 B+ l, e( G' l
- 8 e$ l4 d# e1 c: o/ X9 A8 E
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)( O6 Q n4 \. G; e
- {
1 [9 s$ i7 u2 P4 [! O0 w# |" o* P - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
- p1 _# I* J7 l8 b$ v5 K - if (!thePoints.size()) return;
2 H2 |' O+ p1 N" t l7 F
1 Z# u% U3 {" V( N% n- F- Spline *theSpline = createStudioSplineThruPoints(thePoints);4 v8 X1 D+ u, P2 E! E
$ P, ]2 }/ O% I- if (theSpline)
8 K9 E3 \7 E: R+ J0 D) q' ? - {
: `1 F! ~/ R( C* i' { - theSpline->Highlight();- G* i$ J/ X8 t8 B5 \
- uc1601("Studio Spline Created Thru Points", TRUE);3 C7 C* I- Y9 y9 E0 B1 a1 j m
- theSpline->Unhighlight();
. z* W+ o$ ~; E( Y0 `* O - }9 }5 j% Y0 |* E! Y, Z7 b2 t, s1 W
- }7 G4 I1 U% S0 I% W# Q' p6 I
复制代码
, N9 V2 k( _$ a+ g9 g. q& b! ]' i t# }9 m+ a+ x& G
- X% ^! |+ l, Z- _0 l |
|