|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线, z: H, L& h# P0 U9 _
- #include <uf_defs.h>; i" @1 h/ q/ }, X
- #include <uf.h>
& I {4 S1 T" s" @" ^. m: R - #include <uf_modl.h> T) X q* J3 m; @# ^
- #include <uf_object_types.h>
1 |1 A+ ]3 H- A. }: Y' {, R - #include <uf_ui.h>( A; f0 ~+ V( l2 u+ o
- #include <uf_modl.h>+ `) F- n$ C3 A0 \# ]
- #include <NXOpen/NXException.hxx>
8 q8 N# V3 i' ?1 O+ f) y - #include <NXOpen/Session.hxx>
7 x/ H9 `' }2 {! Q+ ?8 h$ G4 J - #include <NXOpen/Selection.hxx>
t' r4 \# W! ?: ?% z* I - #include <NXOpen/Builder.hxx>
. W: |% W2 N0 C- N$ c - #include <NXOpen/Features_Feature.hxx>: ~& H' n* s5 M0 e, W; E5 Y' i
- #include <NXOpen/Features_FeatureBuilder.hxx>& v Q; c& C" z" s& W& S
- #include <NXOpen/Features_FeatureCollection.hxx>
! M$ T" h/ u/ F2 b- |9 [- X - #include <NXOpen/Features_GeometricConstraintData.hxx>' H* d- _, N: v& w; H. C) E. R
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>( T8 ^! ]3 x% d' [" `- S
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
. X4 ~, L0 m9 B: ^- @( @! j8 ? - #include <NXOpen/Part.hxx>; f& _0 B0 u; J5 C/ c+ t
- #include <NXOpen/ParTCollection.hxx>
& d/ d1 _2 _8 z5 i! l - #include <NXOpen/Point.hxx>
u4 z( k! @" I+ k - #include <NXOpen/PointCollection.hxx>8 ~% @: K+ q a$ @; N2 M
- #include <NXOpen/NXString.hxx>' p3 g! j* S+ G# k$ {2 k' r. a2 Z2 b
- #include <NXOpen/UI.hxx>1 L0 f1 n; {2 @; O1 L
- #include <NXOpen/Spline.hxx>3 @8 S5 T }3 w1 T
- #include <NXOpen/NXObjectManager.hxx>
- R6 J' P0 o7 I1 {: G+ h% ]- Z, a4 s% |
% j9 d6 C) C% k- using namespace NXOpen;6 y9 d; Q% m1 A; l1 `8 G; I" g" n
- using namespace std;- } k: H) \" n# W9 K6 f
; b! F4 [4 t( s- extern "C" DllExport int ufusr_ask_unload()
3 T6 t1 L0 d2 f% m% G* W - {
) m# R, D. a/ E - return (int)Session::LibraryUnloadOptionImmediately;
7 N( h) w3 l, G1 q - }4 ^' z% g& A! v" `8 h
- $ p5 m, s& T9 z& B$ a
- static vector<Point *> selectPoints(NXString prompt), N- } s9 z- s* I8 b" c
- {
" }1 M; s2 }7 `$ X - UI *ui = UI::GetUI();
1 O9 M7 H8 U/ t! m, \7 g# }, F - Selection *sm = ui->SelectionManager(); ?/ l& s( x5 Q4 J/ n8 G
- std::vector<Selection::MaskTriple> mask(1);
, D9 y X0 b: }1 I# T - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
( ?( h9 {" a& c9 i* w5 I - std::vector<NXObject *> objects;
( {) `. G. s! a& K& q - 7 [$ Y+ @& R' v5 @
- sm->SelectObjects("Select Points", prompt,0 G+ \+ O: N, E* H" {
- Selection::SelectionScopeAnyInAssembly,, d: M) M" k1 u" `( p
- Selection::SelectionActionClearAndEnableSpecific,) [. c: `. \$ e" }0 V2 w
- false, false, mask, objects);
) P& D, m+ I$ b; H) i - ( F4 m7 J7 {. [
- vector<Point *>selPoints(objects.size()); {6 O3 j2 X1 r
- for (unsigned int ii = 0; ii < objects.size(); ii++)0 L8 R9 L+ K! [& o3 e$ d. a
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);# o4 P, Y' D) j0 M
& _- U# k! O( J' L# A# U& X- return selPoints;
5 L) ~! v8 B7 [9 i- ` - }
8 h! s( k& I3 L" D! M- ~* |; Z - 8 N( C$ i% ^' T, R- }3 h
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)* `$ T* p% D+ P, L/ ~) ]' v
- { B' @7 k) \$ h! k& s
- Session *theSession = Session::GetSession();
7 e N/ H5 y7 w7 H; D8 `( F. B8 v - Part *workPart(theSession->Parts()->Work());
3 h7 [8 n# F( \ - : R- G* J0 @" F. N) s9 Y: i
- Session::UndoMarkId markId1;
: ]8 J# D5 o2 O% @, K - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
, {( f( [1 B/ O; v: Y$ ] - "Studio Spline Thru Points");
" U6 t0 b$ o8 Z5 P9 [9 y
' a7 e: A( i+ c @- Features::StudioSpline *nullFeatures_StudioSpline(NULL);% ^4 U1 q! S0 s, }# }
1 w) u5 [! ~8 E) k6 p- Features::StudioSplineBuilder *studioSplineBuilder1;+ X; n! q4 n% ^& n7 R8 [
- studioSplineBuilder1 = workPart->Features()->( m+ P" E, y6 g/ `" K$ y
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
8 x2 [4 M) \$ e$ Q/ u - studioSplineBuilder1->SetAssociative(true);7 J J g$ d1 S
- studioSplineBuilder1->' T7 F( [. O2 O& J& e' }0 ~; s
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
3 D( I! K! X8 ~: L' G+ ]8 J9 L! j - studioSplineBuilder1->, g1 d# P1 y$ J
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);0 P0 ` r3 d' ^% \' o! S6 S
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ H/ b5 N( U0 H& V9 y& W
- studioSplineBuilder1->SetPeriodic(false);
# u3 f, e6 c, b0 {' d; e9 F+ c4 ]5 Q - studioSplineBuilder1->
$ W+ V/ L- C6 H, j8 r+ I2 [" G - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ o3 S, k1 B, b# ]5 h0 }1 Q
- std::vector<double> knots1(0);
. d! i6 w8 J1 y7 u' F - studioSplineBuilder1->SetKnots(knots1);! K V+ r- J: t; t! k7 r/ b
- std::vector<double> parameters1(0);; m8 p* M3 ]3 F
- studioSplineBuilder1->SetParameters(parameters1);
# K2 i$ E$ T0 e2 {' ~9 N - Direction *nullDirection(NULL);
; {. a6 M4 c- i- z* G* E1 p - Scalar *nullScalar(NULL);
! Z1 `0 ]3 {6 z0 F - Offset *nullOffset(NULL);2 t& B v( ~5 ?3 o3 h8 y. P
- ' M& ^. z/ n0 q& S. \
- std::vector<Features::GeometricConstraintData *>$ c. C3 @& ?8 j0 d) J5 `
- geometricConstraintData(thePoints.size());
- [2 r$ b1 |% Q* y& L( f f
: x) _! Z+ p( Q$ R4 n% M- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 g8 w& I: y8 q2 D" A/ `
- {+ X% E! ^: \6 Z
- geometricConstraintData[ii] = studioSplineBuilder1->
% ^$ y: I7 Z3 b$ P3 x, C3 g - ConstraintManager()->CreateGeometricConstraintData();/ g) U# H) o4 A- H4 m, m4 L7 t
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
# I$ P1 p9 b9 M; T# x: U - geometricConstraintData[ii]->SetAutomaticConstraintDirection(. Q1 b7 A X6 L, m
- Features::GeometricConstraintData::ParameterDirectionIso);! E0 C r! k. T2 i, X1 I2 k6 Z" r
- geometricConstraintData[ii]->SetAutomaticConstraintType(
5 u8 i4 d" O# o( w0 Q1 h - Features::GeometricConstraintData::AutoConstraintTypeNone);
$ V" F" r2 n& J. v9 _ - geometricConstraintData[ii]->SetTangentDirection(nullDirection);0 o2 y9 T0 \ @- y
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);- ~+ _2 L& ^* ^
- geometricConstraintData[ii]->SetCurvature(nullOffset);
' D" D' s/ @9 n, K, J* F - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( ?/ j2 ^5 ^( r( _! M
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);7 R _. U% t; m0 \4 e" t! _; o0 T$ k9 w
- }# G. `6 `4 f* x" \8 l
- S6 v3 ?& X, F3 J0 u4 h- studioSplineBuilder1->ConstraintManager()->SetContents(' W+ |9 t, }8 ?" D
- geometricConstraintData);
( ~9 b3 C) i+ l; J5 [
5 \' v4 A# P6 J: s# L7 C- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
5 I) ^1 I: f3 j5 B k, u0 i3 F - Spline *theSpline = studioSplineBuilder1->Curve();- o) S5 |. b9 z- J- ]3 O& V- Y
- 0 p) I4 d; z: C" w
- studioSplineBuilder1->Destroy();
7 T w/ S& P9 @4 k! p1 M
, p# N- ]* Q2 @" \. h) L D" c- return theSpline;
: i/ `1 p- }; S$ u6 U* [& ], z) } - }& [( x' ^- | B% f- Y3 m
7 O. s2 [7 l) V, {' a- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
7 }" K3 Y4 `: B2 b( F - {0 e! `- W* Y3 v
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
6 E; i" W1 v# r& C( N5 u - if (!thePoints.size()) return;& t( F+ s: t u# `+ _
. u" X& Z% S) {- Spline *theSpline = createStudioSplineThruPoints(thePoints);
# w" w6 y l( Z& F a7 q
8 u! r: s! |, l* J% ?$ y- if (theSpline)
; }8 e3 X6 X) t% f' ] - {; x$ g6 ?! `8 b3 @% V) H9 ]3 Q6 }+ u
- theSpline->Highlight();) _/ V+ J: f- |2 g! v4 b4 f
- uc1601("Studio Spline Created Thru Points", TRUE);, {8 ]$ C9 {$ o3 R
- theSpline->Unhighlight();
2 q# t$ v, Y( v0 g - }' t6 C1 B0 _- _" J l4 W
- }
( l) F8 x. }6 z- K' b
复制代码
) C5 P; x' v r- p. C
( C) m4 F# @+ z& [$ q7 I! n6 a' p
|
|