|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线+ a+ U) E, n) k2 ^( _ z
- #include <uf_defs.h># t4 Y! d% u- @2 g
- #include <uf.h>
1 F( D! G7 f& K& V - #include <uf_modl.h>
- }& f. Q5 X; ? - #include <uf_object_types.h>! @! Q- a0 t) H
- #include <uf_ui.h>
, g( j, |5 U3 U" E8 e/ ^9 |% t2 s - #include <uf_modl.h>
- a0 ?/ b8 U' z5 H6 {" S: ]: @ - #include <NXOpen/NXException.hxx>* v3 _2 T5 `: }& T
- #include <NXOpen/Session.hxx>4 o& Z3 I" w, z$ }5 [0 A# J* t4 a3 h- K# r
- #include <NXOpen/Selection.hxx>; J& C! y+ ]' P- x; B U+ o
- #include <NXOpen/Builder.hxx>2 b0 v0 X y) Z# O5 F! u1 ~
- #include <NXOpen/Features_Feature.hxx>4 _" z: |, g$ {* {
- #include <NXOpen/Features_FeatureBuilder.hxx>
6 }8 y" W* ]" u! V2 c# H - #include <NXOpen/Features_FeatureCollection.hxx>& b( {& X( B; _2 ~5 H9 ?
- #include <NXOpen/Features_GeometricConstraintData.hxx>$ u" K0 g# J2 k& _
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
8 X; P7 X( e, I; U8 Q - #include <NXOpen/Features_StudioSplineBuilder.hxx>
1 x) [2 F! K0 q5 Q, i9 ~7 @ - #include <NXOpen/Part.hxx>$ z r z+ x7 F
- #include <NXOpen/ParTCollection.hxx>
9 n- e6 a5 ~4 K0 d4 w( l- e3 W - #include <NXOpen/Point.hxx>
( A9 s% s* _1 Y- J' Q' | - #include <NXOpen/PointCollection.hxx>
E: U) m# B0 Y - #include <NXOpen/NXString.hxx>
) Y3 o4 i5 e2 O0 A% N$ o) [# p# {4 H - #include <NXOpen/UI.hxx>
; k( U" {( [" G N7 `6 o1 x - #include <NXOpen/Spline.hxx>' P' t/ f" G; T" J2 o ^* {
- #include <NXOpen/NXObjectManager.hxx>. Q3 S" E; n* M1 H4 ^) a, ]- t# H8 J! q
. e) M' S- ?9 k* Q& r/ C- using namespace NXOpen;/ ]0 _& U: a2 `) g
- using namespace std;
2 u% J4 }# v' Y2 j- t6 b2 x' w5 z; u
9 z. g; v3 a: S) f# V- extern "C" DllExport int ufusr_ask_unload()
. e. ` c' `9 T$ O/ r! q# t - {( n5 W3 Q" ?2 H0 d' g% G3 o
- return (int)Session::LibraryUnloadOptionImmediately;! E3 ]# ?/ s0 Q# ?8 H$ v& K
- }
0 M, q9 T2 j* ~
1 Y8 E" W1 p" C) B7 R& t8 C( x- static vector<Point *> selectPoints(NXString prompt)
) q2 O, m% ~& m7 U- i- a, j7 S - {
# i! q; q6 }9 a* L$ ~( C F& Y - UI *ui = UI::GetUI();: P: M8 [: f P8 y) P% d2 C3 Q m
- Selection *sm = ui->SelectionManager();1 Y- A: v' d# X7 R
- std::vector<Selection::MaskTriple> mask(1);* R) y5 Z; j% f. A4 q; J+ e t* j7 }
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);1 t# A/ y2 L9 H, d R
- std::vector<NXObject *> objects;! Z8 d# W# X7 X; E( c- v+ f
- 7 [- B4 s* A0 A3 X! p
- sm->SelectObjects("Select Points", prompt,
2 h O: T- H7 K/ `. [/ i& W. P) U - Selection::SelectionScopeAnyInAssembly,* l( m1 Q) L3 W N" e6 P* S9 l
- Selection::SelectionActionClearAndEnableSpecific,
9 o* F" n! p# s$ O - false, false, mask, objects);8 p/ L( f2 n& i
- 8 W# A5 {& B, @0 e! z- L* `
- vector<Point *>selPoints(objects.size());5 K7 p6 Y4 O+ R1 Y% [9 P7 ]
- for (unsigned int ii = 0; ii < objects.size(); ii++)
% d- x* F' a2 X& V - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
8 p1 D# l" b7 g- i1 s6 o
0 |; C7 x' A) R3 g* l4 a4 N5 k- return selPoints;
* W' h M2 T) T; E: K; T - }; m4 I ^% o% A7 Y6 ]
- - X" P" o& h5 Z* s& `( ?2 h
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). y3 g4 @# S" Y. V h: f
- {+ ~/ ^; c. v0 S' L- l8 [- ~
- Session *theSession = Session::GetSession();0 w! g" X9 D$ d$ p+ K8 Z
- Part *workPart(theSession->Parts()->Work());
. S \ ?. M9 _9 P% o3 O
! q. d1 L. ]# n) x- Session::UndoMarkId markId1;
; b5 b% S/ B8 o, o' S - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
! ~6 q- y9 Y4 X L - "Studio Spline Thru Points");9 }8 \. ?0 x7 Z! Y& z8 S v
8 Y5 c3 d$ q$ X5 T- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
- a0 \/ ?) F, j4 ]# j$ Q
+ K3 I: y. U( d" W. @0 y p7 ]- Features::StudioSplineBuilder *studioSplineBuilder1;
* H4 c3 ]" R" ]4 j; n* q1 p - studioSplineBuilder1 = workPart->Features()->
4 J5 o. k" y) {; c* l R3 x. z - CreateStudioSplineBuilder(nullFeatures_StudioSpline);6 y5 D, q1 C! r1 a' T
- studioSplineBuilder1->SetAssociative(true);
- U7 |; M" f; ]+ p. ? - studioSplineBuilder1->. M7 N9 x# s' [% N) X
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);; C, W# F6 L9 `/ M8 [( t+ y
- studioSplineBuilder1->+ g: z0 J! Q; D9 P7 r
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);; `- Q m: J2 V
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
9 h! N4 B- i+ B: Q5 _ E. n: H. g - studioSplineBuilder1->SetPeriodic(false);
# V. j/ \+ F a$ B+ S; k, I1 s - studioSplineBuilder1->4 i5 b- T& ^- F/ b2 R
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
/ v# U& m4 V+ w3 F ? - std::vector<double> knots1(0); U5 B, ^& o" ^& l- ?8 f* F
- studioSplineBuilder1->SetKnots(knots1);
$ }1 _, S$ S9 Z& ~7 e4 P - std::vector<double> parameters1(0);
; k6 q# n6 l2 w. C - studioSplineBuilder1->SetParameters(parameters1);
M! X: E$ J0 A* [8 A, C6 H - Direction *nullDirection(NULL);
* M# B" ]. m+ Q: a8 h) K' O - Scalar *nullScalar(NULL);
0 f1 o* l. N' R4 ]/ `6 \ - Offset *nullOffset(NULL);
4 u0 ~/ F, ?2 ~* ^
2 B3 m) h9 z$ z- i6 R- std::vector<Features::GeometricConstraintData *>8 ]+ | @) d) u L
- geometricConstraintData(thePoints.size());7 y% Z3 t# ^9 e
- 8 L a% h* X. B% ^) A
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ u+ L3 Q# E4 o" u7 d
- {
+ G K. ?2 @* a9 ^ - geometricConstraintData[ii] = studioSplineBuilder1->
9 l" b, i! n6 u* L8 q - ConstraintManager()->CreateGeometricConstraintData();
9 V3 d: b7 h# A7 y) |# C. R - geometricConstraintData[ii]->SetPoint(thePoints[ii]);& x; t: r4 W8 w0 F5 q/ U
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
8 p# g h. V3 }) E8 ^5 m - Features::GeometricConstraintData::ParameterDirectionIso);: c9 o8 K6 P9 ^9 n- O* V1 w8 n1 Z
- geometricConstraintData[ii]->SetAutomaticConstraintType(* \3 i3 N# y. w+ k
- Features::GeometricConstraintData::AutoConstraintTypeNone);" |$ M, _/ h$ F. o$ y2 b6 z
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ k% h3 G; Y- a: c6 s% J
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
- c- I# p3 H) W' G% g+ r) w - geometricConstraintData[ii]->SetCurvature(nullOffset);2 ~) R; o* O$ @2 A% {; ?, h
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
' [( q3 m0 o- C( l0 d& X3 v - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
' k1 y& J5 i8 h7 s - }
& B! h1 |% B" X7 R* S8 j: P m - ' F/ U& z! d0 Y5 A1 V* E: m- T
- studioSplineBuilder1->ConstraintManager()->SetContents(
' n, w; z* Y+ c- g' A6 B3 ~7 n - geometricConstraintData);* q1 W) V# t: u; p0 f# t# Z$ F
) f1 u% v4 c9 y" Z2 K- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();( F, L# s$ r3 ?. ^' T" y
- Spline *theSpline = studioSplineBuilder1->Curve();# [' h8 h+ w a4 B$ \
7 @4 ^2 N* {# s1 b) Y N0 a& v- studioSplineBuilder1->Destroy();5 Q' B# H0 k. Q9 e5 U
8 X3 \* u7 S7 W2 w1 r- return theSpline;. }" N" Z' D) q( a
- }* |( |0 d$ v! |$ \* b4 K9 s
2 U2 c9 n; i {- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
/ y2 I5 N4 G0 J, d% x. b - {
- P6 \5 ?! ^- D- I) Z2 i - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");6 {$ @9 [6 ?# n
- if (!thePoints.size()) return;
$ U) [! c5 O. w5 u, R$ x: ~ - ! @( i- {6 A, b z6 y% e/ i6 t
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
$ a+ x1 J8 T3 `* x - : R8 p. g1 Y# k* g
- if (theSpline)
! y! z( ?( [$ E3 `/ U - {
; U8 h6 g, q/ A - theSpline->Highlight();
6 D7 C/ w/ b$ T$ @ - uc1601("Studio Spline Created Thru Points", TRUE);
6 s+ z9 W3 W: f% p5 [ - theSpline->Unhighlight();6 o% E3 p5 U( p8 q" s+ b
- }0 Q0 `* s' u4 ]2 j5 m5 ?/ h. @
- }2 s1 [3 _7 Q& l7 p+ G) |- Q
复制代码 ' Q3 U+ o4 y' v' c
" h" c I% J0 V+ m
3 X2 a+ z' c+ W5 s7 ~- i |
|