|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
. S0 g0 X& t4 I& W0 F- #include <uf_defs.h>6 x$ ?, `% V' |+ q
- #include <uf.h>
: c) A" D! Q9 T" {! W0 E* m: r. O - #include <uf_modl.h>7 [% \- P1 F; B W$ q( a
- #include <uf_object_types.h>
) i# [2 N ?; V - #include <uf_ui.h>
1 d$ s& l; R% E* q - #include <uf_modl.h>
7 N4 Q" k4 e* b7 f - #include <NXOpen/NXException.hxx>/ D- N' y- r/ Y9 P/ a
- #include <NXOpen/Session.hxx>. t0 \4 U' B5 M5 Z* n9 O
- #include <NXOpen/Selection.hxx>
& s* s; B+ p, ?/ o8 s/ z7 }4 K - #include <NXOpen/Builder.hxx>3 S# _# \ E+ ^7 x/ m" E
- #include <NXOpen/Features_Feature.hxx>- C7 t! d( W1 g; L, R
- #include <NXOpen/Features_FeatureBuilder.hxx>9 N6 E# C) F) P" W1 O
- #include <NXOpen/Features_FeatureCollection.hxx>
: D3 |! p4 V& N' m5 L8 [) e9 I - #include <NXOpen/Features_GeometricConstraintData.hxx>
2 M% }0 a% _ w8 ]2 j4 F# J - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>. L7 u( w" h( P
- #include <NXOpen/Features_StudioSplineBuilder.hxx>( [8 X4 z0 l- h/ R
- #include <NXOpen/Part.hxx>
! \4 {0 V8 g. g N% f6 \- M+ l( N - #include <NXOpen/ParTCollection.hxx>
$ w# F3 e' N& c3 U$ ` - #include <NXOpen/Point.hxx>- R, d/ h9 F- r3 b% u
- #include <NXOpen/PointCollection.hxx># J# w, z/ D% Z6 G
- #include <NXOpen/NXString.hxx>* v7 q* O9 D& w& l9 c" h9 u' s# M
- #include <NXOpen/UI.hxx>) k9 W3 c4 v4 J# U& W
- #include <NXOpen/Spline.hxx># _5 y0 |5 u# }5 n
- #include <NXOpen/NXObjectManager.hxx>- X: X9 Z3 ]$ F& i9 E4 U
- ; L( w8 K, G3 {% D5 D5 `; y* n
- using namespace NXOpen;. o9 z& O9 k# R
- using namespace std;
2 ~) G6 F* O* ?# C
+ I: c/ r& e3 Z5 B" \0 z- extern "C" DllExport int ufusr_ask_unload()
- o5 l+ x: k: x- V4 J# k - {! a& f: `# H2 W4 [7 Z
- return (int)Session::LibraryUnloadOptionImmediately;' G; \! E. B1 T5 ~. J
- }
: F F! k; D( U& a W% l
8 W* I! @5 w4 v" m3 c; N6 C- static vector<Point *> selectPoints(NXString prompt)2 K0 c: U K; ~2 m6 z/ N4 ]6 f
- {( j! l. a( g* W
- UI *ui = UI::GetUI();/ l9 A: o/ [3 K2 o, E+ Y1 A
- Selection *sm = ui->SelectionManager();- w2 F( i' L$ U2 \- U. p$ {- Q
- std::vector<Selection::MaskTriple> mask(1);( {/ W- P' O- \
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);. Q4 w1 D0 p% F0 i5 T1 i5 V
- std::vector<NXObject *> objects;; A: j+ ~& d [
4 _- q& ]4 H" G. H. A3 {3 U- sm->SelectObjects("Select Points", prompt,
6 Y6 ?# [9 f" X, P - Selection::SelectionScopeAnyInAssembly,7 T# W& u: x/ G Y/ ]* w
- Selection::SelectionActionClearAndEnableSpecific,4 j7 I3 b1 Z8 T: g
- false, false, mask, objects);
' l' w0 @$ V: |+ b6 @$ Z
+ |9 Q! }5 Y: e; Z- C# v- vector<Point *>selPoints(objects.size());, ~" h% K: j# p0 z
- for (unsigned int ii = 0; ii < objects.size(); ii++), x. m) C7 c& _. I. T5 @: ?# }
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 h4 a/ l. Y0 s1 _: F* n% `
% A, m- I! O7 m- return selPoints;
) @9 H* P/ z) b - }
" q: A# o% \0 l- N6 q7 c) h( Y* i - + V+ k, o' M# g. i0 f% |* |
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
1 M. _. d6 ]4 p - {2 F- X1 I5 @+ y P% `) }) b4 c
- Session *theSession = Session::GetSession();
1 @' C: o$ E" O" @ - Part *workPart(theSession->Parts()->Work());
1 b* j+ R% H/ z - 3 X, l- ~' u' n/ }. r: E& g
- Session::UndoMarkId markId1;
5 P) |% A! c0 Q& u% Y( h7 T3 \ - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& V! _: h0 Y( p0 x8 j4 w( S# C
- "Studio Spline Thru Points");# [3 a6 U6 z* ?
o& b& m& k1 N7 W& r- Features::StudioSpline *nullFeatures_StudioSpline(NULL);9 j# n. w! d1 F! S& f0 C+ }
- / B7 S' o; c) @) [+ [3 d) L& M
- Features::StudioSplineBuilder *studioSplineBuilder1;
, y$ q( M! a3 L I - studioSplineBuilder1 = workPart->Features()->
! f) G. M4 K: \) b" [ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
' O' ?' \# D( C0 |; B - studioSplineBuilder1->SetAssociative(true);) x# {. D- f. H* ~- ^
- studioSplineBuilder1->
4 {2 l9 V: x: @* s8 m# i( E - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
6 R3 {8 k/ e1 R% a - studioSplineBuilder1->
9 y! v. T, y$ H9 {$ I+ a. A, M - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);3 k! w0 a; x0 }2 W
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);& d1 u/ v( [# D6 D l3 x. e
- studioSplineBuilder1->SetPeriodic(false);" K! l! b3 v5 E' b2 r& M3 Q! e
- studioSplineBuilder1->9 Z0 I) N, u O" P$ B
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
/ Z, n" y$ k3 v% { - std::vector<double> knots1(0);* V4 M6 h6 A1 S
- studioSplineBuilder1->SetKnots(knots1);. l8 ?5 M1 U( f9 j2 x8 _
- std::vector<double> parameters1(0);
2 K) G5 S5 M1 T- \+ q8 N8 m - studioSplineBuilder1->SetParameters(parameters1);
' U# Q% [- S4 O6 C% F+ o - Direction *nullDirection(NULL);
4 _! O% e- A" l6 \ - Scalar *nullScalar(NULL);/ P0 V4 u& @4 {' w- R: @+ v6 R. X
- Offset *nullOffset(NULL);3 J: i. n0 f0 U# [7 |$ X, J
- 0 w) \9 @6 M. q; q
- std::vector<Features::GeometricConstraintData *>
1 j. U8 h" u7 \8 s; ^6 C6 q - geometricConstraintData(thePoints.size());
- X3 u* l5 H+ u1 ^' g - E8 w' |( s3 p4 |$ A+ d% y
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)3 P3 U( @" q) |% D: S' `
- {
" ?+ W0 ~2 W8 _7 v/ Q - geometricConstraintData[ii] = studioSplineBuilder1->
9 J- n' \/ o* j) Y - ConstraintManager()->CreateGeometricConstraintData();; a8 B1 S/ o2 F( b1 q1 [- P- B! }
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);( E! a4 z- c/ F% p+ R. v
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
$ J2 b' o* f6 T. l - Features::GeometricConstraintData::ParameterDirectionIso);
2 G& h; C( e" w6 t4 o - geometricConstraintData[ii]->SetAutomaticConstraintType(# {2 ?3 o" K* l! ~. T
- Features::GeometricConstraintData::AutoConstraintTypeNone);! l+ J+ V* S0 [% j* h& `
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
}" b7 ~0 S. k s* E - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ W9 E0 K2 P8 a
- geometricConstraintData[ii]->SetCurvature(nullOffset);0 `# h4 N3 [) _6 X1 v$ i
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
: ~/ P Z' F8 [$ u. |5 B5 v( [2 O - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 K5 z4 o9 q$ X0 R2 _$ a' v
- }
+ ^$ M* s3 r+ `: O( }5 M# p8 y
! p# D+ M0 I1 U: b3 F8 _- studioSplineBuilder1->ConstraintManager()->SetContents(
9 |! l7 o d1 V - geometricConstraintData);
6 g2 p+ Z) w# ?
5 A4 B1 C R; s1 ]8 m- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();+ G. @$ M. Z) x4 n. p
- Spline *theSpline = studioSplineBuilder1->Curve();9 k0 F" ~1 r& I6 M
2 J! J) C5 \5 c: O3 c; B- studioSplineBuilder1->Destroy();) R% u9 ^6 N& H7 B" n1 w
% Z+ B; Z% X, f4 a! H v- return theSpline;
' M- s* h O- L2 Q - }, I( j+ M2 _8 y8 d
1 o+ c0 V$ B4 L- P- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): k3 N& o9 y% S+ V7 p& P
- {
5 I B" j; q) b/ H' i# s - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
1 A% S4 u$ G0 N, k - if (!thePoints.size()) return;5 s% J2 ]- [0 p3 X8 m: C; u
' Z! G5 A8 G4 f0 y) K- Spline *theSpline = createStudioSplineThruPoints(thePoints);
: T+ A3 t* l! b0 V" \) @
; |9 E& v# I C/ X6 J$ L- if (theSpline)7 A& j$ p6 M# l
- {
( l# V3 T7 K( l( O - theSpline->Highlight();
1 k* _2 l* J1 e C8 {+ d0 w - uc1601("Studio Spline Created Thru Points", TRUE); h* ~) O' w0 G6 B: s8 k/ e
- theSpline->Unhighlight();* \, Y' e" @2 N
- }# f4 E9 x1 j4 g" F, u
- }
5 b% L. O. {0 J: i
复制代码 / M9 T+ V+ v2 p s
( I. H4 P9 ^0 m
! k2 t9 e8 s3 f/ F; {% I1 H
|
|