|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线& x/ _; b- Y' V/ E4 C" c
- #include <uf_defs.h>
% K: b2 [7 k; Z1 G8 U! ^+ m - #include <uf.h>4 K: s+ Y( {/ j. N: |& R7 Q2 W
- #include <uf_modl.h>" }9 C; K' _9 T$ C: F; m
- #include <uf_object_types.h>6 v: X* z. C8 t2 h0 [
- #include <uf_ui.h>
3 w2 E2 n! y) ~ - #include <uf_modl.h>6 v1 ?& z3 V4 q6 e
- #include <NXOpen/NXException.hxx>
1 c' E9 i* j: R - #include <NXOpen/Session.hxx>* J. F6 k, Q6 ?) N! g6 q; S* H
- #include <NXOpen/Selection.hxx>$ G+ I1 V0 c0 p/ R
- #include <NXOpen/Builder.hxx>
. Z1 A' E, E4 a - #include <NXOpen/Features_Feature.hxx>( t- N. S/ G( D
- #include <NXOpen/Features_FeatureBuilder.hxx>
8 x: j& }* r# ? - #include <NXOpen/Features_FeatureCollection.hxx>( F) g: S4 C) W2 O, Q- K3 Z
- #include <NXOpen/Features_GeometricConstraintData.hxx>
x/ n5 L2 c1 N+ e - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
/ ~; r2 K7 D6 ?7 q - #include <NXOpen/Features_StudioSplineBuilder.hxx>
( V1 k) ^1 U8 i8 m( A7 W. j5 } - #include <NXOpen/Part.hxx>
9 C2 p2 w4 M' p1 \: Y - #include <NXOpen/ParTCollection.hxx>
5 x/ M L4 P% C1 s- F - #include <NXOpen/Point.hxx>: y( Z3 K, U) [# O3 J1 n4 u _
- #include <NXOpen/PointCollection.hxx>9 Q x5 b6 \3 }4 n7 Q1 p4 M
- #include <NXOpen/NXString.hxx>7 |0 ` n- k! x6 Z3 a
- #include <NXOpen/UI.hxx>. ^6 M/ i; z' ^
- #include <NXOpen/Spline.hxx>
3 z' y& u( z7 h, A2 B$ r' ?4 T; i( _ - #include <NXOpen/NXObjectManager.hxx>
H- k+ J+ i4 y6 M+ }0 i7 e* g
! @! w/ a' Z q Y& A, y5 Q4 t- using namespace NXOpen;, j6 Z5 S( i0 K7 U
- using namespace std;9 }2 Z w$ ]( m0 l" W. }, R
$ ~ y! x3 W5 d# I- extern "C" DllExport int ufusr_ask_unload()& N9 W2 L1 `$ Z9 H, O
- {
" y! [. R- w8 @) z1 h q - return (int)Session::LibraryUnloadOptionImmediately;
" h' W* k8 z7 R2 D( |2 x - }; m6 P- F4 N& Q, {2 r/ l+ a
- 6 k: M7 x6 j1 d$ x; T; L, ?
- static vector<Point *> selectPoints(NXString prompt)( ], i( {/ P; N/ }
- {
. d2 b1 Q+ B; x |3 A - UI *ui = UI::GetUI();8 q& G7 M4 g. s6 {5 o
- Selection *sm = ui->SelectionManager();
1 Z$ i& E. u' g1 ]' d - std::vector<Selection::MaskTriple> mask(1);( q" h( u7 Y; s$ v6 T. q t6 [# Y
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);" h% D, c: G, d, D2 v
- std::vector<NXObject *> objects;6 Z4 O; l7 ^* H2 n7 W7 F# N
" E& t# J. q4 |+ L% T: l- sm->SelectObjects("Select Points", prompt,
1 x* q4 d+ l) i" |$ A0 W9 I - Selection::SelectionScopeAnyInAssembly,
1 x( \; k" S' x: \' {6 O - Selection::SelectionActionClearAndEnableSpecific,% Y, M2 G1 E6 C0 h( d8 n( X
- false, false, mask, objects);
9 {7 K$ Z0 h2 C) f - / ^6 [$ }* A& L( }) S
- vector<Point *>selPoints(objects.size());- c" |" Q- V1 {. R' L
- for (unsigned int ii = 0; ii < objects.size(); ii++)2 h2 E' E: {+ D. b
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
! w! `' D8 s5 w7 |3 y- D" p8 u - " i5 F) m2 N( _4 S; f# Y( |
- return selPoints;3 E, t6 p+ o) e5 V; U* Y3 Q
- }
1 b8 {* R% O+ P7 C9 v9 } - 2 U# d1 q6 T- j; l" A
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)5 y+ ?" z+ @; `4 v& B$ G+ d9 I
- {0 Z) A& l( U$ B9 p p
- Session *theSession = Session::GetSession();
; M: y g: X' X+ d - Part *workPart(theSession->Parts()->Work());5 |- J0 G# E( i) k
- ; ]: p! g) v/ P# a5 _# s" v
- Session::UndoMarkId markId1;
- M9 `% S$ q4 A7 p( f - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,# w% w* Z+ {0 z' J6 ?7 H2 i# I: \8 T
- "Studio Spline Thru Points");
( `* U, ^$ e' B. b+ F
" x6 V% v. C+ V" ~. C: y- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
4 V: t2 \: c7 w0 B
; ^0 v3 H. Y- X) T- Features::StudioSplineBuilder *studioSplineBuilder1;9 S. B; u! Y7 A( A: O8 t
- studioSplineBuilder1 = workPart->Features()->
5 |9 |- k% p* z8 L, I - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
& V- G/ k; ~( ]% q; S& V - studioSplineBuilder1->SetAssociative(true);
% n& i/ j1 U# I3 ^ - studioSplineBuilder1->8 Z" m- l0 g! |# F. v# J* [( D
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);0 u5 [3 ~! ^, z* E; L7 z; A2 X, l
- studioSplineBuilder1->5 U. Y. x5 g& F/ j" n/ Y. h
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
! e: E/ Q' a4 W6 n9 e$ ~% i - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( G% b3 d& I& j' `! X3 \3 T
- studioSplineBuilder1->SetPeriodic(false);
: W2 c6 {( {( n5 e) P - studioSplineBuilder1->5 m6 X6 A0 y) c7 y2 W
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
8 q" B) j0 c/ W- A$ g) B- \ - std::vector<double> knots1(0);$ H! f% a$ f% Y3 B" B5 X1 z" Q% ]4 W
- studioSplineBuilder1->SetKnots(knots1);
( ^% _7 q0 l3 d - std::vector<double> parameters1(0);2 B$ H0 F( `2 I) Q& k9 l4 { q4 L" D
- studioSplineBuilder1->SetParameters(parameters1);
* P3 P* o& X, U' K; S - Direction *nullDirection(NULL);
: K8 n! e1 I$ I9 e4 ^ - Scalar *nullScalar(NULL);8 M, e5 Q" E! n
- Offset *nullOffset(NULL);
2 b! Z4 I# A+ U- M( F - 1 Z) [# i/ O7 B% j0 V. ^3 p
- std::vector<Features::GeometricConstraintData *>2 ~2 X7 a- |+ r+ D
- geometricConstraintData(thePoints.size());
7 L" `+ r/ p5 l, P/ V - * ?8 E: d- ?% o* Z
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)8 y, [5 y: m6 A8 N5 v5 v& ^
- {
. l' ]. g- r3 R/ u- h - geometricConstraintData[ii] = studioSplineBuilder1->
2 u0 S/ ^& _6 S" R* r - ConstraintManager()->CreateGeometricConstraintData();7 ?: t m' o) k1 T0 x+ R$ G8 \
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
" E7 a! Y. p& E6 M5 F2 w# b6 a - geometricConstraintData[ii]->SetAutomaticConstraintDirection(. z) |8 H: l- m0 B9 \
- Features::GeometricConstraintData::ParameterDirectionIso);, e9 h1 w& w$ a3 a$ Z! ?
- geometricConstraintData[ii]->SetAutomaticConstraintType(
& G- X: e( c9 }6 n$ u6 a - Features::GeometricConstraintData::AutoConstraintTypeNone);
2 u& g6 s4 o% J# d- ~5 t7 b - geometricConstraintData[ii]->SetTangentDirection(nullDirection);0 z$ `! O. B0 V% }
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);" i i: k' @. [) X: {
- geometricConstraintData[ii]->SetCurvature(nullOffset);8 V& }( [8 I: y- o i" c& E2 G
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset); A5 j- l) T4 R9 u3 x* W# h
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);4 ~: L, A5 \: V T( Y) E: H3 |7 q
- }; w1 b0 |9 o: N
- $ J9 `7 d s2 [& x' e, W% C; f, d
- studioSplineBuilder1->ConstraintManager()->SetContents($ F' D1 X1 S0 Y! _- _# N# y" P% S
- geometricConstraintData);) f$ C% u! M2 k9 P, E6 `
- 6 f# l Z9 I6 r' c# @- I
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();% R9 e; S# P, f
- Spline *theSpline = studioSplineBuilder1->Curve();
- c# u# v" T5 X' a0 J: z8 A
. Y. d$ X3 U8 Z& U! w5 B- studioSplineBuilder1->Destroy();
0 {/ a0 _" g5 L1 S
2 S9 G1 G( R: k- return theSpline;( w. @! t! J9 H2 D
- }
! B4 |3 p9 P- W* U) ^* r- q
3 R% o7 _4 s; Y* o* C- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)& J# ~6 u6 w/ F' ^
- {
" N$ z4 M' [" t- v$ x; B/ M& |0 t - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");+ k4 O6 I+ p9 C3 h, ?
- if (!thePoints.size()) return;
/ S0 I' _+ j9 U% Q2 k
/ G$ l" s. q6 M9 ]% h- Spline *theSpline = createStudioSplineThruPoints(thePoints);
$ G$ f4 S3 ^1 N. V* e5 G/ j
1 Q8 ?3 n! S+ t# X6 ?% l- r- if (theSpline)
& N$ M* h7 n* x0 c% M' u, K - {, _3 H7 @1 y `! [: q" T# W
- theSpline->Highlight();2 }, y8 p. z" L/ c( f
- uc1601("Studio Spline Created Thru Points", TRUE);9 [# j& o* X! A- Z" D$ B: F5 ]6 ?
- theSpline->Unhighlight();: y# |9 @ o- a. j, w- i5 u
- }
* v7 `. N- F: b; L7 M - }1 l1 c4 [1 Q+ b
复制代码
" C( o# ?$ j' S- {8 T' K
+ @ t% B: J( j& w# A7 L. _, Z& e0 P" c- R' V% ]+ B8 }" c
|
|