|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
* ` w) m* C: m! o! x% e- #include <uf_defs.h>
7 E7 `# d" e1 K0 Y m - #include <uf.h>
6 [& Y! v2 X$ z8 G: B k - #include <uf_modl.h>0 ?6 r% N: g3 g1 k
- #include <uf_object_types.h>
# {; h1 I% |5 p/ U, @! l3 d - #include <uf_ui.h>' a5 i# y" D& W$ G
- #include <uf_modl.h>
5 N. [. f$ |3 R$ r) S: @" g - #include <NXOpen/NXException.hxx>
. j' n2 ]" H5 d# e; S: d! W* h' Q/ D - #include <NXOpen/Session.hxx>9 A6 O5 r+ X, e
- #include <NXOpen/Selection.hxx>; P" _5 q0 f3 k7 p+ }; a
- #include <NXOpen/Builder.hxx>
# }/ }( M) s/ u% l: w - #include <NXOpen/Features_Feature.hxx>
% z' [2 z; W8 C1 y - #include <NXOpen/Features_FeatureBuilder.hxx>
: i& L5 \6 L C8 n7 | - #include <NXOpen/Features_FeatureCollection.hxx>1 V7 {# Y" M! K- y. A
- #include <NXOpen/Features_GeometricConstraintData.hxx>8 a& u& P% P+ O) g
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
: u A9 ` u9 K- v# l' t - #include <NXOpen/Features_StudioSplineBuilder.hxx>5 Z- Y& H$ Q( H* A) l7 D
- #include <NXOpen/Part.hxx>/ L; c3 l9 B2 H! H
- #include <NXOpen/ParTCollection.hxx>" Z5 J9 F! L- O0 x& b
- #include <NXOpen/Point.hxx>6 z) f) i: y" T# f7 y. |
- #include <NXOpen/PointCollection.hxx>4 {5 }9 U: P* V
- #include <NXOpen/NXString.hxx>) E- h, h8 h, h" K+ E6 c
- #include <NXOpen/UI.hxx>. ?& @% f8 Y7 T o
- #include <NXOpen/Spline.hxx>- \& c: k$ y$ x% l
- #include <NXOpen/NXObjectManager.hxx>" \" z5 A5 m' r6 [) ]" ~
- $ a1 k6 w4 F6 _- k) [% C" B& {
- using namespace NXOpen;. Z: L5 c9 s+ v, w
- using namespace std;
4 U! n8 C3 ]6 M7 t g9 t/ d - 5 b9 h6 h% a' E! d4 C' P
- extern "C" DllExport int ufusr_ask_unload()
( M- x3 a3 U7 C) {% _: M - {
2 U5 `) R# e+ G5 s5 L( C O% n - return (int)Session::LibraryUnloadOptionImmediately;
; ^, J) `/ l6 U4 R& L9 r( U - }. F0 h" ~% ~+ f$ p" d( }2 b
- 5 e) g& p$ z0 O) u3 }% C3 P" _
- static vector<Point *> selectPoints(NXString prompt)6 F/ |7 W5 K4 t/ |& o$ I, X
- {7 A# W+ j& \; _. R- B3 \) L
- UI *ui = UI::GetUI();
! ^0 t; Y: I" M3 c- n* g - Selection *sm = ui->SelectionManager();
& L5 E/ d# D2 L& c) y/ }3 y - std::vector<Selection::MaskTriple> mask(1);6 t& L4 v7 _2 r4 c' @
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
. k, e6 r& T# [9 d+ ? - std::vector<NXObject *> objects;2 }2 v* N x( q% K% N
- " q6 m8 h4 K7 K h% i4 W
- sm->SelectObjects("Select Points", prompt,
5 _. J g- B. i* l1 j7 g, c - Selection::SelectionScopeAnyInAssembly,0 o/ F' G$ w# A5 d5 g4 w; ?; E0 e
- Selection::SelectionActionClearAndEnableSpecific,
+ A, E; _! [" w: X3 i - false, false, mask, objects);5 D' \1 g8 {, \
- + m( n8 D* q2 G: j6 E8 i% h
- vector<Point *>selPoints(objects.size());& K6 I! g; }3 P: D3 q, U) X* i1 N
- for (unsigned int ii = 0; ii < objects.size(); ii++)0 v- E& U" u7 M6 y9 b4 I# K
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
; y0 r( g) S7 P% S" u+ G, O - ' M% b9 l9 |# M3 V5 \
- return selPoints;
' U+ @% m. \( B - }
) y& e4 C" X7 c: r2 z
4 f# T( k3 J, b! ~- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)4 [: d' e& R2 j. h& _9 |
- {
9 C2 R) n4 ^9 D* n# U - Session *theSession = Session::GetSession();
: C% u1 c+ I& I# S* I" ^8 D( w - Part *workPart(theSession->Parts()->Work());
! u* h, Q$ x2 J: u+ L
. V/ d2 h0 J2 M2 v8 l- Session::UndoMarkId markId1;
4 o/ b) J2 Q+ }% y$ P" E8 l6 V - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,, B% n/ V. l% T3 p: ^* n8 ^
- "Studio Spline Thru Points");9 k, j& n- r6 s
- 1 y, W! q' ]0 {# y
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
% m3 f3 @$ E' G& l! b. A, M, j
4 T1 J( H: W3 w8 _* P- Features::StudioSplineBuilder *studioSplineBuilder1;& j( H& X2 F4 v5 N$ b
- studioSplineBuilder1 = workPart->Features()->+ g, s T2 `# M7 Z
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
# P9 {! }! O4 k, s# M - studioSplineBuilder1->SetAssociative(true);+ I' Q$ g& `4 [9 Y+ b! e
- studioSplineBuilder1->
) g6 O y- a1 z3 ^0 @ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain); y% q4 F' A- B$ J. |
- studioSplineBuilder1->
4 |9 s) I8 t2 y$ G4 s" \3 | - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
' k, X1 B4 k/ |1 M' a6 U - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);. W+ ]! j7 O: q+ }) E
- studioSplineBuilder1->SetPeriodic(false);
. |! v& P% @; a/ N8 M7 m - studioSplineBuilder1->
4 u+ o U5 s: _; p9 w+ r - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. n( V r8 S. F5 e) y
- std::vector<double> knots1(0);; ~ o4 q/ u( w+ G2 v5 z
- studioSplineBuilder1->SetKnots(knots1);
# r. E$ ` X2 J( q4 u% W; ^ - std::vector<double> parameters1(0);
) Z9 a- a) ?$ ^* w5 o# b) s - studioSplineBuilder1->SetParameters(parameters1);! g; z' @ a2 p9 d. L$ i; A
- Direction *nullDirection(NULL);5 C4 \( g, H- Q. A5 j" j& j
- Scalar *nullScalar(NULL);
: n4 J* ?; d. G8 B8 [ - Offset *nullOffset(NULL);
) {& c4 z/ Z. V( r P - 2 \- X4 i/ u" w+ `! @/ F
- std::vector<Features::GeometricConstraintData *>
* D; Z7 S* ^0 `6 f( a W - geometricConstraintData(thePoints.size());7 ]# o' J- Z) k h9 U
- 6 f3 x8 n5 b" g! R
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
9 r n1 r, d' T1 \6 l3 [ - {7 I; \8 S6 Y) T* K- m
- geometricConstraintData[ii] = studioSplineBuilder1->
! {/ L( O5 k% o J9 s, F - ConstraintManager()->CreateGeometricConstraintData();# `9 l' r; d9 k) e- y
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);; V& R- v7 \( t3 h
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(+ v. ^7 W% t! n8 {+ C
- Features::GeometricConstraintData::ParameterDirectionIso);+ L, g, m H5 m
- geometricConstraintData[ii]->SetAutomaticConstraintType(4 r% o) f3 {& a
- Features::GeometricConstraintData::AutoConstraintTypeNone);
" F/ q9 H, N- M6 ?% Q$ c; u$ C1 X! g - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
: [; W: S j8 ]* \ - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);0 l# |% m" }( q% T7 D( |
- geometricConstraintData[ii]->SetCurvature(nullOffset);
- Q/ G! |9 P+ c* l+ L6 [ - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);3 W3 k/ B2 `; B6 R; X% E! Y
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);2 N( |( E& v% c. @5 z% u8 C0 ^
- }( |6 v |+ W, C! i+ h* q
- ; ~/ L, F# r, m( V# Z' Q; v, B4 C
- studioSplineBuilder1->ConstraintManager()->SetContents(
' ~* \* P8 E$ a1 w U - geometricConstraintData);
. j/ ]- W6 b7 ]3 a* t$ E! h' a, [ - - g w' b0 ^; U" w+ Y
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
9 V+ } b! J/ p, Y# x0 }3 y - Spline *theSpline = studioSplineBuilder1->Curve();8 ^( r, d, _% g) }% x# f
P, S% v3 C0 J3 G7 J0 ?* b- studioSplineBuilder1->Destroy();1 L$ X0 u; |) d6 v* d$ N8 N
2 a# r* {) v- Y- return theSpline;* s& F0 m0 _5 z, M, u8 k( J4 j
- }
9 m# b+ E C1 q, {8 @
, \, q, F( |) i' ^& y- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
( J* m* Z9 n! D+ |3 d# ^$ V - {
0 k/ x8 Q7 a4 }( X - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
# q$ r- X: A7 E2 S. J" g - if (!thePoints.size()) return;
' Z3 F P" k' J- N% F, d2 @ - W0 b' U5 M: j& A$ l
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
$ b- l9 ]2 q! M" m
& u5 G0 V; o+ x$ U) V- if (theSpline)' a# R5 K' P) `& ^- H2 C
- {2 {! M( h$ W, T; q
- theSpline->Highlight();
, _) F& Y$ c0 w - uc1601("Studio Spline Created Thru Points", TRUE);
( A7 j a1 |8 |3 E% y& D6 e9 J - theSpline->Unhighlight();
* v" t# f% D' f4 ^ - }8 S a% p' O* U7 u' {7 ]' k, F+ a
- }2 s, j: {3 F6 z3 T4 R# B
复制代码
. v: B4 E2 Q/ Y$ G
3 {' H9 L I; I' k" o$ G8 C! e6 q$ @
|
|