|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
* i3 ]9 J- |. ~1 H* Z' o- \( K- #include <uf_defs.h> T( @9 V' r, M- o1 }) {
- #include <uf.h>
: A9 e: j1 ~ D+ M& _ - #include <uf_modl.h>
9 t0 I% e/ @& G+ t+ d! R - #include <uf_object_types.h>
1 W) D; z1 t$ F: R - #include <uf_ui.h>
0 [7 j. Y H4 ~- q - #include <uf_modl.h>; d, v8 I: K- F6 c
- #include <NXOpen/NXException.hxx>, w' f0 j5 Q/ [7 M, g
- #include <NXOpen/Session.hxx>( I$ P% E* f( K6 \" y
- #include <NXOpen/Selection.hxx>
, E! k) M- m4 k( {0 a - #include <NXOpen/Builder.hxx>5 [: b; _3 w; Y0 z3 A; j2 b
- #include <NXOpen/Features_Feature.hxx>) v5 _8 T A' x, E
- #include <NXOpen/Features_FeatureBuilder.hxx>
' K1 V% B, ]0 V1 o/ y - #include <NXOpen/Features_FeatureCollection.hxx>* _) p+ X. y+ M$ S
- #include <NXOpen/Features_GeometricConstraintData.hxx>
8 ^6 @( V- {# l1 r% X: m' I - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
3 {& U: | n% [* d" s7 R( i! k: P - #include <NXOpen/Features_StudioSplineBuilder.hxx>6 \6 C/ ` }: t
- #include <NXOpen/Part.hxx>8 {( o: L7 L. I% y
- #include <NXOpen/ParTCollection.hxx>7 G x7 w |2 i
- #include <NXOpen/Point.hxx>7 x9 h' P" i* }9 y% C5 Q
- #include <NXOpen/PointCollection.hxx>- B8 I1 j( c" S$ }: O
- #include <NXOpen/NXString.hxx>
7 a g# m9 t% K - #include <NXOpen/UI.hxx>
& s) Q! V7 ^: R `0 v, k7 A$ B - #include <NXOpen/Spline.hxx>0 n7 m+ M* U- j1 D. p
- #include <NXOpen/NXObjectManager.hxx>! U% o6 [* f- [5 z1 t
3 T* ]5 [' c- }( @* X- using namespace NXOpen;
; t! ]$ W1 M9 K/ M. v" c - using namespace std;
C8 D1 z. {+ Z6 l1 v - 5 |" t, X4 z3 k5 [6 i, C+ r& G/ \: c
- extern "C" DllExport int ufusr_ask_unload()
% V6 N) T" j9 S+ m$ m - {6 T+ _7 H! H& q5 z: k+ E
- return (int)Session::LibraryUnloadOptionImmediately;: m6 _- [- Z* k% r& s
- }. m D( P3 O5 O; t5 r. {) y9 T
$ Z# p) g- }* }' a- static vector<Point *> selectPoints(NXString prompt)) W! w6 S4 g0 d
- {0 Z9 q/ M' j' b4 q
- UI *ui = UI::GetUI();- H' N, Z) G- f1 ^8 Y3 w- K
- Selection *sm = ui->SelectionManager();+ W) ^9 Q" A# p( N
- std::vector<Selection::MaskTriple> mask(1);5 A$ S3 `" e; T! V, p& L1 W
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);- v1 i [8 a( e& O; c( Z. Q- o/ W
- std::vector<NXObject *> objects;, q5 D# { {. }, Q/ H. `1 s
- ' v2 S" b# T3 c9 B( l
- sm->SelectObjects("Select Points", prompt,, s2 J- m F. B- l/ q, _" b( c
- Selection::SelectionScopeAnyInAssembly,6 |+ j( n: B! c6 b( D% h: |8 {+ X, x
- Selection::SelectionActionClearAndEnableSpecific,# L) }6 w9 T! i; T+ |2 y$ @
- false, false, mask, objects);) N6 B2 K# _1 j: o- s2 j7 g1 \
- ~, h# n$ `* J) `1 e$ M, t
- vector<Point *>selPoints(objects.size());
0 F7 ?6 W* J- K' e ` - for (unsigned int ii = 0; ii < objects.size(); ii++)
, c' x9 D2 h& V6 P) R! e - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);( N6 g5 h7 G0 |) |
* I- N1 y9 r' ^% S7 L/ X- return selPoints;2 ~* `2 f$ K5 ]0 d: o( Z ~
- }
# V( |8 @( C# T @& u0 ~4 M1 j5 V
4 u6 u+ U9 a E# a5 D2 U- t: l- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)" @) x) {$ f+ L
- {$ C) d* `' L5 C. f" i
- Session *theSession = Session::GetSession();' G: o* Q+ I/ V
- Part *workPart(theSession->Parts()->Work());( q! M$ c* L" O* Y& W
* K- w5 R6 B4 y$ @, Z8 F* A- Session::UndoMarkId markId1;
1 [" |6 W7 B% k5 G4 b: n6 a; X" i - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
' p8 x3 Y2 a9 f/ q6 K3 T- O - "Studio Spline Thru Points");& U" O @, L! H2 S- e' W8 F$ a
- & x; D/ S* N4 O: x6 m: t O
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);- G' ? h3 M& E) ^0 i
- t; _9 @- U: D a# ^5 q( j0 C$ w
- Features::StudioSplineBuilder *studioSplineBuilder1;
- T& C( d; |" L - studioSplineBuilder1 = workPart->Features()->* ?7 {7 \1 C% h0 c
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);- ~, d$ O$ h& t. p
- studioSplineBuilder1->SetAssociative(true); h/ o$ G# T, Z, F
- studioSplineBuilder1->8 W* S6 b- l* X1 k( C& w5 C
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
- }4 E3 [! K8 X( V% V7 ] - studioSplineBuilder1->
, }9 g% X8 M5 p4 M5 L - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
$ H2 m2 e& }4 ~ [+ W9 D, Q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
$ ?9 K/ K+ s0 m- Y' R! S, q - studioSplineBuilder1->SetPeriodic(false);) P; \* L6 B/ i% ~! A/ }3 K
- studioSplineBuilder1->
- ]8 u- F# {7 X# a2 V* u# z l - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
. l* A' q# z1 r# j* I, h3 g - std::vector<double> knots1(0);
; ]7 p' ?# N$ F8 V9 n - studioSplineBuilder1->SetKnots(knots1);$ w8 }4 f5 L, R6 s2 `- V
- std::vector<double> parameters1(0);
4 v. A' G q: i! Y - studioSplineBuilder1->SetParameters(parameters1);
7 I* ?7 Z% t& o2 r+ |' y - Direction *nullDirection(NULL);
3 Q3 c7 r" ?: Y* r - Scalar *nullScalar(NULL);
" c/ K0 ]+ d5 X* m8 E - Offset *nullOffset(NULL);
" k8 ~" j( Y( }& O
% J! W1 H1 p: r/ W. a- std::vector<Features::GeometricConstraintData *>
+ A- ~$ Q) E3 o$ Q! ~ - geometricConstraintData(thePoints.size());) J- b5 V+ j; }6 V7 N h8 ~& |
- 6 B* u! C4 l/ o" Z) c0 j2 @4 i8 ?8 H
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 |- @5 L& [- K: b8 X
- {0 Z. L: v8 Z* H; [& a
- geometricConstraintData[ii] = studioSplineBuilder1->: r8 h- W M4 n/ W7 `) W: M; w
- ConstraintManager()->CreateGeometricConstraintData();# o- [2 n( M2 U. z, x
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);- c: I! j n( U5 }/ o. g
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(" a6 B; d1 _/ {" H# Q# S- b. T" g
- Features::GeometricConstraintData::ParameterDirectionIso);
* h- t) P1 L8 ~: ~9 H$ L - geometricConstraintData[ii]->SetAutomaticConstraintType(
; ^7 W+ s+ Y) l6 O - Features::GeometricConstraintData::AutoConstraintTypeNone);
* ^2 J; i9 F% b, x g - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
1 m* \0 h: e2 x7 s3 \ g9 s- G$ O - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
' ?2 p4 k c+ z- Z - geometricConstraintData[ii]->SetCurvature(nullOffset); Z7 b( ]2 C1 g) l5 t% G+ l0 {
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);6 R" P- J9 ^! O# ]0 \) T$ j
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);& @1 |/ p1 e: G* `" Q+ A
- }4 G: ]3 M* b* a7 Q, J I8 q1 a5 z$ A
- ) ^! y* S% \3 C1 J- ?- ?/ e. o
- studioSplineBuilder1->ConstraintManager()->SetContents(
1 ?+ C, }! S# X. c( ^. W& i$ ? - geometricConstraintData);+ D9 k" c, h% @3 p0 ~
- & u# t3 h; T4 d5 z" Z$ y' j% m& e# k `
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();) s9 M r, u) |% k* N8 I0 B; }
- Spline *theSpline = studioSplineBuilder1->Curve();
/ ^' L ~3 J3 E - ; M! y% _6 P) |2 f- x
- studioSplineBuilder1->Destroy();
4 k3 e! |, s! A+ Z+ W
) H2 b8 r# F" x3 @' g1 ^- return theSpline;0 ^* @7 N; e) p5 ^
- }# e+ P. [; n3 p; j0 \0 [
- " `8 }6 J( B6 w" N5 [# X+ l1 U- [
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)4 V) k! _6 s, d* L; m5 y" {# r
- {, G% F1 U; z# F; a
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
2 \/ M9 k0 X. x4 f - if (!thePoints.size()) return;1 s( L+ Q. r( p+ k% R( y
! M- A- k5 c8 O5 O% F' l- Spline *theSpline = createStudioSplineThruPoints(thePoints);
2 U0 {" ^: U3 B# n - - R1 z* f0 I7 v; z1 Q4 C
- if (theSpline)
4 k- X1 x2 m1 k5 { - {* W+ _1 q% z1 N- t3 W: D* z, p* Z
- theSpline->Highlight();
5 T8 D+ |% R. ~. m# ? - uc1601("Studio Spline Created Thru Points", TRUE);
: ^- \) e; G3 a7 f% M - theSpline->Unhighlight();: {. c( E' | B4 C5 A. t9 @
- }& @5 g& g/ O& ?: Q9 d
- }! W* e' {; Z, c# e* a7 @" U3 b
复制代码
/ }) V- C: m2 T2 z' k$ @
! T2 G% ~) L' k9 \) e) e' p& c
. A; J! p* {5 }+ E |
|