|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线) G/ c& c/ m+ | s2 }% T% R
- #include <uf_defs.h>
4 c1 G' E6 R1 t- t4 f - #include <uf.h>
7 s* e' e; t4 N( o/ ~4 e2 I: I/ O - #include <uf_modl.h>
1 `2 h7 {5 P. M& u# `6 q - #include <uf_object_types.h>; I: s5 e5 b1 R# N! S
- #include <uf_ui.h>: y- O5 _) @/ @0 V/ F9 N/ o5 A
- #include <uf_modl.h>; _: w+ E; N! P4 v
- #include <NXOpen/NXException.hxx>
. ]! E% S! ~+ U+ q3 w6 j- ? - #include <NXOpen/Session.hxx>
4 N2 n/ f! H2 y o4 O$ r5 W - #include <NXOpen/Selection.hxx>
$ I& ?# Z; [8 c* u/ I- K) S - #include <NXOpen/Builder.hxx>( A; p0 Q+ a. K0 e+ t: G) x* R
- #include <NXOpen/Features_Feature.hxx>
" q6 [# }) [: i# O* n' _1 ` - #include <NXOpen/Features_FeatureBuilder.hxx>
% G* m P7 { R* l# w( b9 l - #include <NXOpen/Features_FeatureCollection.hxx>, X A0 [% s' m8 ?& n
- #include <NXOpen/Features_GeometricConstraintData.hxx>
; A; p$ k* c ^ q. y - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
/ E# V* y5 e8 H( I - #include <NXOpen/Features_StudioSplineBuilder.hxx>
7 Z' l9 K1 E' E - #include <NXOpen/Part.hxx>* d9 Y% J) J0 @ ^- a, p
- #include <NXOpen/ParTCollection.hxx>* |$ ?* M5 m" D4 C2 }' \; O
- #include <NXOpen/Point.hxx>
2 m/ t" _/ S, f - #include <NXOpen/PointCollection.hxx>: L1 j% V: u: ^. D4 H. Y: f
- #include <NXOpen/NXString.hxx>
5 Z$ k' F! i; ~: T$ t - #include <NXOpen/UI.hxx>
2 d" i0 X# m& u) L - #include <NXOpen/Spline.hxx>
) Y' {$ s1 a+ D/ q" }- f - #include <NXOpen/NXObjectManager.hxx>
8 B' f& @# g7 u3 @5 a - , |: ]* R( {. r0 g4 }) P
- using namespace NXOpen;1 a# B H; V) t( F8 B
- using namespace std;
E! ]: e: p* O( Q - / f9 O) @& b& Y( k, A6 S
- extern "C" DllExport int ufusr_ask_unload()
. _% c6 j$ w. T& _/ X7 f9 D5 x2 z - {( `5 w) c+ J. {0 p. V
- return (int)Session::LibraryUnloadOptionImmediately;- M0 p! f9 S2 x' i/ Z- u1 O
- }1 w4 u. w, \' I" C$ \; I8 K
( {& }& ?; [( R7 E& L" s- static vector<Point *> selectPoints(NXString prompt)
( {! c1 S7 R- p1 ?" g$ M - {
5 v( G2 Q4 V6 h* b o; ^ - UI *ui = UI::GetUI();
- A' z9 _3 x) o8 _1 T3 f' [ - Selection *sm = ui->SelectionManager();
/ R8 o) @- T) V - std::vector<Selection::MaskTriple> mask(1);
2 o& t; q$ Y F" n+ z5 z# G - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
% ^7 C" |4 I6 K2 T% `' ]: { - std::vector<NXObject *> objects;5 N* y9 M; N& G5 s
3 p7 x" G: W9 I d2 v- sm->SelectObjects("Select Points", prompt,
4 l9 U$ U! s. z! Q" n1 a - Selection::SelectionScopeAnyInAssembly,1 A3 g; v* w% r0 d1 h2 ^4 w7 @ T, J0 t
- Selection::SelectionActionClearAndEnableSpecific,
& l& c! d9 H \5 Y$ ~ - false, false, mask, objects);
7 [2 f5 } G$ [+ _
Q# } {0 U* c9 u5 M+ l- vector<Point *>selPoints(objects.size());; T, R4 _; {. I' \7 h- y
- for (unsigned int ii = 0; ii < objects.size(); ii++)
/ n& I, P# D' G( v8 V% T/ u - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
' G J+ |1 J4 y" @ - + l4 t: A) X+ f8 l/ J C
- return selPoints;& n2 R7 B- Z& X r8 z' {6 R/ y
- }
. l/ u% v( }7 c. E! c0 y - 7 r9 e) |, Y, D1 ]
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
1 \5 s' s m8 q* O! G - {
% l I0 S- ^% W& n6 J/ o9 N - Session *theSession = Session::GetSession();
( w3 Z# T6 h" {3 w" |* w - Part *workPart(theSession->Parts()->Work());
6 {( S; d; w" ~7 i - 4 @( `0 s, O8 f9 a0 u
- Session::UndoMarkId markId1;' H7 z- L% u5 M% _- y5 s
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,- m u5 t% v0 C
- "Studio Spline Thru Points");
7 Z, j8 [# R5 r$ Z9 s- ?: A
0 l+ f) p, W+ z7 u! a+ k& l$ b4 v- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
3 e3 ~4 u+ _* Z. t) w' q* y
4 u& ]" n# s2 ~6 w# U) q9 Z9 |* P7 V- Features::StudioSplineBuilder *studioSplineBuilder1;6 I! g! v: G4 w
- studioSplineBuilder1 = workPart->Features()->
4 u$ X: L" \ @! F - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
- ~8 D6 ? {9 e - studioSplineBuilder1->SetAssociative(true);) \ ^8 h+ W4 L
- studioSplineBuilder1->, v1 y/ o3 y9 w- v* d! v2 V
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
4 C! T! q: j# Y! ^ - studioSplineBuilder1->
, L, t% i0 ]. {, Y L - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);- ~2 e8 D( y7 ]6 ~) ^- l
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);' t* I2 S' @4 L& Q0 w
- studioSplineBuilder1->SetPeriodic(false);
$ h$ [" c9 ?6 h, a$ O - studioSplineBuilder1->( U- g" F; Z R
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
4 c+ a( m& n, i& l0 o( I1 ~ - std::vector<double> knots1(0);5 L+ P, c* g' P/ l3 k( v3 L
- studioSplineBuilder1->SetKnots(knots1);
( p5 e; S. U" y( d - std::vector<double> parameters1(0);
! _4 O% }5 @/ b4 O5 e - studioSplineBuilder1->SetParameters(parameters1);
2 W; w6 l6 G/ P2 |+ T- M8 _ - Direction *nullDirection(NULL);+ p, F1 a- G: |; e+ s( Z
- Scalar *nullScalar(NULL);
% x# L( c, u7 u4 g* a - Offset *nullOffset(NULL);2 G1 F1 O; Y9 S$ H. l
- / |, v. J3 e9 P2 j
- std::vector<Features::GeometricConstraintData *>. ~) e9 E& P+ ]0 H" K3 |
- geometricConstraintData(thePoints.size());
& ^) l1 p$ S/ D% G4 p' r
* d+ Z/ b4 M' l, C# m- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
6 O, O3 S) s* i1 g h - {
0 p+ Q% s9 X o9 W6 O' b - geometricConstraintData[ii] = studioSplineBuilder1->
; _) {1 S# o) H$ E( i - ConstraintManager()->CreateGeometricConstraintData();- k- F- m& b0 ^- @3 e9 Y
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
. i: g& x8 d I O4 k1 O - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
8 @) w" T& C$ q3 I& a5 r - Features::GeometricConstraintData::ParameterDirectionIso);1 E4 y! l! ^+ Y; f- K' W
- geometricConstraintData[ii]->SetAutomaticConstraintType(
/ g( S$ x, E' A0 }+ w6 y K, F4 k - Features::GeometricConstraintData::AutoConstraintTypeNone);8 Y' ~% F% Z. i/ F2 L! a( P, O, a
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);- i. b% ~9 s2 u# j2 q8 d
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);$ B3 W! _$ ~& I+ f' u) P
- geometricConstraintData[ii]->SetCurvature(nullOffset);
/ p. o( I3 ^; H0 m+ t8 o- m - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);* S1 d3 C3 Q8 \4 p( Y5 I, z& L
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
& a9 j& u( K7 h. i - }
" k" u. ]- A+ v - : t b0 D- p8 ~( J' _
- studioSplineBuilder1->ConstraintManager()->SetContents(, U# }* p' F2 n! ^2 g0 e& H
- geometricConstraintData);1 S; i$ \# |! [- U
- ) T2 n0 s/ s2 y0 S/ }' [2 I
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();" P4 n0 w- d! N* l9 @: {* F" a# ~
- Spline *theSpline = studioSplineBuilder1->Curve();/ H0 a, {+ T, ]2 ^" d
- % s$ M% ~" O' @8 m% _- x
- studioSplineBuilder1->Destroy();
4 t" f4 `6 X) R! g! X7 s$ d
# V) F+ V4 b2 I2 I. b- return theSpline;% Q; _7 C7 b0 |5 |* [! `
- }
+ Q# f* H' d$ U, Y
& z6 b* j6 B0 t' L# P6 T% d- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
4 B+ Y' N8 G6 {3 g/ b& G& v1 d - {
# P5 @- B6 e8 V2 A. [ z* j - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
' h% m7 r9 x9 ?3 D3 V! Z - if (!thePoints.size()) return;6 D- Q/ r, m" U& |0 E4 b
- 6 A+ }" I( G6 S) E# Z
- Spline *theSpline = createStudioSplineThruPoints(thePoints);! Z0 t' J5 d! b7 c
$ r# J1 M1 z0 W( t- if (theSpline)
( z2 O6 n) R6 X - {6 s7 S" {2 X! l
- theSpline->Highlight(); b, l8 b) o1 \# a" c' I
- uc1601("Studio Spline Created Thru Points", TRUE);# d0 W# C9 `4 d6 O
- theSpline->Unhighlight();
8 O. X$ V4 `+ u* A+ n8 { - }
/ j& T* B# E F: E - }) y4 p& f* `& x* B; A( n
复制代码
4 ]0 a( z0 x8 L2 o0 U+ g
& |2 }3 i- \9 M, d7 r$ j
' ?, N" v$ T7 k |
|