|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 N) k. S: O' s: G% hNX二次开发源码:通过选择点创建样条曲线
) S8 g7 O6 y& i- L! N5 {# S8 G6 R3 w- g0 ~+ b2 ^# l
6 C) w- f) |' _" `- , h6 a/ M# n" H. l: k& h ^6 W) ^' g6 k
- #include <uf_defs.h>- e; E8 J2 \. K0 F& J
- #include <uf.h># \, W7 i9 _2 s+ H4 x h# X" [
- #include <uf_modl.h>, c# o) \( j1 R, Y) Q* S. k
- #include <uf_object_types.h>% m* j/ V* \; q4 h/ e
- #include <uf_ui.h>" l2 c1 O' c/ L9 a {- f
- #include <uf_modl.h>2 I. G4 f, f% ], b
- #include <<em>NXOpen</em>/NXException.hxx>8 A. j; b6 w% G4 g- N1 d- [% n
- #include <<em>NXOpen</em>/Session.hxx># u! m% C& R$ ?/ o5 t1 E+ G0 M8 |
- #include <<em>NXOpen</em>/Selection.hxx>
9 h& v* C( v8 X* M" C7 T% W - #include <<em>NXOpen</em>/Builder.hxx>) M4 R: w+ T) B, p
- #include <<em>NXOpen</em>/Features_Feature.hxx>
7 e$ R) x( A: ]; O8 J; x8 E - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>- m0 [/ J# D$ `8 g `
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>; Z* }/ [3 n4 N
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx># F- n% {7 W+ N8 `* Y4 _
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>0 Y5 D; Y2 p0 L9 f/ I% L* Y
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>4 }- J" @' m4 [8 | y$ b$ {8 T
- #include <<em>NXOpen</em>/Part.hxx>7 ^8 J; x8 \& c8 y# D
- #include <<em>NXOpen</em>/ParTCollection.hxx>
3 w5 r0 c7 H6 B5 w - #include <<em>NXOpen</em>/Point.hxx>; ]( p8 \ l. t. W! a4 j
- #include <<em>NXOpen</em>/PointCollection.hxx>
. I2 d, @% d- Q3 _; h. j0 m' M - #include <<em>NXOpen</em>/NXString.hxx>
' k" S" X6 U+ i- s - #include <<em>NXOpen</em>/UI.hxx>$ b b8 c3 d- y: l. s
- #include <<em>NXOpen</em>/Spline.hxx>
+ c& r8 u' h; [8 d) m6 C4 L' r- w# m - #include <<em>NXOpen</em>/NXObjectManager.hxx>
# A* M+ V8 j" x& E* @+ E* c* d
) P o% W# }: \- using namespace <em>NXOpen</em>;* B& Z4 C! S9 \, F. @
- using namespace std;
0 z- n( b4 ?5 E$ X
( k8 Z. {! p3 J |- extern "<em>C</em>" DllExport int ufusr_ask_unload()) r( o/ Z2 J2 Z6 D; o4 X" @
- {
0 L$ M( A4 g- l* Z! Q" L3 j+ {( v - return (int)Session::LibraryUnloadOptionImmediately;* x: N* G! `) i# t% h- h
- }
2 w# |4 L& Z. o2 r) O
4 K/ ?+ Z, s2 ^* P! u- static vector<Point *> selectPoints(NXString prompt)
5 g" K$ R/ T% i Y* e - {3 E1 C) T d2 P/ K* T1 f& R3 h! O
- UI *ui = UI::GetUI();+ @+ ?$ l9 |+ l2 @( |
- Selection *sm = ui->SelectionManager();& s& G$ ~& t% l- q2 O
- std::vector<Selection::MaskTriple> mask(1);/ K2 T7 W9 b+ t+ @* w
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);* a7 A1 y8 \ e: Q& @- H7 ]
- std::vector<NXObject *> objects;
/ F" n0 o7 U$ w l - 7 U3 J# b0 w" G* ]$ o. j
- sm->SelectObjects("Select Points", prompt,3 T4 j/ }/ p W3 p3 b* I) Z6 R
- Selection::SelectionScopeAnyInAssembly,
7 M: B6 L0 e! d8 {: t \ - Selection::SelectionActionClearAndEnableSpecific,5 a I+ J. N- P4 K% x
- false, false, mask, objects);# i8 K6 k& t% E) d
- 5 z. x1 G1 e2 ?/ j0 }. y
- vector<Point *>selPoints(objects.size());/ \+ \5 b6 ^ K
- for (unsigned int ii = 0; ii < objects.size(); ii++)
" E9 A: B+ _) Q5 P6 p - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);4 p0 K; Z; B, n$ W$ [
- ^$ f: U0 p1 g) [7 G- return selPoints; k/ y; y* I! s! x
- }, D( W! g9 f* m6 H5 j3 _7 c
0 W: z" C* y5 B0 E6 L# @" w- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints). C+ N% U2 B/ _0 l( C+ |6 V, q
- {
$ Y6 b' m$ L/ u( T - Session *theSession = Session::GetSession();
- C1 g6 X% `% m @; t9 l - Part *workPart(theSession->Parts()->Work());$ f( G( C+ f: W% \
- 7 {7 N: Z6 I. C( V9 s+ R/ _% V
- Session::UndoMarkId markId1;
( }% q, T3 e+ Q1 X$ ? - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
; R5 R& w5 |0 u7 n' | - "Studio Spline Thru Points");
8 J& b/ r5 V2 U$ R. i - Z7 m# r9 V( Z& u
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
! H3 {) G# v% { - : L* {3 B& T5 k% ~1 z
- Features::StudioSplineBuilder *studioSplineBuilder1;) m' l5 p, K7 ~! D7 q
- studioSplineBuilder1 = workPart->Features()->
9 E6 N/ L$ f+ _ - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
: V4 O6 C3 h+ n+ y - studioSplineBuilder1->SetAssociative(true);
]6 V5 c k: S& F2 r5 z - studioSplineBuilder1->
" O6 P- T) Q! U+ z3 R9 V+ G- ~ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);3 u, t& ], ]! Z8 K1 p+ R1 Q0 \
- studioSplineBuilder1-># X3 f) y" Z& D9 f+ `7 U7 Y, C
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
* ^) ?/ ]; w9 P - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
! K$ o$ u4 W0 `7 \ - studioSplineBuilder1->SetPeriodic(false);
, i* X4 I3 b5 Q( H* e5 m5 v - studioSplineBuilder1->% a, [" ~4 d. x& E
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
+ C6 X) L$ F8 `, d3 D - std::vector<double> knots1(0); m D1 {. D% B: o0 T
- studioSplineBuilder1->SetKnots(knots1);
7 s& ^& r& z- W - std::vector<double> parameters1(0);2 d1 x, F& H) `
- studioSplineBuilder1->SetParameters(parameters1);* @5 l' T/ N: }% ~8 _" L
- Direction *nullDirection(NULL);
* H8 ` h0 a! C1 X: o - Scalar *nullScalar(NULL);
# C' K9 R! `0 d& z3 Y- E - Offset *nullOffset(NULL);
6 Z5 t8 r. F& Y" ]# \( {6 Q - 2 P% x, k7 h/ ]' H. G, u1 p1 k
- std::vector<Features::GeometricConstraintData *>
+ P+ K8 P7 _6 r - geometricConstraintData(thePoints.size());1 A$ ]1 S6 ]/ p8 d2 w
5 y( O( I$ ^5 G0 G- for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ ^' d, i% M1 y- e& t
- {
. c; I& L# \1 H. e3 \: s, ?8 J - geometricConstraintData[ii] = studioSplineBuilder1->
* T9 `0 e( y) h! N9 G; t - ConstraintManager()->CreateGeometricConstraintData();1 r3 O# i: ~; o! e% Z' u. t9 [( T. u
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);3 ~/ n" |+ Q; G# c- w0 f
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
, j- s( i$ ^/ x/ ? - Features::GeometricConstraintData::ParameterDirectionIso); J- h$ [" N+ k0 A5 B
- geometricConstraintData[ii]->SetAutomaticConstraintType(9 {% Q% D9 w+ K1 n. `, J
- Features::GeometricConstraintData::AutoConstraintTypeNone);
2 u8 e, f6 i. j p- G C - geometricConstraintData[ii]->SetTangentDirection(nullDirection);+ I! U3 c% q0 e& Q9 q/ y3 t' Z% [; z5 R: w
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);" A9 B2 i' i3 i
- geometricConstraintData[ii]->SetCurvature(nullOffset);
8 k6 n1 E* r8 s" s/ v0 n2 n - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. i' N* w( }4 r
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 S( `, L( i! q. v; _
- }' K& [) A) J" u1 S y: p& I
- . w+ @/ j) x6 A P% l; z, T! a
- studioSplineBuilder1->ConstraintManager()->SetContents(0 M/ f5 r& k2 I
- geometricConstraintData);# Z$ }# P4 u9 Y+ a5 H9 e& w) ]. s
$ g8 ~( m' e. C7 w" k( H- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();. \4 S7 A+ m, |5 X& w
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();
; }, G+ q& H' A3 P - 8 F+ I: |0 s6 O- T/ {
- studioSplineBuilder1->Destroy();* O. F3 s J% l2 E1 Z+ ^
% B1 x( W; t3 Z% K7 g# \; U% C# g- return theSpline;6 c H+ f) f1 L& q/ v1 T3 n1 A
- }
( Z" _# ~9 N) l8 V: e. m/ [' i4 l - ; w- p1 h- ^" s
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)+ h! V: e: u/ e2 @
- {
7 B8 i0 ^; _0 s1 b! |% I& M/ t - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");" a0 t( b$ ^4 n
- if (!thePoints.size()) return;
# Y( }5 D# U1 B0 S6 C# ]% W1 B
+ `, Y% x- ?4 X8 A+ `% }3 ?1 B1 T ~- Spline *theSpline = createStudioSplineThruPoints(thePoints); E3 ^% e1 H& }0 _* h
' Q' i9 k+ X7 ^, {- if (theSpline)
4 S: f( s2 q( r8 V z - { Z* L7 l. d( @1 d' S
- theSpline->Highlight();
" R3 [/ S7 W: ^ L) q, X - uc1601("Studio Spline Created Thru Points", TRUE); ]& R6 o5 R/ Y. T
- theSpline->Unhighlight();" V9 J: b; q( ` [+ U4 l) l
- } [1 D9 e! N4 O, d
- }
: [! r* ~6 F- q2 Q2 m - <p> </p>
复制代码
* o4 ~$ c# N- \% Y1 k |
|