|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线3 Z' c. j2 w9 {, ?1 f
- #include <uf_defs.h>+ x' W. O& L1 y' I4 l5 C
- #include <uf.h>
r; j* M% F D6 j - #include <uf_modl.h>
+ j* s5 G5 @8 l d- P) M, U - #include <uf_object_types.h>5 @& O$ f% R" q, [/ g# b
- #include <uf_ui.h>
& J' i9 t; W* e5 c( a - #include <uf_modl.h>* t' h) U3 j! y7 K
- #include <NXOpen/NXException.hxx>5 b9 f' v! t+ O+ `: L& W. \
- #include <NXOpen/Session.hxx>
7 D4 V, C) U3 `/ U- X3 N - #include <NXOpen/Selection.hxx>
, A" t3 \4 n: T" x1 y - #include <NXOpen/Builder.hxx>
5 }: h( i$ R0 t3 n3 o" T1 }2 Q - #include <NXOpen/Features_Feature.hxx>8 K) x4 n) U+ Y! S0 \
- #include <NXOpen/Features_FeatureBuilder.hxx>" ~5 m# W& S6 |# e; t! g
- #include <NXOpen/Features_FeatureCollection.hxx>
" m: V/ H1 X. g - #include <NXOpen/Features_GeometricConstraintData.hxx>8 n* ?$ \$ ?, ?
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) S' b, a; _) ?7 ]: O' z* q( A& i
- #include <NXOpen/Features_StudioSplineBuilder.hxx>2 b9 l& s( y+ h* @1 K. }
- #include <NXOpen/Part.hxx>
, h+ E3 S: Q& ]/ W! u& j" K - #include <NXOpen/ParTCollection.hxx>
* H4 e- F4 G; {% F - #include <NXOpen/Point.hxx>& `/ g5 m2 p! F- ^: s- D! g; M
- #include <NXOpen/PointCollection.hxx>& g$ E/ Y# y1 F9 _" g! f
- #include <NXOpen/NXString.hxx>
( n4 W# R4 E1 K9 i0 j% _ - #include <NXOpen/UI.hxx>" e; u' y2 ~. L
- #include <NXOpen/Spline.hxx>
- ~3 W3 j) F3 ^. [2 [, J2 n - #include <NXOpen/NXObjectManager.hxx>5 {: z" \# a8 g; l; O
3 l1 d) z3 _3 Q- @- using namespace NXOpen;
& v( i- E! X/ o$ q1 | - using namespace std;/ \; }0 a2 x! b" `& M( l
y5 M6 J5 X) ~+ F- extern "C" DllExport int ufusr_ask_unload()
+ `: E( w. A0 x/ H - {
4 T- P6 t' m; t: U5 r1 y/ r - return (int)Session::LibraryUnloadOptionImmediately;
* a: O6 M' g: @( k. G2 j8 O# p - }
c0 l/ E# }; _& b
( K1 n+ S* n% w8 o- static vector<Point *> selectPoints(NXString prompt): V# Z% d% P# i) g
- {
# K" \+ P' {1 p+ a, @- V6 P - UI *ui = UI::GetUI();
/ v {2 M5 m! Y. i, Y - Selection *sm = ui->SelectionManager();+ A& g& Q& o1 k; Z# _
- std::vector<Selection::MaskTriple> mask(1);
: B4 O' b0 x( Y" ]1 S - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
! s. @0 Y7 ^4 s. [2 S - std::vector<NXObject *> objects;3 k5 Y0 _% S8 i/ J( z3 @; u
3 b7 h2 t/ a2 b q/ S" d1 v- sm->SelectObjects("Select Points", prompt,$ D! f8 f5 B) w7 x% V. p
- Selection::SelectionScopeAnyInAssembly,
) ^, V) R) ~6 c6 Y0 M4 F0 D7 M) y7 \ - Selection::SelectionActionClearAndEnableSpecific,$ Z2 ~& C7 T8 K) k. C, T& ^
- false, false, mask, objects);- u) V+ B/ P0 S: C+ o1 o
- ) F% D/ O* A F% p2 u! v6 Z# R# F
- vector<Point *>selPoints(objects.size());
! d) i+ R9 e& p3 Q - for (unsigned int ii = 0; ii < objects.size(); ii++)& `) I. S# } u+ j! v" |
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);2 D3 w6 ]1 C& |4 a
- & Y( F. y6 E% e* g& K) i0 X% \0 \
- return selPoints;2 D( l, X% f j$ o5 I! E6 \
- }) I3 {7 z3 l8 y; _1 \, Q
- 4 _. F' r+ q3 g4 S0 a8 y' s
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints), C7 ]* F+ h5 M; s
- {4 R; }5 X6 s+ }9 p* F
- Session *theSession = Session::GetSession();( p6 c9 ^$ d0 s7 J- m. K
- Part *workPart(theSession->Parts()->Work());
1 ?% A& a* b2 U& c! G" [
$ X1 T. o' Z& M% i8 I- Session::UndoMarkId markId1;
$ _$ ^( i4 d; U C& X! X# R - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
9 v9 C! _& \" Y: b8 s& }1 Q- A - "Studio Spline Thru Points");
+ X2 F" G" u2 d6 e - ! Y. s5 u/ a; _3 V( H
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);4 G$ j4 |0 d, |7 l; L) z
- 6 b$ N% ?* J! d9 `: v% k
- Features::StudioSplineBuilder *studioSplineBuilder1;4 M& ]& d7 @8 D9 z
- studioSplineBuilder1 = workPart->Features()->
( r% J* K4 Q5 F V5 y: E - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
, r' C$ T" X4 N l& m - studioSplineBuilder1->SetAssociative(true);
3 d4 p( n: z! h8 \7 |9 E( Y# J$ \ - studioSplineBuilder1->5 t1 B% W! g% D
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
, Y9 L6 p! b. A+ N- U. J - studioSplineBuilder1->
7 M, Y @: P$ O* ~, f$ b4 |5 W - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);& y v8 z1 A$ R3 B
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);/ O ]% d& {' I" H& ^
- studioSplineBuilder1->SetPeriodic(false);" T, `" R. V( p; Z+ c5 a5 X6 x/ q, X0 C
- studioSplineBuilder1->
' r1 W# t% s8 u o% ]. S# A2 \# T: [ - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
9 C, E+ Y+ w( o `! P6 x - std::vector<double> knots1(0);; _' }0 y/ r$ @1 x$ p' i
- studioSplineBuilder1->SetKnots(knots1);
8 |6 V3 m6 F) v - std::vector<double> parameters1(0);
$ j' E1 _" Z- ?! `# a8 x/ ]/ a - studioSplineBuilder1->SetParameters(parameters1);
4 ?+ C0 w; d% ]& J$ B" G4 T+ ` - Direction *nullDirection(NULL);. Q) m* n7 ?3 _8 d
- Scalar *nullScalar(NULL);7 y' E2 I! }8 y" e$ P
- Offset *nullOffset(NULL);
0 `% s. w9 h9 ^$ R0 D' K - . X; S0 V1 B* `& V* R7 n% j- A
- std::vector<Features::GeometricConstraintData *>
7 b, f* @" x2 B - geometricConstraintData(thePoints.size());
3 r7 r& r$ z( M$ d7 \7 d, T, n
+ {+ x7 ~. J( b5 O- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
; A$ S/ g% K) L; N2 {1 b4 G9 p - {
7 S5 o: |( q* i- V! a/ q2 k: a8 ^6 L - geometricConstraintData[ii] = studioSplineBuilder1->0 i- i9 y( N& P4 z
- ConstraintManager()->CreateGeometricConstraintData();
' s8 l$ r; t+ t" E - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
1 p' k$ [- q& U$ q. ~ - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
) o, x( A" G; N( P2 ?3 m - Features::GeometricConstraintData::ParameterDirectionIso);
: O! h& G# |! d7 {1 K - geometricConstraintData[ii]->SetAutomaticConstraintType(
1 l( }' G1 {; S1 {. Z - Features::GeometricConstraintData::AutoConstraintTypeNone);. q3 s' x) U: u a
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
1 P. L7 C4 M0 z; I9 @6 [$ l - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);2 \; R# P9 z' n* J9 i
- geometricConstraintData[ii]->SetCurvature(nullOffset);
$ I! _$ m4 H8 |! J, \1 g: f - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
, b* {+ M9 d, m% d f% n$ U4 I - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 |" G" g) q/ O: n& B+ }
- }
9 c- Q- a3 L% t& D: H7 X* V
4 t+ K# n/ f$ N) [$ N- studioSplineBuilder1->ConstraintManager()->SetContents(
' K: k8 L5 w r+ |, Q - geometricConstraintData);
5 i( T! Z) w8 |5 \6 P. | - / V5 l0 `$ b* E: w
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
! T9 f3 o! `; E' T0 |/ P - Spline *theSpline = studioSplineBuilder1->Curve();
3 T5 d' w. }) H3 z7 x' s
9 i' Y6 ~8 z6 ]$ ~# X3 q9 C- studioSplineBuilder1->Destroy();
) A% X5 `+ K+ n) W
`# m- c4 e7 h2 W) M6 _5 D% V- return theSpline;
4 A: ^3 d5 R: W - }' o& N; d& A3 [+ B! T
- 9 g/ o" l' I5 c4 w) ~* I0 E
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
* n! G: n: W$ \. v/ T- v9 q1 | - {+ B2 H. p \/ m8 f1 x2 U p
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
8 Z6 \# v, U5 Q& U - if (!thePoints.size()) return;$ h/ F J% d5 r1 \
- 7 z! T6 @) d3 K `& J
- Spline *theSpline = createStudioSplineThruPoints(thePoints);: q0 e! S; u2 ?
+ i: y/ i+ U/ J+ v" T" e$ P- if (theSpline)2 E- O# ~1 f, L5 @' q- ?$ I
- {
/ [( j6 \7 u0 d$ R. H# c - theSpline->Highlight();) z+ |3 ^3 u0 a; B7 }9 M3 ?
- uc1601("Studio Spline Created Thru Points", TRUE);8 g& b6 p) I# ^0 g* R7 c+ q
- theSpline->Unhighlight();% X, R) p6 P& Y% ], k# e9 J }* q+ i
- }) ?' r. K" ^. {" S
- }
( v4 n) b8 x6 M1 k* Q) l0 W+ |
复制代码 7 `1 [' y3 W: i' D' J
* m* ]. V9 ]9 [9 B5 i" L/ n4 }" ?
) H$ s6 |. Y& F: ~0 }+ v" c
|
|