|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线) Z% [/ `' Z+ Q1 |, n9 ^% o" l
- #include <uf_defs.h>6 e4 ?; v$ L2 y5 ~; H# x7 P E7 O
- #include <uf.h>
$ u; i% k. x- ^- Z - #include <uf_modl.h>
& Y1 N9 j# e5 d& \$ X& ]7 o; a, I - #include <uf_object_types.h>
1 k3 g0 o( K- Y I0 s - #include <uf_ui.h>$ g0 d4 Z; k9 R1 I" v! z" u
- #include <uf_modl.h>5 z3 C$ C# x* o3 N' n# I1 F0 {
- #include <NXOpen/NXException.hxx>
# c3 F# Z% J6 O' I O( [3 R2 L - #include <NXOpen/Session.hxx>% u) @4 d0 v6 k9 J( K6 I
- #include <NXOpen/Selection.hxx>
& e* a" {# y* k! X: O3 l - #include <NXOpen/Builder.hxx>
& _3 [6 }( n7 Q( Y - #include <NXOpen/Features_Feature.hxx>" _: q! b! ~, y5 j7 H. d
- #include <NXOpen/Features_FeatureBuilder.hxx>
, F+ Y1 B! F8 r - #include <NXOpen/Features_FeatureCollection.hxx>% Y4 b* s6 |1 Q) M, T4 X
- #include <NXOpen/Features_GeometricConstraintData.hxx>5 @0 w, p. r; M
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
' A r$ _3 }% }, t% O - #include <NXOpen/Features_StudioSplineBuilder.hxx>
4 X' U0 x- b }' n0 u0 q - #include <NXOpen/Part.hxx>
0 N* m3 s/ E5 Z( Q1 ` - #include <NXOpen/ParTCollection.hxx>
; D6 {. V! i+ Y# h% y - #include <NXOpen/Point.hxx>
, i( m) Q* W _( |0 ?6 t; i - #include <NXOpen/PointCollection.hxx>
" g5 h6 B1 \3 `/ t - #include <NXOpen/NXString.hxx>; F: G' p: l6 k3 I& w: k
- #include <NXOpen/UI.hxx>
U! J9 J* A* e8 Z* u2 _ - #include <NXOpen/Spline.hxx>
) T: }" ]; T; T) a - #include <NXOpen/NXObjectManager.hxx>' t) R' w( k7 K7 |# A
- & Y" r3 T: b# X) v! t. _; J1 S
- using namespace NXOpen;
1 D5 |% d9 C5 U" e: R - using namespace std;3 W, n: K9 }/ \& z$ d& l$ K
: W6 J0 [- n% ]& l% j: K% _7 r- extern "C" DllExport int ufusr_ask_unload()
4 O4 H( i- D; |, \, z - {0 N( N, n- R2 c" g3 d8 P
- return (int)Session::LibraryUnloadOptionImmediately;9 a8 S! U6 [8 C
- }! d+ U# S. f& p8 A2 \
?. Y, H. l; X. j9 W- static vector<Point *> selectPoints(NXString prompt)& L/ `- `! x5 `* }
- {
0 _- F) N* }8 u) Y: B) R7 o4 k. ], } - UI *ui = UI::GetUI();. `% S1 e) f2 |
- Selection *sm = ui->SelectionManager();
& y; W# q0 i* F O - std::vector<Selection::MaskTriple> mask(1);
5 k. H8 s& f* a" c: ` - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
! r2 E$ T: `5 Y! ~) S - std::vector<NXObject *> objects;( w# _# J2 p& u) @2 ~, k
- + y8 Z1 ?/ O& {! |2 z) u
- sm->SelectObjects("Select Points", prompt,/ h( h5 ~' V! U
- Selection::SelectionScopeAnyInAssembly, A0 q6 J6 E# S" `' l& T9 x
- Selection::SelectionActionClearAndEnableSpecific,3 O6 W% y# D, t3 T' I1 b3 v( \+ \
- false, false, mask, objects);9 w: ^; Q& p4 y
- 8 \) Z- a8 J v6 v) R4 y
- vector<Point *>selPoints(objects.size());! H: G; ^6 a4 N: g* W6 Q" p
- for (unsigned int ii = 0; ii < objects.size(); ii++)
$ E% a& Z2 m' I - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
$ N$ n. Q' A+ Z) f2 a+ D! C - . u k6 ?1 \+ o% _( L- e' h2 E2 h
- return selPoints;
# x6 m" [- U- ~8 e8 [& L3 x9 x - }, H @) e5 U& A; X+ i: q! v
5 S# |& p, ]- \: E5 N' z' F. P4 C- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)% B! F, Z a& `! I2 Z. N1 a
- {7 a2 L3 u& m( W' H" s# R
- Session *theSession = Session::GetSession();7 F4 _; G6 [$ t/ f' J
- Part *workPart(theSession->Parts()->Work());
. [2 I9 a2 i/ Q c- P4 b8 X! Y0 w. K( f
' D7 ~: H4 G$ [6 b- Session::UndoMarkId markId1;/ _" R+ D: N2 B/ i8 {. i4 s# G
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
# X e! o+ @+ j& X - "Studio Spline Thru Points");' s( a8 M9 v, t, n9 x
8 K0 _2 @6 R; H9 H: b; ]5 z# {- Features::StudioSpline *nullFeatures_StudioSpline(NULL);, ]7 k5 c" S1 H2 B9 h& c
. i7 [: g! a8 D2 C" B8 ^0 R- Features::StudioSplineBuilder *studioSplineBuilder1;- Z) J8 ?8 A3 d! Z9 I7 h: z
- studioSplineBuilder1 = workPart->Features()->$ q% G: m# n# J( }
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);% H$ ]1 j) U5 D5 E
- studioSplineBuilder1->SetAssociative(true);
, f0 l Z1 b/ _( I4 |% e& H - studioSplineBuilder1->
9 R& p; O& e1 ^/ c: `: g3 E - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);* ]) K. |7 Q+ M% N' {" p. ?7 M
- studioSplineBuilder1->
: y* ?# Q4 t) {( _ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
7 Z- U$ _3 j+ W1 R! ?$ w - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
7 W9 }$ U" }: _* g$ } b, @+ } - studioSplineBuilder1->SetPeriodic(false);# G; k t$ y4 j- C
- studioSplineBuilder1->
; L" g! z7 R \" E; { - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ m5 C1 p5 m% I4 g' N2 M9 ]7 h2 s1 N
- std::vector<double> knots1(0);
! q$ A" B8 L+ G7 Y; n2 @) P, v - studioSplineBuilder1->SetKnots(knots1);
. ]0 w- R- f# L: q - std::vector<double> parameters1(0); S7 ~- y) k/ Y/ U2 Y, c8 C
- studioSplineBuilder1->SetParameters(parameters1);
: S3 A% J) T# Z8 q - Direction *nullDirection(NULL);. }: [8 I0 W+ I4 n6 J; A
- Scalar *nullScalar(NULL);+ h9 x' i ]" V9 q+ k
- Offset *nullOffset(NULL);" b/ i4 d: L* r$ m }) G s
' Q, c6 m' S3 \5 h- std::vector<Features::GeometricConstraintData *>3 g/ S3 P7 K/ W6 n; ?
- geometricConstraintData(thePoints.size());$ \' L8 v. N2 r1 F; Q/ p/ n& s; O
0 f: w- z9 y) a- w# P, p1 k6 n% l- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
: Y2 f1 [1 i5 u! H f - {
3 x9 ]( F/ ]% x - geometricConstraintData[ii] = studioSplineBuilder1->
1 G" r/ V& i8 z - ConstraintManager()->CreateGeometricConstraintData();
, ~4 O- e- q# V% b; G4 B, B - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
4 _$ B/ s& M5 t" P6 { `! M* L - geometricConstraintData[ii]->SetAutomaticConstraintDirection(9 W! c) V( D5 s; s8 h. k9 X
- Features::GeometricConstraintData::ParameterDirectionIso);
# g0 C8 w. j( @ k. S - geometricConstraintData[ii]->SetAutomaticConstraintType(0 B- U/ J, k6 t* J
- Features::GeometricConstraintData::AutoConstraintTypeNone);3 {& k) K& s+ b# u1 N4 ^
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);2 a, X! O# t3 D8 X1 j' y3 @3 y
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);3 x( t8 ?) K3 S, M" I5 f) L# m
- geometricConstraintData[ii]->SetCurvature(nullOffset);) c) E" r3 O" _6 S
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
% m' H' g0 p h6 A - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);, c' ?5 k/ Y& {, t2 m5 g" A! N
- }4 Q! [! D6 o8 O* B% U1 G @
- 4 b- k0 _% N& M5 h
- studioSplineBuilder1->ConstraintManager()->SetContents(
2 |: E; k4 U V$ }) U1 p$ _ - geometricConstraintData);
|, i$ t, N8 n; `+ |5 O: X6 B - . |4 C* F; T; e+ j" J
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
. Y' V4 q% r# R# [; ?# x - Spline *theSpline = studioSplineBuilder1->Curve();
9 [% ?' }" m9 S8 C
6 v2 w( g. y1 G4 h- studioSplineBuilder1->Destroy();
) c& f3 U4 Z5 a1 ^0 q9 M, D$ A - 2 r+ e1 J) \' v/ p2 [
- return theSpline;0 d( W+ S2 ~# Z6 j( T% n
- }- C$ Z3 p8 e1 V2 n K
- 9 o* K( N. {+ K; t/ A Z
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
; i( j# U3 m0 | - {0 J6 H$ O& U! w* T2 t9 H
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");$ M$ F; ]7 W/ A; _3 c- H
- if (!thePoints.size()) return;! }; ?+ K S2 i: S! _% E1 }
2 J: G! U& C( ^% g- Spline *theSpline = createStudioSplineThruPoints(thePoints);
0 ?: }5 J' B+ t3 {5 s2 P" E: ~ - ( H, I# X5 y+ r; |
- if (theSpline)
$ G* w% q- [ e3 G7 T* ~$ h. B. g - {) F5 j0 s% _) p
- theSpline->Highlight();
} f' J( n' g, p3 x4 e* r - uc1601("Studio Spline Created Thru Points", TRUE);( R4 U2 `7 p Z" j" f" H
- theSpline->Unhighlight();1 F2 R4 m+ x9 A+ _6 l
- }. L) Y" i" @: Y7 `4 {8 j
- }
L) y* T6 y) q5 h" C# Z8 E
复制代码 # U1 i% c# a8 ^# R! T& g
& P$ \, u b8 O! M- Q
4 z6 q* l3 q) b0 J5 D
|
|