|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线6 r: y+ K! F: p" b
- #include <uf_defs.h>$ S/ v' m$ Z2 o
- #include <uf.h>
7 U- D8 K% b$ f3 ^: a1 Q - #include <uf_modl.h>: w9 g* \# W, t1 Z
- #include <uf_object_types.h>- W- | Q" V! |" {! P) `9 r$ G
- #include <uf_ui.h>& R/ t: l! _" H: v3 j' L
- #include <uf_modl.h>; j8 q% W) T, j2 d) [8 L
- #include <NXOpen/NXException.hxx>& T7 G' N b0 r3 \
- #include <NXOpen/Session.hxx>
( k" r" R$ l$ W$ I+ e- Q - #include <NXOpen/Selection.hxx>0 j* h# X$ N1 O
- #include <NXOpen/Builder.hxx>$ \, M l+ p- k% {
- #include <NXOpen/Features_Feature.hxx>
" J% b4 B/ K7 t+ E$ O% `0 V - #include <NXOpen/Features_FeatureBuilder.hxx>+ G6 o5 z3 N, b; ]+ l# u
- #include <NXOpen/Features_FeatureCollection.hxx>
: y! t% Z+ M6 i0 s - #include <NXOpen/Features_GeometricConstraintData.hxx>
1 P* `+ ]7 O' w- } - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
) K: u, W( m" d. u - #include <NXOpen/Features_StudioSplineBuilder.hxx>; c7 @' D% q, m9 m; m$ b
- #include <NXOpen/Part.hxx>
* I3 d) @- I9 s" B1 R8 X2 ? - #include <NXOpen/ParTCollection.hxx>
7 z& W$ c1 G8 t- X - #include <NXOpen/Point.hxx>
; j5 u0 }; a0 y' D1 v2 ] - #include <NXOpen/PointCollection.hxx>
# Z4 C, c- P% z. w - #include <NXOpen/NXString.hxx>
* u. k) ~' u1 B0 v" B - #include <NXOpen/UI.hxx>" u" M7 A9 S+ T
- #include <NXOpen/Spline.hxx>! e2 X8 d& n B; b- i& x3 p
- #include <NXOpen/NXObjectManager.hxx>
: t4 R: i( i% Q1 \6 Z$ c9 Y( Y - $ V2 N/ w! f9 l! T+ d
- using namespace NXOpen;3 ^$ ^" v0 ^, Y; U% h4 {9 Y
- using namespace std;- e; g6 t3 D' W6 ~9 W
- Y; b* }* l" X$ V+ P# f- extern "C" DllExport int ufusr_ask_unload(): M$ k5 A, k2 j; b, {- |
- {- g: P& M$ L) u8 G% _
- return (int)Session::LibraryUnloadOptionImmediately;& @# e1 C6 b$ `" \6 s5 t9 }
- }7 c- V3 q4 p- W4 F
- 9 M4 ^+ h5 x# t3 [2 q8 v0 {* x
- static vector<Point *> selectPoints(NXString prompt)
1 Y) q4 r1 j O& E - {
; E% k! V, ?: }- s% T" X - UI *ui = UI::GetUI();: u( ~$ R/ t, i5 W! E
- Selection *sm = ui->SelectionManager();
! E: @% @ _, o9 n' j8 F - std::vector<Selection::MaskTriple> mask(1);* z" i5 m/ k' K
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
9 ]' w/ o2 {/ _8 {6 e: [1 k - std::vector<NXObject *> objects;% ^- P+ I/ ^' Z
7 P) e8 Y! P: s$ M! ? e2 b- sm->SelectObjects("Select Points", prompt,
3 E3 Y4 y0 P9 r6 ~; D& U - Selection::SelectionScopeAnyInAssembly,
( B/ x9 ?) f @ - Selection::SelectionActionClearAndEnableSpecific,; M7 Y* C) B0 h- S9 K
- false, false, mask, objects);
, B1 K! O0 Q! h, ?% H* W
3 N& ^; P3 V! j. {- vector<Point *>selPoints(objects.size());5 t6 A' |" B: U D ~* ?& y
- for (unsigned int ii = 0; ii < objects.size(); ii++); H" \$ g2 o! }8 t/ G
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
( E3 V0 M5 ^0 W2 c8 h; k; O! Z7 t
! X. ~5 U! T' @/ x; w1 @7 Y- return selPoints;7 F- Y4 O2 E- z. a8 ?
- }6 @$ H7 ~. `$ @1 Z2 N
/ v" A% \" p6 c0 T* i8 v8 W- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)" r# I$ I) ]* T& B( j# t+ |
- {
# m6 T- b6 J8 n2 T2 a" u1 n - Session *theSession = Session::GetSession();
1 n5 G6 @/ H. `4 A) U3 R- s2 X - Part *workPart(theSession->Parts()->Work());( B1 f" x8 m1 a" p
5 P! r% m( M. i) B& A8 m- Session::UndoMarkId markId1;
. s `/ U) S3 ~* u3 C4 J! o4 Q5 R1 W0 K - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
9 h* K* G! R& S8 {7 W - "Studio Spline Thru Points");$ O, |2 y( ?9 w# K+ d
- % @0 D1 s5 X8 J- Y* L: T
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);+ u! b% o$ J0 Z5 }2 V z
7 P; h* k( L+ X7 y, s; F1 k- Features::StudioSplineBuilder *studioSplineBuilder1;
- X- R7 M) l6 J7 y - studioSplineBuilder1 = workPart->Features()->
" ^3 F6 x2 X- Y# M8 C" c7 h* Y - CreateStudioSplineBuilder(nullFeatures_StudioSpline);1 l$ ^! M. N/ ]( O- _/ y8 O2 i9 t9 D
- studioSplineBuilder1->SetAssociative(true);0 E( F. W$ Y) g, L: w5 x3 R/ b
- studioSplineBuilder1->
/ V7 B5 `; {% u- D% W7 k - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
" Z3 C. w% y* s( ^# n' ?- Z# m - studioSplineBuilder1->; X' H) Z9 c1 ~4 |9 T" o: o
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);) D* t2 Y2 m2 i; C
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
. o5 l) }+ C. `8 h - studioSplineBuilder1->SetPeriodic(false);2 P( Z% U+ F- \+ T' M" s/ p3 R, X
- studioSplineBuilder1->- P0 f4 z! x: H4 `
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);5 P+ W9 a5 q& k3 m, O
- std::vector<double> knots1(0);
; B4 b- P! `- D8 Z - studioSplineBuilder1->SetKnots(knots1);2 {) v7 M3 Q) u
- std::vector<double> parameters1(0);
5 `. S( D$ k, I) f - studioSplineBuilder1->SetParameters(parameters1);
0 ?' B1 l2 G) C& b* C - Direction *nullDirection(NULL);
! J4 u& ?8 v2 c2 c - Scalar *nullScalar(NULL);
O' q( b6 Z7 ?2 Z - Offset *nullOffset(NULL);& q/ T- S. s- B4 T
$ F, K; n T7 W+ n6 [& w1 \! D$ T- std::vector<Features::GeometricConstraintData *>
4 P" x+ O& G$ X* u: \; }* B, _ - geometricConstraintData(thePoints.size());
/ R S7 d. v2 `3 G7 T- R, v6 Y - + o4 e. c1 `, x1 b( x. W6 ]
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
4 j+ _" W( o U1 Y- d8 q; E3 V, n8 T5 O - {# N: `* p; [0 ]" _ {
- geometricConstraintData[ii] = studioSplineBuilder1->
8 H, C# a% I ]1 c/ n8 q - ConstraintManager()->CreateGeometricConstraintData();4 k( c# P) ?; i% b" O* R! Y, g( a
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);: R3 g! C/ I C3 m9 ?9 W8 I/ \
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
# ^7 m3 [" C5 v+ Z0 _5 U - Features::GeometricConstraintData::ParameterDirectionIso);- e# q0 ~9 m4 {( c
- geometricConstraintData[ii]->SetAutomaticConstraintType(
2 k D2 f$ N1 ~4 s3 g1 [# j - Features::GeometricConstraintData::AutoConstraintTypeNone);2 H! w6 I% I8 p* A- ^
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
! F( ]. q* b+ b/ o6 ~0 t- A - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);) [) s, Q1 I0 N! p
- geometricConstraintData[ii]->SetCurvature(nullOffset);- ^; }5 Y: o3 ~" B7 ~& m7 ^( l
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset); [1 ]$ R, Z. i9 q0 k' p& x) e
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
y8 X) l& w* T4 f - }, z6 a' e; K+ b4 J( s
/ A+ t9 k! G% }+ I- studioSplineBuilder1->ConstraintManager()->SetContents(
; t( _& `9 C$ I* I2 K& v - geometricConstraintData);
4 V: {+ X# ~1 x
, L; `" C% s7 z; \- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
2 o/ v8 K6 J% q: m. l' @0 X5 V3 h4 A - Spline *theSpline = studioSplineBuilder1->Curve();, g, m* O# l S$ E- ^( F, A# I2 I
- 1 c0 T( \$ g4 d' h0 `# Z
- studioSplineBuilder1->Destroy();
s3 Z4 @$ U1 V5 d) h0 i. e* A0 o - " |! V/ }. |, B b
- return theSpline;0 I( e4 d2 `# c Z) H' l' q2 G
- }
& C& M3 x$ j1 k) k7 w8 D) }
' O( _. |& F m f) z- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)2 S2 k5 x1 Q$ a7 v1 W$ ?! k) [6 E
- {
1 m& b' e3 T) c' v - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");- E4 }3 E$ Z6 [" O& K9 F+ H6 P
- if (!thePoints.size()) return;
4 P' W8 k+ i7 R1 k3 a
- R8 e3 x9 Z s9 N4 y- Spline *theSpline = createStudioSplineThruPoints(thePoints);
. B) h' F3 a+ n+ E
) l& d e8 n. F# M/ ^. Y- O" Y- if (theSpline)
' k" a2 q% c& ^* L7 h. B( S- w: F - {
$ Z% h+ s1 J- U) R+ O1 `4 x - theSpline->Highlight();; n% W( D. z; G
- uc1601("Studio Spline Created Thru Points", TRUE);! w. B9 x$ ^0 ~! y4 z, S0 |
- theSpline->Unhighlight();8 N6 d) w2 m9 j8 O6 u8 R' V, ?
- }
6 [* B1 `! f6 t$ E% H' v - }
1 i( t7 W/ z4 M+ M; {& ?- V
复制代码 4 \" S- \- \: I* C
* R& j! e1 A& [; H; T
Z% X, J6 s/ c; m
|
|