|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线: p+ ~; H$ t6 F
- #include <uf_defs.h>! _) G- M4 k& ?" J- t1 m5 H+ c ~# A
- #include <uf.h>
; p" `7 Z- F$ x' ]# C H( q. O - #include <uf_modl.h>
4 L4 O T$ r5 C/ r9 R1 u) n- i9 x, u' E - #include <uf_object_types.h>: ^7 |: G q3 g, p8 I
- #include <uf_ui.h>/ A1 x) d/ ~0 ?3 o6 J$ w
- #include <uf_modl.h>0 E7 D! f& L; U, X+ a
- #include <NXOpen/NXException.hxx>+ ]# Q4 k7 s6 U( ?- n# d" K$ ?9 B; c" p
- #include <NXOpen/Session.hxx>
1 J; M+ S+ P! V. b* H- X - #include <NXOpen/Selection.hxx># R R9 y) ^1 H9 A) K
- #include <NXOpen/Builder.hxx>
. \9 N5 `7 m5 B% T9 y# d - #include <NXOpen/Features_Feature.hxx>) b7 Q# V; [# y
- #include <NXOpen/Features_FeatureBuilder.hxx>
* Q: ~, B- d0 j% _) K9 ]' P - #include <NXOpen/Features_FeatureCollection.hxx>
6 ?: M( Z$ n" O - #include <NXOpen/Features_GeometricConstraintData.hxx>" T# f; l: A' K: N
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
. v6 r6 `+ @ L. v - #include <NXOpen/Features_StudioSplineBuilder.hxx>3 j- ?. |. }+ S; K4 Q3 ]3 W' M
- #include <NXOpen/Part.hxx>1 A: p! J5 f$ i) R g9 ~' x
- #include <NXOpen/ParTCollection.hxx>
3 X9 Y% M6 E& s1 v9 y) ^7 ^ - #include <NXOpen/Point.hxx>
6 @8 \- z2 R1 G9 ^7 z* u - #include <NXOpen/PointCollection.hxx>
& V/ Z7 ~ y0 v; @6 X7 x& Y - #include <NXOpen/NXString.hxx>9 o" O% j0 U# v/ ]9 T4 A. O
- #include <NXOpen/UI.hxx>
4 [ j1 ^2 _& Y6 H# k: Q - #include <NXOpen/Spline.hxx>" D! b- F" h. I/ Z8 l& }: p
- #include <NXOpen/NXObjectManager.hxx>
7 P. l9 G1 P4 u! H- D2 A- e
& u) n7 w) w7 S" D6 K- using namespace NXOpen;
H8 C4 l$ l1 K2 v& U - using namespace std;1 g- _+ i* j( o/ d: g
1 e) N8 d O; \* D" _- extern "C" DllExport int ufusr_ask_unload()# @' c) j3 z$ H& m3 Z: J/ R: n" h$ h# l
- {/ R* A5 t, T0 `/ Q0 ]
- return (int)Session::LibraryUnloadOptionImmediately;! M9 r G; Z0 q Q
- }+ E- {) Z% i8 k7 Q! R( a9 O
- * t" T/ a3 ^! Q' P
- static vector<Point *> selectPoints(NXString prompt)# h. Z; j, m% b- o: c3 V3 M v
- {
& E) c1 o/ H) L+ x - UI *ui = UI::GetUI();: h' e4 M- ~6 O3 h- V) S. {- h
- Selection *sm = ui->SelectionManager();
" h. p) g, e' F: x4 j/ w8 q - std::vector<Selection::MaskTriple> mask(1);1 [* d) l! e# @, ]9 ~: G
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
' v. N8 O) u$ F# a& U9 [6 Y* { - std::vector<NXObject *> objects;
( y+ I1 U4 b8 H+ r - $ _6 J4 u3 W9 U
- sm->SelectObjects("Select Points", prompt,
( m: x5 a: d; ?1 S - Selection::SelectionScopeAnyInAssembly,
9 B: v% A. Q; Y# S! C* z - Selection::SelectionActionClearAndEnableSpecific,. e1 h1 {6 o) D9 C! J
- false, false, mask, objects);
* r9 l7 B3 E7 y) e. c+ F; a% y
% ]5 d. r t5 g G" w( d' n2 a/ O* d4 o- vector<Point *>selPoints(objects.size());
5 I Z, P, ]- a& y6 C - for (unsigned int ii = 0; ii < objects.size(); ii++)3 Z }4 i, R# V# f9 D8 G
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
% T9 m- x/ V$ G% `
. F5 w! ^4 `0 ]$ v' V+ }0 s5 T9 K- return selPoints;1 W4 j1 ]0 W, G
- }; @6 I* |7 b( N+ @; }
5 ~: }! V2 | g9 t, y6 m6 `" }- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). i9 G, L y/ q3 w) Q3 t$ t
- {" A5 d9 }) L7 a- l9 T
- Session *theSession = Session::GetSession();; E" M3 u$ v% w2 J# R2 U, |7 m
- Part *workPart(theSession->Parts()->Work());
0 R; ]/ Z' O* U6 S, I- Y, Z - " \# _8 F: t3 H# T# f) I
- Session::UndoMarkId markId1;
( j9 G' k' q& E( R - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,# j% R2 ]) S0 A" o) {# r$ i
- "Studio Spline Thru Points");8 l+ [ n) N0 S+ n l9 F6 Y
: A% ~% s( H2 i1 P* }1 l+ H, ?- Features::StudioSpline *nullFeatures_StudioSpline(NULL);8 R( {3 y$ `1 o) R! ~. }
- 6 i1 b5 W* |" p- A [# K
- Features::StudioSplineBuilder *studioSplineBuilder1;
% d. b4 U7 m; {2 { - studioSplineBuilder1 = workPart->Features()->0 U& Y0 y, ?6 z# M8 b2 c
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);+ d) Z& ~; L$ }1 P: L
- studioSplineBuilder1->SetAssociative(true);
0 Q. G! h" D H$ i. J8 A- I9 C+ I - studioSplineBuilder1->
9 n) ]9 {7 l" b - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
" e/ k* _) e# X - studioSplineBuilder1->. B4 h, K5 w/ A1 d/ G
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
, \. \1 l5 q) Q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);0 {( c% N$ j1 O: t; ?' I
- studioSplineBuilder1->SetPeriodic(false);
0 n1 b6 c# I7 c% z3 { - studioSplineBuilder1->
+ A: g' d% e. R" x - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);/ L/ u( b1 ]4 {1 w
- std::vector<double> knots1(0);
6 y7 S i @) i$ w* i6 R0 e - studioSplineBuilder1->SetKnots(knots1);
" u; i- E/ {5 H9 p - std::vector<double> parameters1(0);6 c- p" `2 t4 U$ U" g
- studioSplineBuilder1->SetParameters(parameters1);
2 e/ k( {0 X' d( \9 } - Direction *nullDirection(NULL);- e) B. d* R/ a! g8 \
- Scalar *nullScalar(NULL);' ~' V2 l" d5 f$ W- @. G
- Offset *nullOffset(NULL);; i& c" U1 B2 d
- ' T" V0 a: Z8 L( ]) R
- std::vector<Features::GeometricConstraintData *>
+ a4 d" c( `7 S" ^1 X% I; c - geometricConstraintData(thePoints.size());7 L' n0 P( Y7 d+ {& C( T
- 7 g, f7 Y/ T" \: v. K7 E
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
6 p, b7 |' `* J' i2 W - {$ G! [' ]* n9 t$ d" O, h
- geometricConstraintData[ii] = studioSplineBuilder1->& J/ ~3 T% t' e
- ConstraintManager()->CreateGeometricConstraintData();
- ^( @2 s# e7 @0 e$ ` - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
& z# y$ c$ y" C) d1 i" ` - geometricConstraintData[ii]->SetAutomaticConstraintDirection(/ u4 X9 F* g1 ~5 H
- Features::GeometricConstraintData::ParameterDirectionIso);
! X8 _, [" B6 t1 M - geometricConstraintData[ii]->SetAutomaticConstraintType(
3 J/ Q' y4 T5 g9 C( q8 x+ z - Features::GeometricConstraintData::AutoConstraintTypeNone);& U+ P( E9 U. I- d" Y% K
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
; h0 p2 Y: ], F! r* S, t1 N: F3 m0 v# M - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
4 K. R$ y% }( c" p( O8 I - geometricConstraintData[ii]->SetCurvature(nullOffset);+ h2 b s' _% _: J! `! Z
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
( N X5 R/ R% a ?6 `6 m) _ - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
5 c2 D' g2 l6 v0 Y5 y9 W, e - }- I* s/ m9 z; z% h, b, x' Q
3 b3 G+ G4 L8 ~- studioSplineBuilder1->ConstraintManager()->SetContents(
7 k) \+ z9 t5 ^- L$ m' O - geometricConstraintData);
% H Y+ m6 x, w% @ - ) Z* ]6 q) b+ `6 f8 b
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
, c6 k1 u( x. I3 F' P4 G - Spline *theSpline = studioSplineBuilder1->Curve();
& R' o* m4 b, M$ ]. x8 `; n9 {; r
: ^% c& y! T! M- studioSplineBuilder1->Destroy(); w. t2 S# Z0 t% J7 F4 N
- 4 _. s( l# P' \1 n" X
- return theSpline;
' U% A9 L- _9 y" q! f9 b6 m - }' p. d: E( m3 { f- n
- ( O0 P/ [, H! P2 S" i
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)6 v% G3 Q3 J7 F1 ?' @
- {3 ]$ D, c6 a9 v
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");9 V% r% G. @" E7 ~
- if (!thePoints.size()) return;
9 \' A0 x2 Y) ~& v7 ]* m$ r
) j: Z! @4 Y, C; u2 V- Spline *theSpline = createStudioSplineThruPoints(thePoints);
: \# O6 ]3 C! m; d# V
4 d7 v5 a7 n; H8 R5 `- if (theSpline)
1 P+ ~- ~! U1 z. _9 l - {
( q: M# i3 @. g - theSpline->Highlight();
) e& S# K6 x7 |% p: [$ a. f+ M - uc1601("Studio Spline Created Thru Points", TRUE);
/ r+ B7 e. C! w. ~6 ^7 Q - theSpline->Unhighlight();
% ?) f" ~* X3 y" ?$ E/ v - }- s9 k+ n) m" E: y7 u9 i
- }4 \; @$ _: }. G" F0 d% _
复制代码
0 Y& _: b9 P4 q. {& J C# B1 R. F
% K. p) H* `5 F4 w
|
|