|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
" j& H& `- j+ Y( k- #include <uf_defs.h>
" n9 {4 n" d( s& z9 Q. p - #include <uf.h>: ^# n4 R' y6 s4 C" |- ^
- #include <uf_modl.h>7 K& Q3 i# l: ~' ~' K5 s9 ^
- #include <uf_object_types.h>5 E3 [) {, D* `- l- l0 u( ]& @; i0 X
- #include <uf_ui.h>
) D! M/ k. d B0 a - #include <uf_modl.h>' m9 L* i( ]( N ]* f- L
- #include <NXOpen/NXException.hxx>0 X4 J2 ?: v3 F+ G2 s. h
- #include <NXOpen/Session.hxx>4 `% M+ ` D; T8 W4 N! W, Z
- #include <NXOpen/Selection.hxx>, ~9 M1 Q7 ]. r4 v' Q: M
- #include <NXOpen/Builder.hxx>
5 l( K- q$ q& V# c7 Y( x - #include <NXOpen/Features_Feature.hxx>4 k6 n4 ~0 F( r0 a& _( K9 s, y0 n
- #include <NXOpen/Features_FeatureBuilder.hxx>1 Q- H2 A0 m; S4 Z
- #include <NXOpen/Features_FeatureCollection.hxx>
0 q7 q: \6 z: K/ i# ^ - #include <NXOpen/Features_GeometricConstraintData.hxx>
: _5 z! f7 i4 i3 ]6 }; u2 {4 _ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) L9 k1 ~; J; y* _& p
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
" s9 ^( y8 K1 `& p, ] - #include <NXOpen/Part.hxx>& F6 u7 w# ^ R" P+ G
- #include <NXOpen/ParTCollection.hxx>
; |) Z i0 d" g- k, O8 [ - #include <NXOpen/Point.hxx>; Z! }/ E- {* V. a2 L7 j
- #include <NXOpen/PointCollection.hxx>8 m" h e. P. a5 h' e: S% [
- #include <NXOpen/NXString.hxx>
4 |) v& e9 B. E% K( K - #include <NXOpen/UI.hxx>
* d) V' |/ {3 T! B" V& b - #include <NXOpen/Spline.hxx>
' W& R+ {6 F' M0 i - #include <NXOpen/NXObjectManager.hxx>
; J; R- d& Q" v( I - * `( [6 m/ E( D
- using namespace NXOpen;
6 b4 y0 Y5 R x - using namespace std;& m8 Z/ k' M h: q
- 6 B% M# S% ?) g$ _% k+ V2 j" M
- extern "C" DllExport int ufusr_ask_unload()
0 H) M( `3 B; [, A. M/ \ - {
1 I3 L$ }/ N. B v( y4 B8 R - return (int)Session::LibraryUnloadOptionImmediately;0 }* |% l4 V' T* Z* B& u
- }7 H' w% U: ]. v
- ( F, H8 w: H$ Q( t0 I7 }
- static vector<Point *> selectPoints(NXString prompt)
V1 s4 D9 ]4 F9 \ - {9 n1 n5 W" e4 j$ f
- UI *ui = UI::GetUI();
9 K# ]1 }$ H2 h9 \4 E- z - Selection *sm = ui->SelectionManager();4 K/ ~! l9 _$ V: ?
- std::vector<Selection::MaskTriple> mask(1);, n& `2 D3 y1 w' `! w2 k7 n0 F2 r+ v
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);7 P9 Z& r6 _9 ^
- std::vector<NXObject *> objects;
5 N# f* K7 j- B7 [/ I. R- @. J
5 J3 I. \1 i9 R/ t" ~- sm->SelectObjects("Select Points", prompt,5 }# y8 S! B: j
- Selection::SelectionScopeAnyInAssembly,
, c% Z1 P# J: A9 @! K8 _ - Selection::SelectionActionClearAndEnableSpecific,. `( ?0 p3 A5 L& E0 N2 F7 v9 g& a1 p
- false, false, mask, objects);
$ m$ |1 X. s3 u2 P8 Q
" v, D- d7 X: n- z0 d0 Q- vector<Point *>selPoints(objects.size());
, Z9 W* D8 Y6 q* ~; ?1 ?8 S7 D7 D - for (unsigned int ii = 0; ii < objects.size(); ii++)
3 ]' j- Y$ O' d7 Z: `* J - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);8 a0 L: `( {1 s) m. }* X1 g
- + z! Y: r% t5 p: r. ]# r
- return selPoints;
- B* y5 v1 T& B8 B! u( o9 T - }0 i/ I8 ~- r, x, P! x9 q
+ e3 g A% N+ ?4 r- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
3 n t2 ]5 K: O& B8 k6 u0 S - {
( B' L# a$ B- ~5 Y# M9 v - Session *theSession = Session::GetSession();
& U) f: p5 v* e8 Z! a+ Q; a8 W1 r - Part *workPart(theSession->Parts()->Work());
) J( n5 B. p" \, d( _ - # V- ~* A/ U1 I) n; [0 W! z" o
- Session::UndoMarkId markId1;
, x+ \8 i4 k( A% |+ A) R - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
" F* `) s# A' {( E4 X - "Studio Spline Thru Points");
7 P5 J9 Q9 |( d& L" [) r
/ p+ ^( h$ W! [* ]: D- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
1 u# a, |) c' I0 d" @6 a$ |
4 B6 C+ I! g5 ^. C. O+ x- Features::StudioSplineBuilder *studioSplineBuilder1;
% Y J) u$ S8 W/ l; l5 P# Y3 h - studioSplineBuilder1 = workPart->Features()->
. J. C7 Z/ I* `( ?5 _6 | - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
& Y. B# U' b7 p( W% X) w - studioSplineBuilder1->SetAssociative(true);
% D: d5 Y2 A7 F0 Z - studioSplineBuilder1->: v! ]) ^ Z& p# E4 i H& p( A
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);7 A: V0 K, ]0 [! O" E. ]
- studioSplineBuilder1->3 |( I' O: |- k2 z: F5 O
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);5 [1 K. G3 K+ R
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
$ m6 ~4 y" L8 ^+ [7 d - studioSplineBuilder1->SetPeriodic(false);
: [( |+ \( m' f& M8 R) c3 ` - studioSplineBuilder1->
~$ Z7 E6 ?1 m$ @/ \ - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
/ p, b* d9 A1 U1 c - std::vector<double> knots1(0);1 m3 D' U' Z8 o/ x' v
- studioSplineBuilder1->SetKnots(knots1);
# V, h8 h) Y. {2 F - std::vector<double> parameters1(0);5 H" W. s1 g" |5 s; M4 g! R
- studioSplineBuilder1->SetParameters(parameters1);
' \; Y" u( {6 `, B2 X - Direction *nullDirection(NULL);, r' s6 ]7 }7 o9 B4 K
- Scalar *nullScalar(NULL);
m2 C; L6 ^8 s+ ~$ N - Offset *nullOffset(NULL);
9 t' f3 l$ N" i& x' k) N5 T - # ?$ b$ g9 J2 O- Q3 {8 C) x- P" m |
- std::vector<Features::GeometricConstraintData *>; l/ d4 T( V5 Y9 y- L7 K
- geometricConstraintData(thePoints.size());% l$ V' l; V! @
- 8 }; H2 Y2 ~6 |' V' w g
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
4 u# g" z) [; W9 _ - {
/ W4 J- p' Z- k* A+ X - geometricConstraintData[ii] = studioSplineBuilder1->5 j$ F6 Y# F6 W/ k
- ConstraintManager()->CreateGeometricConstraintData();
" X# }* U' b4 i3 t( ?* W - geometricConstraintData[ii]->SetPoint(thePoints[ii]);6 u A7 d% r( @7 N. v. l
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
l& Q l$ j( F# Z - Features::GeometricConstraintData::ParameterDirectionIso);, e: y7 X n, H. C. N" w
- geometricConstraintData[ii]->SetAutomaticConstraintType(
& F; C/ n. O8 P( l2 M - Features::GeometricConstraintData::AutoConstraintTypeNone);1 V% P% v/ m o: E
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);% z. G% V1 Y' n1 i
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
( L8 a7 M0 @- a: a& d$ E - geometricConstraintData[ii]->SetCurvature(nullOffset);
% }3 C" U1 o- X/ B: N( z& m- _ - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 P$ B8 c' w5 t z
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
8 s: I* c# _! ~# u2 g$ l3 f5 f& G& p1 I1 H - }* l* z! ^/ D' s1 K' z4 X+ j: o
( m; @- M& x9 ^: g- studioSplineBuilder1->ConstraintManager()->SetContents(! G. S* q# V9 ~0 S
- geometricConstraintData);* s, B% l+ O K% w* _3 g$ Z
- * g& `. `. @2 a% z1 |5 U" `) F, X
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
# \# W* a) E( O2 ]! C9 V. v5 P - Spline *theSpline = studioSplineBuilder1->Curve();
' i0 ~8 C$ D+ {# |$ m, ]9 R
; J# z6 Y' `; u- p% C- studioSplineBuilder1->Destroy();$ q. h r w/ @9 ~( i1 `
- 9 ~# g% x1 C) }
- return theSpline;! F: P5 L" q4 _" \# @6 Z) K
- }
: O( h+ U8 p& P
" V6 w+ C! j& A, ?" K B f- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
. T( h2 A; Q" u& T - {/ P- W+ u9 ~# W+ Y4 v3 v3 I9 `5 p3 |" s
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");- E, @7 _' s1 Y) N B
- if (!thePoints.size()) return;
( W6 W7 ]8 Y7 i8 e6 i! e% ]" }+ a
" ?( ^6 m" }4 x! @+ X& h5 n! K0 V4 _/ K- Spline *theSpline = createStudioSplineThruPoints(thePoints);8 z6 Y8 l6 e5 G. T5 _
- : A1 }3 c1 K0 ~& P4 H0 M" i) ^
- if (theSpline)
( {4 r4 D3 p+ Z" ~& n) S - {
# Y3 {$ ~6 E4 z9 \8 a9 o - theSpline->Highlight();
6 M/ v6 ]* G" A' i4 D - uc1601("Studio Spline Created Thru Points", TRUE);+ |$ J ^( `5 z' S+ y5 l
- theSpline->Unhighlight();* p- C3 D5 Q# t! a7 w+ k5 D
- }; D' n' c8 R7 Y. ~* i
- }
5 Y2 m, N+ N% [# U6 ~$ H8 H8 N
复制代码 3 T! _/ N' w2 C& d
$ L& U3 h. [8 k
+ h6 x! n' q& m k) Q |
|