|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线: w. s) [, p$ z4 k8 @2 J4 k& g2 |
- #include <uf_defs.h>, {+ _6 m! F! W5 \7 i3 q
- #include <uf.h>
9 s7 [" o; N; j- c% w6 L - #include <uf_modl.h>
4 z+ o f4 L4 O9 d2 n' W6 j1 _1 @ - #include <uf_object_types.h>9 G& ^% b, G+ A [/ d$ _
- #include <uf_ui.h>: X0 o+ g/ N% S2 B( `) x; \
- #include <uf_modl.h>
, J+ O8 U& Y7 i7 f# i1 Y7 I - #include <NXOpen/NXException.hxx>: V& _ G8 B) S8 \/ |. G# H9 i' C
- #include <NXOpen/Session.hxx>6 G. [/ v9 A2 Q: O2 o! ]" k3 l6 e+ |2 G
- #include <NXOpen/Selection.hxx>/ N: ]7 y0 _: }( y! ?: Z
- #include <NXOpen/Builder.hxx>3 T6 g" E& n2 L ^: e7 j% x
- #include <NXOpen/Features_Feature.hxx>. R" o4 k/ K3 j- W
- #include <NXOpen/Features_FeatureBuilder.hxx>
0 ^% o* c9 @0 |: ? - #include <NXOpen/Features_FeatureCollection.hxx>( }; r6 i' J! b+ m# F) \* H
- #include <NXOpen/Features_GeometricConstraintData.hxx>
! s8 Q+ C. n8 } - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>: T) v/ t6 a2 P- ^
- #include <NXOpen/Features_StudioSplineBuilder.hxx>9 N$ b w7 w2 X3 p
- #include <NXOpen/Part.hxx>
# |* ^ S0 C1 ^- E - #include <NXOpen/ParTCollection.hxx>. Z& [7 Q% g. g- u$ H! `5 O/ U( t
- #include <NXOpen/Point.hxx>
* z( {7 C: E, a - #include <NXOpen/PointCollection.hxx>" i/ N& ?- z, D9 n" J" N* h
- #include <NXOpen/NXString.hxx>0 i5 G$ a0 v N' `% |( [
- #include <NXOpen/UI.hxx>, B% o( P) ]. x" T; g# {* ^7 J
- #include <NXOpen/Spline.hxx>4 t+ k9 M- `2 f+ X3 V. a1 {8 c8 ^
- #include <NXOpen/NXObjectManager.hxx>
& |# @) D: S0 I. o - # j8 b+ N* [; A S
- using namespace NXOpen;3 i7 [, [ R, I2 F0 g& {
- using namespace std;% v9 F( V+ f; Y
1 [1 y( J# g0 W3 \3 M- extern "C" DllExport int ufusr_ask_unload()
9 m! l) j2 M. }% l- I& v: l - {
+ F& U! g9 ?& c- t$ i. m' s5 | - return (int)Session::LibraryUnloadOptionImmediately;) m; Z) f; k. \9 o
- }
0 v- \' V; |$ N. \5 ]
, O& Z0 K: s5 y' V- static vector<Point *> selectPoints(NXString prompt)# \, N. _, r/ C0 [
- {6 V% R! c; A% A1 J; a4 z
- UI *ui = UI::GetUI();' m# g% k% _; g% v
- Selection *sm = ui->SelectionManager();8 P: O" x( y. R8 W" @6 @* m2 c
- std::vector<Selection::MaskTriple> mask(1);% @0 r W5 {8 o. H3 n
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);' j# _( Q/ c- Q2 T* a3 z
- std::vector<NXObject *> objects;
& A; \8 V& Y0 f$ P0 N* ] - 6 _$ ?; J# }: B( i- [% ^: e
- sm->SelectObjects("Select Points", prompt,: r" p) o; C' C- Y+ Y
- Selection::SelectionScopeAnyInAssembly,# x9 s# `8 G3 q. C+ {0 q
- Selection::SelectionActionClearAndEnableSpecific,
8 i' s8 C# G' A; j$ X* z, l3 V& ` - false, false, mask, objects);9 l* N+ |3 ?* W; m
- . g6 {6 Q2 |2 a2 a
- vector<Point *>selPoints(objects.size());4 O+ L8 s# F" O& v. y+ j" ^7 x+ i
- for (unsigned int ii = 0; ii < objects.size(); ii++)
! x1 e5 N: B% L: V" g/ P0 m% U - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
5 ^ Y( p; B* ]
! y6 ^4 }. U; w$ Q3 H- return selPoints;
! T+ R- i4 Z6 F) Q$ b( M - }
0 ~' i$ ^- T8 P- Q4 `( ]: | - ! R: P5 p0 L/ H# _, G) {
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
+ L! o; w% t* U' R* c1 F - {4 l5 Q9 s. h& ~* n
- Session *theSession = Session::GetSession();& F( g) x1 h' x7 h
- Part *workPart(theSession->Parts()->Work());
. r1 r% F) s% Y3 ]2 n6 D
- @" s+ M$ c% ]3 u4 k- Session::UndoMarkId markId1;) x+ z# y+ D( M
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& t( V& j/ D" [& g6 `, c
- "Studio Spline Thru Points");
! t9 G# h- J+ E. j& E - 0 K+ [5 q1 g6 x8 W0 d) x V
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
, w3 O# Q3 [3 M$ r0 X* \9 x* B - ( z, S4 A3 `6 G& L: W3 o
- Features::StudioSplineBuilder *studioSplineBuilder1;
( M& E5 d: S8 ?4 a4 \ - studioSplineBuilder1 = workPart->Features()->0 `$ Y0 c/ x9 u, L$ V
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
2 N: [# W4 F# ?( O; o - studioSplineBuilder1->SetAssociative(true);
; e9 i0 l4 {+ Z" i% x" n8 B; J/ n - studioSplineBuilder1->
2 R2 P7 m; r: K! e: L/ { - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
# Y' b* j# D* ]; B7 K - studioSplineBuilder1->5 i" }& y$ _6 T1 J% s* h m7 u( G
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
- i* G1 a4 q j - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);7 P& M1 w4 I' ^% u: F9 ?+ [8 Q4 H
- studioSplineBuilder1->SetPeriodic(false);: L3 D3 `4 N: A! f& H" [0 z" ^0 n
- studioSplineBuilder1->1 ?* |* t& b8 D( }7 @6 J m
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
3 _; m1 S4 U4 O" v3 ]) j - std::vector<double> knots1(0);
+ T& X5 r$ o/ _' h5 R$ \/ }) U - studioSplineBuilder1->SetKnots(knots1);5 t, i: v8 @3 g9 t, [# u7 v' y
- std::vector<double> parameters1(0);" B; j+ K; e9 L3 J
- studioSplineBuilder1->SetParameters(parameters1);
" C) w" ~6 m. g1 P! J - Direction *nullDirection(NULL);
" e) y5 ~; ^% d! i - Scalar *nullScalar(NULL);, R) J/ G$ O3 h) l$ ^# M% V; x' \
- Offset *nullOffset(NULL);, W. x3 V6 c6 {4 v5 y2 I
0 R3 M6 q h, t( s# u- std::vector<Features::GeometricConstraintData *># Z$ P; H t D
- geometricConstraintData(thePoints.size());
/ X, Q' u$ u: v& _7 ?' o/ r
; Z: d$ O& ^# W- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
/ c& ?& S+ V$ j. \& {1 n" r - {
- L3 q o+ R9 U- C - geometricConstraintData[ii] = studioSplineBuilder1->
" \; U' g# Q2 P: H0 n - ConstraintManager()->CreateGeometricConstraintData();
/ M+ M& b- `- c - geometricConstraintData[ii]->SetPoint(thePoints[ii]);( [' I' I' k* F- W# U! x
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(' g3 W' p0 M: z v L
- Features::GeometricConstraintData::ParameterDirectionIso);
& I$ a4 q8 B+ R0 w: B; l: F8 V4 b - geometricConstraintData[ii]->SetAutomaticConstraintType(
" T" O/ `# v6 y" ~" U0 B, m0 { - Features::GeometricConstraintData::AutoConstraintTypeNone);
6 A( \* I v+ k6 W - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
5 B3 ?" j# N% @0 Y - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);% q, m% t6 C- |
- geometricConstraintData[ii]->SetCurvature(nullOffset);% d- d4 G" K- h! N; Z
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
: Y. L! x. d7 Q } - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
: x8 M+ X$ n s* F* K - }2 }6 P# s6 u; }
" p# o* S" i. k! E7 e- studioSplineBuilder1->ConstraintManager()->SetContents(# c6 [3 r! r+ f1 o" h
- geometricConstraintData);
1 P0 U. d; g h- u/ S( U" h6 `% X
0 R: {: \( M, v8 A! v2 W- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
, l! C, Y) z o' V% W - Spline *theSpline = studioSplineBuilder1->Curve();* D- Z: N5 z, e* s" l; [+ `
3 a; [0 H" s. O3 k- studioSplineBuilder1->Destroy();
& l2 x! B6 O+ f7 I1 ^- s: f - 9 q5 k2 Y9 G/ c7 j: r) _
- return theSpline;
0 S7 R3 X# Q; W( S- q - }/ c# [) v( u( I# z9 w: z4 G
% i2 D5 ^* c$ ]* Y! E9 N- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
" s1 I; o( D+ a! {8 ?: | - {. c: J: D" I2 N
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");3 l1 M. t1 r8 m, M6 `1 ~9 l
- if (!thePoints.size()) return;; ]1 Y& u2 I) \2 Q2 l5 q
- - r/ d; w. A3 O# E
- Spline *theSpline = createStudioSplineThruPoints(thePoints);9 J0 S1 ^) j3 r2 H
/ t* k- Y& z6 z; o5 e/ O1 I3 t- if (theSpline)' z- t' a" C7 D5 |. k
- {; F$ I5 t: d6 o3 f" ^
- theSpline->Highlight();
8 u* X1 \( j- o) I4 E6 C" o; @% f - uc1601("Studio Spline Created Thru Points", TRUE);
" j5 o9 y( V; Y/ j1 u - theSpline->Unhighlight();7 Y# e! v) y* K
- }
& ?) g& u: q' S+ Q% j* M - }: e; c: f7 T, `% ~3 ]% X" Q
复制代码 $ k8 m, r7 X3 Y, p
4 `! U! a) V( Q1 t
* ?$ D7 r1 j# Y
|
|