|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
2 K6 n0 N" R4 o# n) I j- #include <uf_defs.h>$ d' m4 u# V5 H1 J' e
- #include <uf.h>
, |2 K3 w5 c. y1 a+ ^8 B - #include <uf_modl.h>
' x. C: R, b; \ - #include <uf_object_types.h>
; G! B) u; H K: r - #include <uf_ui.h>, B* h/ R1 k; Q# O/ n8 [: e# c8 x
- #include <uf_modl.h>
]5 r) k; L* F7 A, e - #include <NXOpen/NXException.hxx>
# R0 b9 I. q; B& c - #include <NXOpen/Session.hxx>' L9 \/ Q' g& C. L8 C/ y
- #include <NXOpen/Selection.hxx> h7 D+ z! A: `: n- T- v; f- _
- #include <NXOpen/Builder.hxx>
) b+ l0 x) f9 R4 [+ c3 \ - #include <NXOpen/Features_Feature.hxx>/ K3 `1 q( i- X3 ~/ i. n
- #include <NXOpen/Features_FeatureBuilder.hxx>7 i" W% s" o' O) L
- #include <NXOpen/Features_FeatureCollection.hxx>5 \ p* T ~3 r
- #include <NXOpen/Features_GeometricConstraintData.hxx>3 f6 Y' b. P4 B9 K' [% U
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
8 S9 N& \# m7 R' c8 Z, Y Y - #include <NXOpen/Features_StudioSplineBuilder.hxx>
: A( R1 M3 G) j0 N( _: z$ G' @ - #include <NXOpen/Part.hxx>3 |3 e6 Y1 N1 Q; B3 X* @$ b
- #include <NXOpen/ParTCollection.hxx>
# K+ u3 N4 k" ?- O - #include <NXOpen/Point.hxx>
9 E% N# X8 q" k) n) g - #include <NXOpen/PointCollection.hxx>
1 H+ i3 s4 j- t) p2 s$ T - #include <NXOpen/NXString.hxx>. e8 _( a4 y, ]/ N4 E" m
- #include <NXOpen/UI.hxx>- o' {6 p3 i2 F5 E- k- V- E# Q0 S
- #include <NXOpen/Spline.hxx>
" O% f, [, u9 j6 Q( H - #include <NXOpen/NXObjectManager.hxx>/ |3 A' x5 O) T m4 i
- 8 e. o5 {, X" w# Y3 a
- using namespace NXOpen;
3 ?# D5 a6 x$ r1 X! T/ ~ - using namespace std;! f W' v& k) G* Z) @( m3 Q4 |: g! C
- : d- _( U$ C" Y
- extern "C" DllExport int ufusr_ask_unload()
! w+ e" [* p! c _( F+ x" I - {$ e2 r6 h2 o/ q4 i1 X
- return (int)Session::LibraryUnloadOptionImmediately;$ \7 S1 x5 }# q5 Y* e2 X
- }; p* f( |( }5 `# ]3 }7 W5 c: R
- / z! ?, b; m$ m9 g0 C; Q* d
- static vector<Point *> selectPoints(NXString prompt)* f% z. @7 Y% A5 ]4 e
- { V6 ]$ }& \* J( I+ h& r
- UI *ui = UI::GetUI();
8 j; }9 ~* y9 @& R. e. k v - Selection *sm = ui->SelectionManager();
$ ]8 y& Y; l( h& ^ - std::vector<Selection::MaskTriple> mask(1);
% g+ a3 E* x5 }8 E1 a1 g - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
; `# Y2 x& _# }- v9 E - std::vector<NXObject *> objects;
m$ o& d& t0 _) G+ f - ( I5 ]1 i) \& g# k4 f: }
- sm->SelectObjects("Select Points", prompt,2 y- N/ C u1 j$ }, u
- Selection::SelectionScopeAnyInAssembly,
! D5 r6 g+ a+ d1 o& e - Selection::SelectionActionClearAndEnableSpecific,, S1 N5 ~9 r F
- false, false, mask, objects);% `0 k3 `# z2 v
- # U, I& m0 F+ D+ D' ?
- vector<Point *>selPoints(objects.size()); _: T* o" }, O0 n% k$ A
- for (unsigned int ii = 0; ii < objects.size(); ii++)" j, S. A' O: |0 \: O1 \8 ~
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
* w' A' r$ q5 b" w& u; P: j - , H1 L5 q! ?# @; {& q
- return selPoints;* B* M6 V4 M: j
- }
$ H4 e3 M& Q$ j+ O& r0 m+ E - 6 p2 b+ O1 O5 w
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
& q' V0 Y* Q4 x2 G) f - {& F) ^* A) N$ R9 Y1 E
- Session *theSession = Session::GetSession();* { K$ N3 [) e
- Part *workPart(theSession->Parts()->Work());/ t, B5 f# z( q' l4 b a: E
- & ~& d& v% U- U7 a" Q
- Session::UndoMarkId markId1;
8 X4 b, w' l h) Q - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
5 c! `* O( r- I- _ - "Studio Spline Thru Points");1 ^) U0 @: j7 x0 n" O
- 4 Q% p F- X! D3 d
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 Q/ g1 {+ q9 r8 Q% f/ R' Y! x
1 Q- D$ H n, u" V# p- Features::StudioSplineBuilder *studioSplineBuilder1;! l! S# Q0 H. ^# D
- studioSplineBuilder1 = workPart->Features()->) {: u5 c5 V& E1 v. b
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
4 D7 V6 D! w9 l9 X! a- J& J9 v - studioSplineBuilder1->SetAssociative(true);2 c% |3 l! f% @6 Q
- studioSplineBuilder1->
/ R: |# D. |& \! m - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
- i0 _2 P0 ]9 L8 o( ^! o& @& B2 B - studioSplineBuilder1->; D: Z4 Y" | Y3 e
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);. t% j' Z( O' p* [/ N
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
: x. J& X' k9 o/ U - studioSplineBuilder1->SetPeriodic(false);
2 U& G6 n3 j8 p3 n, j - studioSplineBuilder1->
5 B' b: U- f- O. @ - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);* m. s2 @9 B3 O! L
- std::vector<double> knots1(0);3 F) p+ K$ d) ?/ _
- studioSplineBuilder1->SetKnots(knots1);, c T% B m3 S% W8 D/ n% E
- std::vector<double> parameters1(0);
4 U" y5 ^# }" b1 |- t - studioSplineBuilder1->SetParameters(parameters1);
8 k% p% Z9 U) q - Direction *nullDirection(NULL);2 p' u8 n( [. u* R& e& R
- Scalar *nullScalar(NULL);
8 R1 {6 g3 v G1 E P; i - Offset *nullOffset(NULL);' w- M' ?- [( [$ I( P
3 k( U1 |2 O, z2 p- std::vector<Features::GeometricConstraintData *>0 V: ^' _2 E ? F
- geometricConstraintData(thePoints.size());- t" B9 x5 w9 D( C- c
- % M" r o2 T/ @1 a6 l/ C
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
# R$ \8 g" n J. I6 L7 d1 K - {
" n4 }. c7 H0 [( `' s9 W - geometricConstraintData[ii] = studioSplineBuilder1->
L5 U$ r' j3 e0 {$ [2 C - ConstraintManager()->CreateGeometricConstraintData();
+ U% V' H+ Q$ D, x2 A1 Y - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
" p4 i- q H3 b3 o8 t1 e9 t. P - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
" S2 z3 ~/ J) @8 O - Features::GeometricConstraintData::ParameterDirectionIso);6 {% A+ G6 h2 }! g) a4 s
- geometricConstraintData[ii]->SetAutomaticConstraintType(6 B: M% j0 ~0 p$ s' ?0 C
- Features::GeometricConstraintData::AutoConstraintTypeNone);, l! ^9 t! E1 ~6 h
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ p6 N' H2 V9 \
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);# _; h+ b8 X- K
- geometricConstraintData[ii]->SetCurvature(nullOffset);
- T5 m% p0 n$ [8 y4 P% V - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
' n; M( f& M9 t2 ]4 B# B1 w( A5 ] - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
& d* Q9 d% B3 {7 ]8 k$ N - }4 W0 B! h, ?. p6 W( F- L5 D
5 v2 ?- j5 B$ ^- A- studioSplineBuilder1->ConstraintManager()->SetContents(8 O2 x3 w8 H- a7 I# p
- geometricConstraintData);7 [3 b& K4 D9 W8 i. y
) @: E) I" h- @% ?% b' u5 g- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
$ n- Y. B/ z2 ], q4 @$ ~. c! f& C; w - Spline *theSpline = studioSplineBuilder1->Curve();
+ e3 ~* @, F/ m2 \( B; r _
' x/ s2 Y) u6 r8 a- studioSplineBuilder1->Destroy();
8 I7 q6 i- d: _1 g0 D
4 [ L6 U9 x1 P- return theSpline;
0 ^4 Q1 D7 x2 _, c; x6 K - }
: Y! F; R5 O7 C. Q" B: V8 H4 i0 D
% c# ~! }6 v0 C Z- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
3 x) C+ V* l- z0 Y# g - {/ K- s4 A' u2 g( {7 ^& {
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) x4 V* x: q; H0 A2 n8 p6 q3 k& x) C
- if (!thePoints.size()) return;1 [% ~! p& x( z7 H3 f
9 ]" q4 k- C; |* P* P; _- Spline *theSpline = createStudioSplineThruPoints(thePoints);/ I- R. d3 `. s- S3 d; d( z, a
- 6 M U! L9 I7 u v; L* t! Q0 g
- if (theSpline)
5 Z+ J( l/ N4 e - {
" o0 f$ c4 y& d: M8 g7 F1 I, J8 Q - theSpline->Highlight();- W/ g1 Z' Z* E# M" O+ @' X0 `
- uc1601("Studio Spline Created Thru Points", TRUE);/ v' `; o) C& T8 p& k' v% G
- theSpline->Unhighlight();% U1 e4 v) ~' H% L/ z0 O, @
- }
+ e4 q$ t+ B0 T# C3 w - }
6 Q- Z' M# a( n4 g( a3 \9 V- k) n
复制代码 , E6 b' }7 [: q: b- n
7 X M3 V2 n$ k- D: D/ m- N6 V* B. R% z5 `9 J7 r
|
|