|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
$ `) F) t9 n U# t$ b# R3 w- #include <uf_defs.h>+ X" c) o& Z! }$ t2 n
- #include <uf.h>" q2 K: O) ^9 [. t1 m
- #include <uf_modl.h>
% d6 G) u# G5 e0 v: v) C - #include <uf_object_types.h>2 _+ N3 t" J+ D' X m, c1 }* c( r
- #include <uf_ui.h>8 _( k' ]+ I: A
- #include <uf_modl.h>; ?; d4 F/ I& |" v' R
- #include <NXOpen/NXException.hxx>6 g# j- _/ G. G0 c O! N* ^
- #include <NXOpen/Session.hxx>
: g: K% k# ?% j' V f, q6 F - #include <NXOpen/Selection.hxx>$ l! X1 z8 e V h: X% G
- #include <NXOpen/Builder.hxx>
. N2 @% e u! j2 I, B - #include <NXOpen/Features_Feature.hxx>
* \8 G; @* |) ^% U6 x - #include <NXOpen/Features_FeatureBuilder.hxx>
2 m8 R5 A( b/ r1 }+ v - #include <NXOpen/Features_FeatureCollection.hxx>0 ?, J& p4 u$ Y {2 ~
- #include <NXOpen/Features_GeometricConstraintData.hxx>% O/ r$ d7 s! y9 ]( i+ B; }" h' F
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
! P* j: @- c7 Z- p/ h; t2 g8 G - #include <NXOpen/Features_StudioSplineBuilder.hxx>5 @3 l8 L0 t" {- {% B/ u
- #include <NXOpen/Part.hxx>
6 r8 c8 N3 r+ P& j - #include <NXOpen/ParTCollection.hxx>
/ Y$ q4 Z% _; E/ ~: n9 R - #include <NXOpen/Point.hxx> Y% |) o% n; S7 y4 n. W
- #include <NXOpen/PointCollection.hxx>" o# R* f' ~: M5 Z+ y6 V
- #include <NXOpen/NXString.hxx>
; O; \: f, m/ t1 t5 n - #include <NXOpen/UI.hxx>
4 P" |1 g+ _. @- }0 Z, C - #include <NXOpen/Spline.hxx>
2 ?/ f5 j# Z: O3 A2 K - #include <NXOpen/NXObjectManager.hxx>) z- B8 ?- p+ m/ K1 Y# G9 I% H
- 6 @2 [8 {3 n* l( L/ t$ C/ X- ^( N2 e
- using namespace NXOpen;
; U+ B {6 `2 e4 l3 S( | - using namespace std;; {" w, ^) T& { Q: @+ }; r' l
- J& }* [- X+ ^+ s6 r
- extern "C" DllExport int ufusr_ask_unload()1 f4 ?3 o' t6 i
- {
2 V4 |) K6 q0 Q/ T - return (int)Session::LibraryUnloadOptionImmediately;
4 g1 U4 i: ^2 z - }
/ P! W, f1 g8 ^! N; j
) V4 ?( @2 S3 Y5 A3 T5 ]2 q& R# t- static vector<Point *> selectPoints(NXString prompt)
" G/ C7 ~1 o6 N: M - {2 u# [/ o5 T5 H) Z: z e
- UI *ui = UI::GetUI();% @+ y" |* x. d5 N3 W9 _
- Selection *sm = ui->SelectionManager();5 e6 D% d( p( F
- std::vector<Selection::MaskTriple> mask(1);* Q9 d4 w- ~) o; o; Z
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);# x. k" o3 M& B! |, h% m
- std::vector<NXObject *> objects;
6 R% ?0 W* _$ X" F5 c5 c U
% G! W! h; o7 e. s5 }1 I" z- sm->SelectObjects("Select Points", prompt,
1 T' g- l: M# f0 @0 j# h - Selection::SelectionScopeAnyInAssembly,
5 J- [" [& v. N+ }7 }& \- z5 z - Selection::SelectionActionClearAndEnableSpecific,* e" U$ m% c& ]( k
- false, false, mask, objects);
% R: N+ ]" e+ W+ L - 1 L# L6 E( M: J5 n/ W* m7 l8 W) E: G
- vector<Point *>selPoints(objects.size());
# @/ K* I4 E. n% @# V$ d - for (unsigned int ii = 0; ii < objects.size(); ii++)
8 S- M! _* P) c0 {5 K - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);$ h3 r/ `' e( z- V$ Q$ I
- % }" P% @$ v" R% k8 h1 H
- return selPoints;
5 g3 b+ Q$ L8 C4 g6 w Y# Q - }% W; b6 {# E# Q( S- _
, }$ w% N6 m5 d+ }1 ?. ^- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
K, R5 u- ~ b' o$ O) i - {
% K" ]% D) ]0 ~) h( ]: h u+ v - Session *theSession = Session::GetSession();
8 q+ k! {2 L' _8 c& \# V. U- e - Part *workPart(theSession->Parts()->Work());7 A) w; P. b* o- m% Y
$ Y5 F' P8 e1 [+ b* i) E. ^* A" a- Session::UndoMarkId markId1;0 }% C" K8 s5 e; t0 ^8 l# E* S
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,* n$ h2 E% D# p5 g- @* I$ k' J
- "Studio Spline Thru Points");$ D- x9 q& V: v3 t6 o% Y7 W& P3 u7 j
- ! r3 ~, I/ |7 j3 a+ `
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);# X' F# L8 a% t* \
, R! \$ y# l/ N% s: j- Q- Features::StudioSplineBuilder *studioSplineBuilder1;
% R5 D) x4 x) S& r$ Q, n' C& C - studioSplineBuilder1 = workPart->Features()->2 L4 _2 Y/ n( g& L1 b
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
% ]. A" f; J5 B0 `2 U - studioSplineBuilder1->SetAssociative(true);
1 e' I' g0 O5 g3 m - studioSplineBuilder1->
/ O6 d/ l# I& V, l. C0 V; c5 @ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);: M# f# w6 y0 p, U3 C2 }
- studioSplineBuilder1->
8 h% N# U8 t7 U6 o1 C/ \) E7 E \) _: l - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);4 d7 Z* j0 ?+ R" ?1 _) w! l; A! p {
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
( R- h+ R6 q8 h1 R# r1 g. n - studioSplineBuilder1->SetPeriodic(false);4 V2 y8 v/ x. z) G/ V. K' B8 S! u/ X
- studioSplineBuilder1->6 h: p! N7 |( H2 |4 g" [. B
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
" {$ Z. h& U+ n8 r G' `$ ] - std::vector<double> knots1(0);
+ X3 b+ e+ e1 n Z: U - studioSplineBuilder1->SetKnots(knots1);
+ w- @6 l. _+ y2 \; q) i8 ]8 s - std::vector<double> parameters1(0);
5 P$ [! M$ H5 s+ x, K* [% W# }% n - studioSplineBuilder1->SetParameters(parameters1);
3 {0 M5 m$ z' K6 ~7 F# ~4 t - Direction *nullDirection(NULL);
6 g- V# _/ @! m& L - Scalar *nullScalar(NULL);2 _9 \1 N4 s+ L/ q% m
- Offset *nullOffset(NULL);0 T h* P" O9 N4 `$ }
- ' t1 l; h6 y3 C0 s
- std::vector<Features::GeometricConstraintData *>
% x" J( _7 e9 f3 U C$ n - geometricConstraintData(thePoints.size());- b& H6 y7 f0 x9 l# W* i
- 5 U8 g6 S6 l* W; {
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)% D0 O! Z2 W/ U8 t6 @$ o
- {) ?( [8 P0 ^$ J
- geometricConstraintData[ii] = studioSplineBuilder1->
q4 x Z1 ?9 | N( u0 C - ConstraintManager()->CreateGeometricConstraintData();$ G) R2 t C; ?* S
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
% U$ T8 @/ s3 { - geometricConstraintData[ii]->SetAutomaticConstraintDirection(/ D- G3 x9 u5 Y* @. Q8 {) N
- Features::GeometricConstraintData::ParameterDirectionIso);" {6 |4 V* w, \7 Y! o7 r- m2 {' U. O
- geometricConstraintData[ii]->SetAutomaticConstraintType() V9 ~ |5 x6 d% n2 `0 n- g. H3 q7 t
- Features::GeometricConstraintData::AutoConstraintTypeNone);6 ~0 Q) @, R1 t
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
- e4 J' P, |; _( f - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
* M& }0 O6 ~ j( K: J+ C6 R - geometricConstraintData[ii]->SetCurvature(nullOffset);
- Z3 x! ?7 X7 ~$ T - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);$ y E3 o1 C& d& B1 Q
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);* Q" {; X1 E) d2 ^
- }! r5 Y0 ?; H! v" d& f$ N. {& S
- D( U( t7 K- J* Y7 J5 k
- studioSplineBuilder1->ConstraintManager()->SetContents(' e; u$ {/ k J& |6 L2 x9 f
- geometricConstraintData);* I! g7 C" K0 o, ?, ?: p
' |0 q' @* t* I( |3 ]7 y- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();& e2 \* B7 B$ E" _2 W. ?
- Spline *theSpline = studioSplineBuilder1->Curve();" E4 B' ]- B4 ~: T+ p( K
; c" x9 B) f0 O. j# @& G- studioSplineBuilder1->Destroy();& s3 y$ E) N7 C6 B3 J- \9 G( k
2 o E. j5 b1 |. a U* s- return theSpline;
* y: f5 a9 J5 ]# n) Y - }
$ |; _" F" q4 t8 C5 N6 u - 9 J9 w/ N: E4 T0 x4 [$ L* l2 E7 y% [
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len) h5 X! l( T2 E$ C. C$ A( b
- {( E0 H7 t M. J8 R3 t" f0 p
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");( c. X2 m+ t1 q# P1 ~
- if (!thePoints.size()) return;
6 @4 N5 |; y5 |
2 u, w4 [7 |" ~/ J$ {- Spline *theSpline = createStudioSplineThruPoints(thePoints); e' R9 t* Z1 r: C' }9 X! @; q
- . K# z$ ?2 ~( s% }7 j% t
- if (theSpline)8 l5 C( I, J6 e
- {
3 I* p8 O$ h: B# O( w0 L - theSpline->Highlight();/ v$ e& [5 D) V$ C5 R) a
- uc1601("Studio Spline Created Thru Points", TRUE);
8 W" g- ~' z- |1 b$ z - theSpline->Unhighlight();
- I7 q; ~5 h% ?( A2 D. S - }4 j y8 U& ?! U5 v8 V8 j
- }' r+ }" e4 S8 c; R% Q7 y
复制代码 $ y: A+ b! ]; \5 R9 N. m
9 W( i' T' j+ y S; y
8 \3 Q @2 O, n& q/ r |
|