|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
* C- H3 u4 X' _4 @3 s, ~- #include <uf_defs.h>
/ L+ q- W3 j2 Y2 ?( N - #include <uf.h># t$ Z2 Y5 L! f J$ T' U5 a
- #include <uf_modl.h>+ n+ G6 I2 _" D+ t4 q9 C
- #include <uf_object_types.h>1 w8 r: U( U. D/ D
- #include <uf_ui.h>
4 X2 ^( E6 N( [- {+ l4 q4 @7 p2 h - #include <uf_modl.h>9 r& i$ k/ r/ n; m, B- C6 d6 h
- #include <NXOpen/NXException.hxx>
/ Y+ w( a% z! n - #include <NXOpen/Session.hxx>
- h1 e) Q i( d - #include <NXOpen/Selection.hxx>% r+ D5 I9 \3 N! r' I( G
- #include <NXOpen/Builder.hxx>
; S. |6 `6 S, p - #include <NXOpen/Features_Feature.hxx>0 Z" T3 ?$ x$ l) |/ @: ^2 d
- #include <NXOpen/Features_FeatureBuilder.hxx># Q4 e8 p# X' U# s) |5 W3 C2 c
- #include <NXOpen/Features_FeatureCollection.hxx>
, I. S& j7 h4 q) | - #include <NXOpen/Features_GeometricConstraintData.hxx>
. q, i" ?: @2 y: ^) {3 ^ - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>' o. h4 u6 W9 j+ F
- #include <NXOpen/Features_StudioSplineBuilder.hxx>1 I+ U. a p7 I; R& c* |' a; N
- #include <NXOpen/Part.hxx>
+ A1 s' p: i( Q - #include <NXOpen/ParTCollection.hxx>
, K! k' g( ?: \ - #include <NXOpen/Point.hxx># L% l2 o# G% d; O% Q% h* s
- #include <NXOpen/PointCollection.hxx>$ Z" R! ^% L( N/ U9 ~) y- F/ J/ K
- #include <NXOpen/NXString.hxx>/ `5 P8 A! n; Z+ _% f4 {
- #include <NXOpen/UI.hxx>
) {: B C% g1 D p6 S/ P0 y - #include <NXOpen/Spline.hxx>& L8 w% @4 ^+ p' b0 x2 }
- #include <NXOpen/NXObjectManager.hxx>
% x/ @0 Q9 G1 r* ~1 [. N0 S
2 O6 Z' c: ?' T' R, f, S) f k- using namespace NXOpen;% X, p& X9 t* J9 _6 x5 [3 N9 |+ ^& a
- using namespace std;
7 G5 g8 e8 X. s. L" o. k - 4 P* d5 \: U( h M
- extern "C" DllExport int ufusr_ask_unload()
, k; ~3 F3 d, H - {1 ^3 R; m% |5 @3 g$ g9 L3 D
- return (int)Session::LibraryUnloadOptionImmediately;, ~0 T3 P6 S: @
- }& t3 j1 C2 I( ]) I5 e$ b7 N
5 v, H6 u% w! V" I- static vector<Point *> selectPoints(NXString prompt)
2 n6 T7 P. |0 h ^6 u7 t. r1 u - {. R9 y% y* z5 K9 l, \4 n% y
- UI *ui = UI::GetUI();
8 t' F& W) P. D+ Z - Selection *sm = ui->SelectionManager();# L% E c& t. O" ^$ _+ }2 s0 [
- std::vector<Selection::MaskTriple> mask(1);/ X5 b6 A! m& `0 N
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* ]$ J9 B6 a) a1 u0 Y- s" o+ }9 G0 ^% @5 L
- std::vector<NXObject *> objects;
# ?- ^1 z% M0 F" }1 M
/ o9 B6 k1 Z5 N1 \# v- sm->SelectObjects("Select Points", prompt,
( f( F; I7 j5 v - Selection::SelectionScopeAnyInAssembly,. ]3 r% u+ Q! h8 a; K4 X! ~6 Z
- Selection::SelectionActionClearAndEnableSpecific,9 v# I! X1 x8 F+ U5 H" ~
- false, false, mask, objects);; o; R/ C3 n% W
- f; S4 W5 S2 t- W$ K8 Z1 B- vector<Point *>selPoints(objects.size());- M5 g9 k, j7 b8 T0 @* ~
- for (unsigned int ii = 0; ii < objects.size(); ii++)2 U9 Z+ l& ~; K7 d5 \4 h
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);3 a$ w: }. ]! C! O' T
- 8 l/ X( s3 F( h: O4 L
- return selPoints;
Z; L V: c+ y+ m& y6 H- h4 | - }0 ]% ~, x0 d$ C1 [5 } ]9 }% [6 L
1 s# l5 R& u2 E, V* t5 P- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)# R& [' ]2 K' ~- H' z1 e
- {
I" u5 z# B, [7 O$ H - Session *theSession = Session::GetSession();
\; k0 n$ C$ V - Part *workPart(theSession->Parts()->Work());
: \/ A# r* [) a4 G - 5 x2 v: ?, R9 A4 i
- Session::UndoMarkId markId1;
9 q9 K5 N5 d( ~- K+ t - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
0 y' I# d$ \+ N& e! [) h( c- V) n: k& p - "Studio Spline Thru Points");
1 _& T) p5 B0 A/ \3 ] - 2 k( A9 z; u) w) P& v z9 w
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
i8 w0 K$ i0 e/ }- {6 p8 x
7 e( q% g% k) i7 {5 `. e- e6 ?- Features::StudioSplineBuilder *studioSplineBuilder1;0 E( {( R' P c- f c/ {! P& I
- studioSplineBuilder1 = workPart->Features()->( d. Y; R7 F- S n N6 L
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
% `3 L; `$ m& e1 Y, r- w - studioSplineBuilder1->SetAssociative(true);0 M% J) P! g: L/ Z7 Y
- studioSplineBuilder1->
7 {3 |; }1 [' l - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
# s0 U1 p# q9 O - studioSplineBuilder1->" W( n& u# i' C3 m. d
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);6 K$ g `! E* f9 Z! R$ E
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
c: O& |; R* [, K - studioSplineBuilder1->SetPeriodic(false);
3 s6 K9 x4 ?, v& c' M- _9 q+ s b - studioSplineBuilder1->
, j7 P: l, ^0 M0 u - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
5 c! ?2 D- q+ E! A' _% v - std::vector<double> knots1(0);
1 S/ B' D* k; f( p - studioSplineBuilder1->SetKnots(knots1);4 ?" }. n9 D- N. F$ [& B$ h
- std::vector<double> parameters1(0);7 b" F: [6 _/ m+ Q/ `, U; ]4 j
- studioSplineBuilder1->SetParameters(parameters1);
3 o2 n0 l0 L+ B8 Y: K# t5 A - Direction *nullDirection(NULL);
! X& J$ U2 q) Z3 K - Scalar *nullScalar(NULL);9 L K& U" Z, ~, k
- Offset *nullOffset(NULL);
; o3 U G5 f( u - , Z; G8 I5 F$ \6 T* ?8 Z- h0 U- f
- std::vector<Features::GeometricConstraintData *>2 e4 ^2 b* c" W. I' d
- geometricConstraintData(thePoints.size());' p: F7 t. F% p# u( \
- d z3 ?3 @5 ^/ A T Z+ H7 w/ H
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
; p) p9 ^. @ h - {
; E X7 G6 G% y, s* e8 w - geometricConstraintData[ii] = studioSplineBuilder1->
: Y( C- B* ^! r& w - ConstraintManager()->CreateGeometricConstraintData();* o$ q) y- z6 y4 p9 Z, ~1 s
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);6 t% m2 E9 d$ r$ w4 z' ]- ^& m
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(9 C! R+ H0 f% }9 B
- Features::GeometricConstraintData::ParameterDirectionIso);
4 t0 Q& V; y5 A7 m - geometricConstraintData[ii]->SetAutomaticConstraintType(
& s' P t4 N- y9 { - Features::GeometricConstraintData::AutoConstraintTypeNone);
! u$ u6 Q x* s0 ~9 B9 Y - geometricConstraintData[ii]->SetTangentDirection(nullDirection);9 _$ g9 T8 e3 t1 m, r C
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
- j# X: j. i- C2 W k0 @2 X - geometricConstraintData[ii]->SetCurvature(nullOffset);- O/ Z: s) O, e; w7 F, |
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);( F8 \' z# x6 @/ Z3 K4 T! x# w- ~
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);) R! W" F8 i+ t' P, z, X
- }
, r k0 W6 p6 k% l/ X
3 T' K/ q" g/ d8 ~- studioSplineBuilder1->ConstraintManager()->SetContents(7 t) c! L, ^' u# b' e* C2 p: j! }
- geometricConstraintData);
# Z$ t/ {* R3 c3 E" V8 t& g" k5 U" r
, n. n& }7 x7 D3 |" c1 |0 g- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
( ^6 A/ q5 F$ } b1 m. c4 S$ i - Spline *theSpline = studioSplineBuilder1->Curve();
' r) M5 ?% `2 g/ n
0 _$ }" N6 g" x: F. k- studioSplineBuilder1->Destroy();
0 f8 k0 H/ X6 M3 D! D( x; }4 C a( X - , F% a4 t& d% c2 c7 o) \: S1 z
- return theSpline;( f6 s2 b3 j7 W$ H
- }
- V5 ?- @! ^4 t, c1 [/ e3 P3 g - 6 J7 T- K' ?* w- d* p& D
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
1 _9 w; S3 P1 A1 y$ F2 ] - {
) f8 a. z% D7 U6 j) d# [1 W8 N: l% a - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");1 N) L: B5 K+ V; y# x4 E
- if (!thePoints.size()) return;- f7 B. z. k" J
/ W! f3 v- i7 `0 o2 g; ]; A- Spline *theSpline = createStudioSplineThruPoints(thePoints);
; k/ W7 ~8 L% N- K$ q* \ - ) t2 l6 o1 C! i9 H% r
- if (theSpline)
' {3 [/ u. x3 a7 ~1 U+ d: O - {
& F% L& k& E3 V' d# z% B% ~ y - theSpline->Highlight();# K8 u9 ]+ \; o" ^1 w5 d
- uc1601("Studio Spline Created Thru Points", TRUE);
, F; ?2 C; n( J/ s1 O7 R& o# \$ z5 Q$ ` - theSpline->Unhighlight();) e) h6 g4 y. E/ L7 V6 A
- }' W# c; b# L, A }0 c
- }
) H8 z' b4 ~) v9 z
复制代码
2 F. ~) i7 a9 X! ~0 ?1 @
2 v" |8 g0 V+ k0 h, y- F3 C
$ i- I# u" M+ V5 d$ {; m |
|