|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
* o, | i& ^9 b- #include <uf_defs.h>1 s: @, c$ c4 s8 i- F2 C0 V
- #include <uf.h>$ i1 i; J3 ?$ z R! x1 y- i
- #include <uf_modl.h>
- X% Q0 [. }! W! { - #include <uf_object_types.h>) G6 }, ?6 N% [* f
- #include <uf_ui.h>/ @ J4 s9 ~4 y% J! F4 q2 l. Y
- #include <uf_modl.h>
( h& R8 r' ]6 R* a z8 B' I. t, h, S - #include <NXOpen/NXException.hxx>/ a5 [: Y' l8 N R
- #include <NXOpen/Session.hxx>6 F. E6 f _1 p# D8 H, F0 V
- #include <NXOpen/Selection.hxx>
7 `6 v7 w" B- w6 Z" N7 R/ C - #include <NXOpen/Builder.hxx>
% M: b% X, c' j - #include <NXOpen/Features_Feature.hxx>
" }4 y/ D1 c- n - #include <NXOpen/Features_FeatureBuilder.hxx>
# S( q0 B3 P5 R; K, x$ g; N/ v - #include <NXOpen/Features_FeatureCollection.hxx>
, z) B0 _) K- @" k- _1 d - #include <NXOpen/Features_GeometricConstraintData.hxx>
. {- A- g* f: w7 Y4 V - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>0 ?+ G% r* ~6 i4 i" E1 h1 Q
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
* E6 C8 C* U$ C3 D- e" @) }. a - #include <NXOpen/Part.hxx>
) h# U8 G4 S( E$ ~ - #include <NXOpen/ParTCollection.hxx>
) v) k) I+ V4 _- Q9 t) a# z - #include <NXOpen/Point.hxx> e: Q+ X7 v- W) Q
- #include <NXOpen/PointCollection.hxx>* ?) J- @$ `7 \% [! v3 k
- #include <NXOpen/NXString.hxx>1 Y+ H& M' b! h& M& r( b: H
- #include <NXOpen/UI.hxx> u- R8 e/ o+ o( S) X; Z
- #include <NXOpen/Spline.hxx>% Y3 @0 E( ^' t9 e/ K& ~! A) A3 e
- #include <NXOpen/NXObjectManager.hxx>
8 M/ e/ W Q+ a" n% n - ; V6 H9 |3 a% E/ A4 \
- using namespace NXOpen;" [$ ~: n3 J" |" B8 d% w9 C3 _
- using namespace std;
. r$ L# E D4 y6 u: p0 U - 9 V) t! r* ?6 ~& W' J: F! L- s
- extern "C" DllExport int ufusr_ask_unload()) ~2 |0 K" o- _/ x; i
- {+ G2 i y, Z! D. c0 C J
- return (int)Session::LibraryUnloadOptionImmediately;) ?2 k2 Q' j# h- R/ a9 Q
- }$ V) W6 k+ C) J$ H
/ ?! M4 p' Y8 @+ c* B/ j- static vector<Point *> selectPoints(NXString prompt)
! T# v( u( I( \ - {) `5 J6 {3 r9 s
- UI *ui = UI::GetUI();) Q' ~0 N( ~: x- U9 D0 ]9 G. t2 J
- Selection *sm = ui->SelectionManager();
( t" y: \7 g+ d3 Y. k" n/ f - std::vector<Selection::MaskTriple> mask(1);+ d" Z, U, F0 N, M- `/ { }
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);9 [* ?: z3 \- q( L' V( G. p. o
- std::vector<NXObject *> objects;/ M% O! j ]+ ^- e, i
- 9 f9 u4 Z% K) k: G! C6 s! ]
- sm->SelectObjects("Select Points", prompt,9 [ b# A* _: `; s( E
- Selection::SelectionScopeAnyInAssembly,$ _/ c8 E' z7 f/ ]
- Selection::SelectionActionClearAndEnableSpecific,
4 M3 d j7 @8 B! U/ N. @/ E( H - false, false, mask, objects);
6 ^5 Z( [0 R& [4 t7 r
$ ]9 J' j6 z; \* e- vector<Point *>selPoints(objects.size());, ~: F9 h8 [% A5 F
- for (unsigned int ii = 0; ii < objects.size(); ii++)# j- D4 C2 [! {* k
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
4 O1 O1 W( P2 e6 }/ Z
# ]5 K) o8 ]9 |, Q& i5 K- return selPoints;
% d, P8 p# ]% }4 T6 ?: _ - }
6 D7 q, E. H/ y( j. @' r
3 X5 ]; G u% P$ P- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
' k8 n% ~. \, r) f. S - {
- m/ V; _+ ?) e: S" w% n- H - Session *theSession = Session::GetSession();
9 i; A: O$ |! x9 r0 D- v3 f - Part *workPart(theSession->Parts()->Work());
# N! N5 F7 L! ]$ l( v0 x5 i
1 G) L$ ^. _0 u3 F0 Q3 o- Session::UndoMarkId markId1;
$ T- ` O* X. |" F7 a+ D - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
( _, o V0 ~/ w% i- d( i) d - "Studio Spline Thru Points");
; }% w; Q1 D+ J7 h) } - I% ]# a! K8 H7 L
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
' a- w8 L1 v( y - : [ A; m) A0 w1 r
- Features::StudioSplineBuilder *studioSplineBuilder1;8 `* U/ X7 x/ P4 j; Q( f" L
- studioSplineBuilder1 = workPart->Features()->
0 o y2 X5 q" h9 m6 f, c - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
8 k$ f7 |" e( O! f3 A# ] - studioSplineBuilder1->SetAssociative(true);
. D4 G( n1 p! q4 f - studioSplineBuilder1->. }8 K! g) R, U" x# {
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
9 y/ T. Z" H# X& L - studioSplineBuilder1->
' {. H: {) p F( a$ R! `7 F. ^ - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
4 D3 R( I" c$ q2 m - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
2 `9 }$ D! u; B; M" S6 V - studioSplineBuilder1->SetPeriodic(false);
3 Z/ I: z2 ?0 G: O6 S - studioSplineBuilder1->
+ y' @. P; D6 e5 {. w7 F/ N - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);7 p1 h2 O$ x+ A( y- D
- std::vector<double> knots1(0);+ r# E+ y5 ]1 c6 v( F5 i# u5 u
- studioSplineBuilder1->SetKnots(knots1);
2 Q2 A" |+ Y4 _" t! {9 V. @ - std::vector<double> parameters1(0);
w! t I' R+ z& H# N6 ?; c - studioSplineBuilder1->SetParameters(parameters1);
$ d- P0 Y W7 u4 T - Direction *nullDirection(NULL);
1 {$ ^! u/ |' a& j! V1 f' F - Scalar *nullScalar(NULL);
+ H) P9 {0 a/ g - Offset *nullOffset(NULL);
4 c8 ?, W5 U, y+ t - 4 n4 j& h2 ^! g% E7 E/ F; N7 `
- std::vector<Features::GeometricConstraintData *>
- d8 {$ G7 u: a! n3 e - geometricConstraintData(thePoints.size());
4 _2 G5 L# M* [
5 {4 j4 m; ?; H+ |- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
O8 ]# s, I2 a& A: f - {1 j- [$ _0 {" W, Q- L9 i+ m/ s& W
- geometricConstraintData[ii] = studioSplineBuilder1->% A9 ^! A1 M: T+ Z& ~
- ConstraintManager()->CreateGeometricConstraintData();9 ^& m8 W$ B# @5 }/ H& S. X
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
x3 O7 A1 r: g0 x5 B$ j, P - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
8 K! ~, ]& D% z4 a8 l - Features::GeometricConstraintData::ParameterDirectionIso);
+ n2 I0 X# R3 M0 D" N - geometricConstraintData[ii]->SetAutomaticConstraintType(
, C: x7 J3 F, M- S - Features::GeometricConstraintData::AutoConstraintTypeNone);( b7 b$ |% ` i3 E3 U6 A
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
% X: s5 w- O0 Q8 h& L$ k - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
0 P8 G$ B# N3 n) [ - geometricConstraintData[ii]->SetCurvature(nullOffset);
( C+ p( ]% G ^" M$ ~ - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
& y/ b& O; t+ i - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
% R7 Y5 D) [0 s - }
7 d1 L% } N# }$ I; |; s# i- V% h
- L8 \* c; J- S- studioSplineBuilder1->ConstraintManager()->SetContents(
* ~: [5 p! O I' g, Y! @ - geometricConstraintData);( F5 g' [7 v4 U' k
- , G/ T9 Q7 L9 ?$ @
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();3 p P, k5 A8 `: V* m
- Spline *theSpline = studioSplineBuilder1->Curve();
2 X' ~" N8 H1 |! {- Q9 K - + C( E/ o* g( B
- studioSplineBuilder1->Destroy();* t% {. N3 m% H) r- L0 t9 P5 z
! u' \9 W( x3 V% O' U5 T3 `' E- return theSpline;
8 j/ M- b% h% l0 n0 e. r) [8 a - }6 \5 m# z8 ?+ u9 a
9 o6 r. Y" F( g9 a; P; L- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
; X2 M+ U6 {( V! p7 |1 y - {
+ f( z4 E1 N/ K0 @2 M - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");' B2 Y/ S/ m$ x* [7 U3 Q2 X: h
- if (!thePoints.size()) return;
9 O; w: x9 R H1 L& l+ Z" K, @/ P - " z& j- H1 F5 K3 c. g+ W
- Spline *theSpline = createStudioSplineThruPoints(thePoints);0 x* e" l% A8 ~5 B: D
- 1 x* ]8 Q& | B V: G; C4 L
- if (theSpline)9 g0 v7 G' D$ w# h2 U7 D
- {
) D' N6 @, e" x+ W0 z, |: U# z, R5 K - theSpline->Highlight();
* w6 a( Q' a/ y: } u" t N2 }% ~7 H - uc1601("Studio Spline Created Thru Points", TRUE);8 ?+ n- ]# P+ M7 Z- J1 M
- theSpline->Unhighlight();% o3 A A% z; h# Y! H. R
- }3 ], B" p1 r4 n( V2 Y
- }8 j* W9 {! \+ t. V- [, D
复制代码
, T1 f0 { O- D. \5 u9 @$ ?: l4 W+ Y* x9 r3 u- k1 K- G: M
+ O, Z X: w3 Z$ H6 T8 n/ p
|
|