|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
" c3 z# P, E4 `1 s4 g- #include <uf_defs.h>
0 b I' @! K/ s6 C# ? - #include <uf.h>
" V* F' c9 A) d2 }7 k2 T - #include <uf_modl.h>
2 F6 U# ]% A2 b0 F - #include <uf_object_types.h>
$ Y V K! o7 n4 t3 F0 T; N - #include <uf_ui.h>
! V9 a, e2 J, p } - #include <uf_modl.h>$ x% F v" S7 e, e1 N
- #include <NXOpen/NXException.hxx>3 { o& {6 V: U" H
- #include <NXOpen/Session.hxx>1 v, ]/ F; U1 X7 c! F8 S" z7 l0 i
- #include <NXOpen/Selection.hxx>
% t0 |* V5 n# q$ @0 K0 j1 m0 M - #include <NXOpen/Builder.hxx>
( R0 H6 z3 N% c* [& J' a - #include <NXOpen/Features_Feature.hxx>! ?! |& q+ a k
- #include <NXOpen/Features_FeatureBuilder.hxx>
) X8 J# U0 S k! R - #include <NXOpen/Features_FeatureCollection.hxx>
$ z+ x) n b4 x# Z: @ - #include <NXOpen/Features_GeometricConstraintData.hxx>
2 ^ c4 ?. \/ d9 Z; X - #include <NXOpen/Features_GeometricConstraintDataManager.hxx> G4 _* e+ ?2 M. k. d
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
" d% r2 V L; _" q2 U - #include <NXOpen/Part.hxx>
$ ?4 h/ N; o4 v% c% z - #include <NXOpen/ParTCollection.hxx>
: p5 d0 Z: W/ Q1 k& O - #include <NXOpen/Point.hxx>0 \- x' v" H( E) D6 o
- #include <NXOpen/PointCollection.hxx>
0 F+ s' B; J. A; @- p) [- \' A - #include <NXOpen/NXString.hxx>5 R) Q2 D3 i, k) M
- #include <NXOpen/UI.hxx>" C4 P3 g# v' g4 n5 N) ^/ h
- #include <NXOpen/Spline.hxx>
2 o6 w" b! z4 w; E - #include <NXOpen/NXObjectManager.hxx>
9 y# w% A$ N' M3 A - 1 Z- u0 @: w9 t0 Y" O
- using namespace NXOpen;% R# h3 p3 `# n( A# Y
- using namespace std;+ s% N" ?8 P. I" _. o/ W: M# ^
* C3 o9 h W& s- extern "C" DllExport int ufusr_ask_unload()$ n/ z+ N) |3 n6 N7 L7 w- N
- {
3 ?& u( g1 d1 n; h5 r4 f - return (int)Session::LibraryUnloadOptionImmediately;% L9 i1 ?; r% k" D
- } ~# ~" o/ {6 _4 X K
- % w( Z8 U. i, F9 J1 \, k* w
- static vector<Point *> selectPoints(NXString prompt)# r8 r, V+ _* o) f( H" G/ o
- {/ E; ~3 B2 H& U- Z
- UI *ui = UI::GetUI();
1 }/ _: P, @. x4 T) x$ @3 u ` - Selection *sm = ui->SelectionManager();& F$ e1 M9 p4 p- p# c4 V
- std::vector<Selection::MaskTriple> mask(1);3 c3 A B8 {) a0 g* p" L6 W
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);, X9 r7 c7 N& q) d3 z/ X6 n
- std::vector<NXObject *> objects;6 U. |! k! c D7 g
- ; o; |" Z _* r5 _
- sm->SelectObjects("Select Points", prompt,
5 `- v8 _7 D& z/ Z2 G. f - Selection::SelectionScopeAnyInAssembly, `( T8 E' K, Y3 Q- f8 Y4 S
- Selection::SelectionActionClearAndEnableSpecific,
( e9 }* |6 o( ]7 [) q% @ - false, false, mask, objects);
( ]( F- F: X* n# N: e- K( ? - : I3 ^& I! H _* s( m$ B, d
- vector<Point *>selPoints(objects.size()); s- W5 H7 @- V- G
- for (unsigned int ii = 0; ii < objects.size(); ii++)
* e0 j2 k. _2 h9 r1 B3 T2 u! D - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);7 o; Q" F9 F) L5 X# V! Y
- , w* K$ T. V- V1 f5 F8 U
- return selPoints;
3 w ~. `: U- J( w9 w- G X, u - }
( I) n6 S: o) l ~; c2 s$ w
* _& r! p% j) T! C/ s4 E7 R2 G/ ?4 q! B- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
& s2 n8 D: m+ }& w& E/ |" {, e - {1 \* c" ?4 b8 f' X% w+ j! e
- Session *theSession = Session::GetSession();! [, `/ B- b7 \" J; ?! I
- Part *workPart(theSession->Parts()->Work());! {7 D2 f% q8 M$ E M5 ?2 b3 I
- . I9 ]/ G( M1 y
- Session::UndoMarkId markId1;
' i& {9 g3 n+ Y$ n; X- V - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
/ e+ K6 t5 \8 m - "Studio Spline Thru Points");5 `; T5 d( h& M; X$ Z! s: T
* y% I# O( |7 }- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
+ V7 `7 D k6 b; a3 o. L& S - % L5 n' x8 ?( e0 z& G
- Features::StudioSplineBuilder *studioSplineBuilder1;
, j b$ w0 X; a z! j+ Z' o - studioSplineBuilder1 = workPart->Features()->
& @7 y, {# y. c - CreateStudioSplineBuilder(nullFeatures_StudioSpline); q6 P& v" t8 `: X$ c- Q7 q" k
- studioSplineBuilder1->SetAssociative(true);
# P& ^1 i2 w# m2 w& W - studioSplineBuilder1->; T' {0 {/ J9 `
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);5 t& k# [; {& U7 o
- studioSplineBuilder1->
1 h, [$ g2 E: h1 {) Z - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
* c D/ P9 r! ^0 c4 R. q - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);: ?; G p; ]0 q' H5 k8 H! c
- studioSplineBuilder1->SetPeriodic(false);
, Q! q* G. U7 S' a+ ^& E - studioSplineBuilder1->& |1 d" K8 ~; M: V% z/ j# R* h
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);( u$ \1 U; z5 S& l
- std::vector<double> knots1(0);
1 t h% j" c' C; K3 P - studioSplineBuilder1->SetKnots(knots1);
) v: @" ^- A: l+ t9 q9 M - std::vector<double> parameters1(0);
5 w5 o% r; M; ^7 d' u& q. [ - studioSplineBuilder1->SetParameters(parameters1);4 _: `7 z0 F- J! D, _
- Direction *nullDirection(NULL);" z. a& w6 i, |' J2 V
- Scalar *nullScalar(NULL);2 r+ \, N5 w4 y; B
- Offset *nullOffset(NULL);
( [- ?* A% N* M6 U
: u7 j/ n% C* ~5 W7 m8 \0 ?- std::vector<Features::GeometricConstraintData *>% B/ s/ E/ X3 z9 S
- geometricConstraintData(thePoints.size());2 ]: A* v _ v1 ]$ b; c
- 2 |& j9 I& f. n: y- g% k* ]
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)! X1 ^" w- t+ Q6 ]- X1 c
- {: L9 t: J' L" j
- geometricConstraintData[ii] = studioSplineBuilder1->, z G7 v- K' y
- ConstraintManager()->CreateGeometricConstraintData();& M- _2 f# w! L; Y, y" [+ h
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);# B) g' W, a7 ?8 ?0 b; u
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(& v9 h& n" j y4 r1 j' {1 H6 W
- Features::GeometricConstraintData::ParameterDirectionIso);
# w# N& F4 D- O2 C - geometricConstraintData[ii]->SetAutomaticConstraintType(- J: i: o4 K' N
- Features::GeometricConstraintData::AutoConstraintTypeNone);
, Q3 t/ |8 \: | - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
6 \1 Q8 W! F4 i1 ^( S# g' F - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 l% _0 Z1 f* C6 l/ a
- geometricConstraintData[ii]->SetCurvature(nullOffset);
9 d$ H9 v6 C+ I' }& E/ r. G - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! m. g% g r0 @( l9 P+ j
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
5 q% W5 v/ v2 c$ ?* |, [ - }- ^( k y6 |* P6 a
- ( F' ]8 I5 C4 R5 m8 T6 K
- studioSplineBuilder1->ConstraintManager()->SetContents(
, t! u) W0 ~% s9 X - geometricConstraintData);
8 S8 G3 P0 }( y. f4 f0 [ - # H0 p+ y+ J5 S( l4 s" q
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
9 Z* Y! d5 l; `( U) { - Spline *theSpline = studioSplineBuilder1->Curve();
& X4 U4 h/ r* r% H - ( |7 U0 C/ P/ @$ o. r# b& o
- studioSplineBuilder1->Destroy();. A; L4 k: ~+ ~' l& X" L
' q9 i2 p" N6 [4 o' K0 n9 F- return theSpline;
* ?" J" R/ Y0 ^! ^! J2 V4 X. i& ]' @. h - }8 L% c0 |% U! E7 G( E! n1 Q
- 0 U! P! n8 i' i
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
1 D+ L1 Z5 a% }1 N1 ?& b* _ - {
5 u e& e2 V+ l; b; y0 V$ V - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
S E* T7 h* ^! h$ g } - if (!thePoints.size()) return; x8 ^* V/ O1 B# s& C7 m6 Y
- : E/ f4 R# ~$ o0 a$ K
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
0 b+ ?% y% t% Y* e$ L
$ e. a6 s, t# @9 ]6 B d- if (theSpline)$ l' s. X# ?! n Z1 Y' M( P7 T4 d
- {
9 H2 @2 H" C& Y6 m - theSpline->Highlight();( t# R* H4 H6 p- L' Z8 o6 q% ?* H; `
- uc1601("Studio Spline Created Thru Points", TRUE);$ F9 Q" G' H" ]- h; \ q
- theSpline->Unhighlight();
8 X7 u+ ]. d- I) d' a* v* c - }! g4 D) x# i4 q8 d
- }7 t# ~3 s4 ~% B& d. g& |
复制代码
. \ ]: y( ~9 b B1 F; O
2 n! Q6 G1 q7 k ?" ^) |7 J; c
$ p- J: m) z4 a3 L) f |
|