|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线, q& W$ W S( \3 Y
- #include <uf_defs.h># e' u4 f. d2 H
- #include <uf.h>" A9 u$ X- Q1 b t" M6 C. C, T
- #include <uf_modl.h>+ w+ ?& Q; p% u% T
- #include <uf_object_types.h>
" r& n* w# O5 n - #include <uf_ui.h>
; a, M& e) L F" h* j! E+ T - #include <uf_modl.h>
7 B* m' e, A+ x( x) c2 Y( L8 ] - #include <NXOpen/NXException.hxx>
$ w4 t9 i" a' Z% K9 ] - #include <NXOpen/Session.hxx>* T! q! ?. T4 s p
- #include <NXOpen/Selection.hxx>0 |- L5 B' m8 Q* n j8 O7 d
- #include <NXOpen/Builder.hxx>
' J \6 n" @6 ]% h& @% p% ~% ` - #include <NXOpen/Features_Feature.hxx>: T% [; I/ t4 {* H2 ?& p
- #include <NXOpen/Features_FeatureBuilder.hxx>
2 ^. P: z& D$ K1 D- F0 h - #include <NXOpen/Features_FeatureCollection.hxx>
$ A+ C( R' j0 Y! c - #include <NXOpen/Features_GeometricConstraintData.hxx>6 _2 C( d* s, C4 Z
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
r& b/ G4 {. s, J - #include <NXOpen/Features_StudioSplineBuilder.hxx>6 i8 N* _) }# o( u; E3 f3 {+ R
- #include <NXOpen/Part.hxx>8 s, \0 P, j( m8 m- \8 I
- #include <NXOpen/ParTCollection.hxx>" @. ]' \* L- m; _% [ F; Y
- #include <NXOpen/Point.hxx>
5 A' h; r, W, @% B" ? - #include <NXOpen/PointCollection.hxx>6 E8 ^& O1 }* O/ q# ]# I) ]% {
- #include <NXOpen/NXString.hxx>. _4 W# I/ Z8 Q; A7 a
- #include <NXOpen/UI.hxx>
# N* D" r6 ^. F* C - #include <NXOpen/Spline.hxx>- H5 C! r" Z0 N! P
- #include <NXOpen/NXObjectManager.hxx>6 I; ~ O+ `" {
- + m: G7 i# X' L5 {$ i2 ^3 T
- using namespace NXOpen;1 ]) e, z% \. a5 Y* ~1 U
- using namespace std;
. }3 a* O( \2 M - 2 Z. z4 N. @) N; y% V8 h
- extern "C" DllExport int ufusr_ask_unload()+ U( D/ m- r! K( j
- {* U9 \( T# h* H9 |% P7 a
- return (int)Session::LibraryUnloadOptionImmediately;5 d/ B' f5 X, C0 U& r
- }9 x1 z& V! ?$ a: C! @
" i* ]5 ]; G; l2 {; p' P+ {$ V4 g- static vector<Point *> selectPoints(NXString prompt)
; f" n- C- w4 j( c+ m G - {
2 D, C% J% @9 U - UI *ui = UI::GetUI();
) l% M( o; A: u$ P0 h - Selection *sm = ui->SelectionManager();
6 y. E7 h# K1 v" s. S2 E' l - std::vector<Selection::MaskTriple> mask(1);* z6 ?2 ?7 V) K. S4 N
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);6 W% d l0 H! J8 N4 ^: G- t/ ?
- std::vector<NXObject *> objects;
3 b% [3 p1 v! ], g+ \ - - H5 X% ?$ q" l4 V
- sm->SelectObjects("Select Points", prompt,
) T( w U, d' a4 Z" c - Selection::SelectionScopeAnyInAssembly,
+ d! E& K/ N: V- R/ z- f. Y+ P - Selection::SelectionActionClearAndEnableSpecific,
5 i/ U4 |& w/ b( E' \ d - false, false, mask, objects);" Y+ m) J. q( q1 p
- + O, c/ h: C' M) n* c
- vector<Point *>selPoints(objects.size());5 P" g! l, Q% |$ C- i
- for (unsigned int ii = 0; ii < objects.size(); ii++)
( }1 [) ~- X& V - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);0 ^1 A2 Y! A! S1 W; X: f# I
3 D. q1 `' {# t# L, u- return selPoints;
7 D. r# M/ k) R& N7 p4 s - }
$ S& n2 J- _/ ]6 V6 P* H+ n* U - 6 f; L" g' w% V0 U
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
/ d0 c, j! J: \2 X - {
# n# R8 l; K# K7 x" n5 A - Session *theSession = Session::GetSession(); h+ X+ I3 O B7 H9 n
- Part *workPart(theSession->Parts()->Work());: Q4 N2 z# E* y; r, E2 k" n
) U3 p" V: f3 t8 b" |2 M* x- Session::UndoMarkId markId1;/ x' ?0 U( T3 K' q' i9 k' ~" Q0 D
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
' E" z+ l) W) }5 u - "Studio Spline Thru Points");1 Z7 B3 \# B1 U; W* ^4 Y4 y/ `
- 4 w: C# H6 `5 I; F6 d# _
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
, a" z4 t( J! {" Z- V! R8 n O - - `/ Y/ Q t' R1 R
- Features::StudioSplineBuilder *studioSplineBuilder1;
" k4 T% Y6 P" _0 W1 N: l0 q* R - studioSplineBuilder1 = workPart->Features()->
. U! d( S. q3 y" S8 ` - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
9 a3 l1 b: }, h% e - studioSplineBuilder1->SetAssociative(true);( D2 c" U7 A' m
- studioSplineBuilder1->
( m( L7 I8 W; Y( |4 j - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);& {; _& \5 u4 \
- studioSplineBuilder1->+ d( S, d m; C8 K1 }
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
+ o9 o4 i5 n3 g# E a - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);& [4 w4 T# Y' L, ?
- studioSplineBuilder1->SetPeriodic(false);# A. v: S d! B' {
- studioSplineBuilder1->
+ a: u( i$ E+ N3 i; Q - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);. n/ h; Z0 e. c+ z) R4 c1 V3 [' m. p/ e
- std::vector<double> knots1(0);" ^& L. F4 ?; k( l# H1 F
- studioSplineBuilder1->SetKnots(knots1);
- _% ^' m% {, L) L3 J. q0 | - std::vector<double> parameters1(0);! i/ l. B# B/ Z5 j2 ?
- studioSplineBuilder1->SetParameters(parameters1);
0 Z. b5 d, c: U" p$ t - Direction *nullDirection(NULL);
; W& {& @8 ~! Z1 m. D - Scalar *nullScalar(NULL);( ~0 A6 s$ ?/ u; u
- Offset *nullOffset(NULL);2 q8 ~; }4 I! z$ o
h; j( ^ C1 b2 E9 K, {- std::vector<Features::GeometricConstraintData *>
$ f0 w: |2 W4 M# I6 Z* j1 t0 m - geometricConstraintData(thePoints.size());' r$ q2 Y+ ?( |- k
- 9 `' r7 M$ s7 t; {
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
& F: @" N4 Z. Z' r" Y" ^ - {- U9 }1 S% ~* {4 I& {% ~8 Q5 H0 G6 s
- geometricConstraintData[ii] = studioSplineBuilder1->
3 H# _7 P, O- ]9 a1 \4 Z0 E - ConstraintManager()->CreateGeometricConstraintData();: B* @+ {8 d, h* b( C- M
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
8 |! x. v6 q7 j9 b$ B - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
+ m4 i0 B* r% m) W - Features::GeometricConstraintData::ParameterDirectionIso);
" D. ^, N1 ^8 f! `8 b. N - geometricConstraintData[ii]->SetAutomaticConstraintType(
! n0 p& e4 ~* h8 s - Features::GeometricConstraintData::AutoConstraintTypeNone);
5 c8 O6 P7 ]; ?8 B" t# \; k - geometricConstraintData[ii]->SetTangentDirection(nullDirection);, ~, K2 X' m+ x0 h' T$ K9 K
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
- C% K F8 [8 x0 ?; t, K" h - geometricConstraintData[ii]->SetCurvature(nullOffset);
1 H1 ?. [6 n3 Q - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! r$ `2 S! w8 s6 M# n0 Y' ^
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
Y) M* V, X2 n9 ~9 P - }. b5 |7 M7 V0 p( p& ~
4 o, d% x) t: ~/ U7 z U! t- studioSplineBuilder1->ConstraintManager()->SetContents(
3 T! f& x& \ W3 b - geometricConstraintData);3 r. t. s9 y$ A1 o3 X) a3 H
- 5 m1 m3 p+ q/ ^0 z# U/ j) M5 G- ]& {- y
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();1 V" P8 T1 A) A5 k
- Spline *theSpline = studioSplineBuilder1->Curve();- t/ u' |) @8 _( k! M/ X2 O
- ! q% P/ l4 a3 |1 d8 T
- studioSplineBuilder1->Destroy();. |, l \: @* M; V" [- A
- ( g! y% U' j4 Y8 a. V/ }* {
- return theSpline;
6 Z8 e5 A0 h4 ^/ c9 K0 Z- b - }5 ^0 `" j) _6 V9 J8 M
- 5 T9 C K* u& M H: y0 B1 n
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)& M1 q0 o# e9 D, X' q
- {
: ^6 c5 J& Q8 |' r# x. o% S - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");& i( @, ]! |( w F8 t& p/ T& e6 M; l
- if (!thePoints.size()) return;
2 n3 h- G) v" e
I* x/ K9 g. l: X; |# N- Spline *theSpline = createStudioSplineThruPoints(thePoints);7 m; s! V$ F! h
$ n1 q/ n0 B* k- L# O/ ?4 ~- if (theSpline)
# g# z- W; t, d p, V4 N5 V# o - {
: f! b; s' Y, c( C - theSpline->Highlight();
0 t: B# I/ P1 y - uc1601("Studio Spline Created Thru Points", TRUE);* L+ _! b# u/ Q7 L4 C" A
- theSpline->Unhighlight();- M3 L# A" O/ T, }* D5 Z
- }) q2 m* h) F4 _9 ^
- }! o- ` P ]1 K0 ]# A5 u ]
复制代码
# r h: v1 W% n" w \
) u- k& y( I. o7 g2 I4 D) Z+ m3 S6 S- s! ~% J+ l. V
|
|