|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线" j8 Z5 P& @. ~
- #include <uf_defs.h>+ _4 J+ h" \6 j4 ^+ v# i J
- #include <uf.h>
: `+ k+ l0 l' c" w3 F4 G+ g: F( X3 k - #include <uf_modl.h>( H5 B, ~7 ~ K1 p+ |) V9 M
- #include <uf_object_types.h>" s- b- W9 U) K3 l( q p1 r
- #include <uf_ui.h>/ Z+ p5 y1 y- l) b" C4 D2 f6 H
- #include <uf_modl.h>7 f# J! h0 ? |: U. o8 k) i
- #include <NXOpen/NXException.hxx>
# K( V' O; J O- x- `# s# B$ M - #include <NXOpen/Session.hxx>
# B+ R ~& ]2 R - #include <NXOpen/Selection.hxx>+ V* ]; h; B4 z9 B
- #include <NXOpen/Builder.hxx>0 E8 n, @2 W% e+ R
- #include <NXOpen/Features_Feature.hxx>
6 z$ I/ T) c8 Q& T# d+ I - #include <NXOpen/Features_FeatureBuilder.hxx>
( B6 `; }# x; L4 }* [7 Q5 G2 Y - #include <NXOpen/Features_FeatureCollection.hxx>% k$ @6 p: S0 h. ~
- #include <NXOpen/Features_GeometricConstraintData.hxx>
4 n! e$ b8 @ Y& x# L; y- E( K - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>4 |9 D3 f/ x t
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
7 U; a; E& y% C8 R - #include <NXOpen/Part.hxx>
* g4 q. c6 T4 | v- \ - #include <NXOpen/ParTCollection.hxx>
, g1 q6 Q+ _7 O4 v - #include <NXOpen/Point.hxx>) U4 t- ?3 ]8 R
- #include <NXOpen/PointCollection.hxx>
# M0 ?4 H$ f V6 u - #include <NXOpen/NXString.hxx>! S4 R# ]0 f" h) u0 v3 \ i
- #include <NXOpen/UI.hxx>
; y% t. m: t8 @" c- D: k' A2 Z0 d - #include <NXOpen/Spline.hxx>
q3 R+ q) ^0 r! T. ?" D - #include <NXOpen/NXObjectManager.hxx>. G; r; k& I4 Z, v* ~+ m9 |
- J X3 M2 h" E
- using namespace NXOpen;; j; o4 e: k8 u2 D9 F# v
- using namespace std;
$ Z7 j. I P! T4 i, \( P0 m/ j
2 z& u5 U: X: n/ y! A- extern "C" DllExport int ufusr_ask_unload()9 _ @2 G% d, ?7 q. S0 @9 M) o
- {, y N7 _6 `8 `
- return (int)Session::LibraryUnloadOptionImmediately;
7 v( Z, b& u+ W6 f! b6 I; y - }
3 n) |7 v K. r: S% q
; W* m0 g- y9 X- static vector<Point *> selectPoints(NXString prompt)+ o6 K( F9 l7 D% K8 n \$ T
- {* e ?3 Q8 ~9 v; L; W3 C
- UI *ui = UI::GetUI();/ R7 h e) [6 V7 G/ m
- Selection *sm = ui->SelectionManager();
- D: a& x* e; H9 m, R+ ]* N, Q$ N - std::vector<Selection::MaskTriple> mask(1);
: r" F9 o- ] L( s - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
5 |& L; F4 v- t. F) u - std::vector<NXObject *> objects;
! C2 [& E8 i! [$ ` - - m0 \( j3 X- V+ j+ X
- sm->SelectObjects("Select Points", prompt,
9 G6 i* ?! Q, {" y$ @0 V - Selection::SelectionScopeAnyInAssembly,
% p! P N8 ?1 R T( n L9 g6 v - Selection::SelectionActionClearAndEnableSpecific,
9 e: _( ~/ |* ?) {1 ?" Z" F$ M - false, false, mask, objects);
7 J' p6 D3 X% o' _* y) K# w
5 X7 L8 a+ ?7 X# z# V6 F# e- vector<Point *>selPoints(objects.size());
0 x# B/ m9 f. d3 s+ x - for (unsigned int ii = 0; ii < objects.size(); ii++)
/ B9 r# j# q b2 }8 d! F - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);0 o- u" a7 H- U
- 5 W# k( s# v& R9 y8 J
- return selPoints;
0 ~ ~/ q* m H7 C x. ? - }, t+ i3 j' W. F% `: g1 _+ i
- - g4 \' H9 f) f {! T
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)- w- V( h z$ \# |- f
- {
# b9 V) u2 W `* E# s! B# I - Session *theSession = Session::GetSession();
* X! q& E& P4 I# w1 _ - Part *workPart(theSession->Parts()->Work());5 \2 {( W* _, E" I2 ^
& o6 j# i) U* f* ~1 E7 Z- Session::UndoMarkId markId1;
& e5 ~+ f/ K8 |- |, J5 r! z1 k9 p. ^- H - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
6 j- |: }& F9 j# B8 @" q5 u# H5 ? - "Studio Spline Thru Points");+ C2 C( V7 l; ^
+ r$ A; m5 x9 U! Y- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
' ^6 J! i. i+ \; t" F2 L; G
# v# |1 I' f" B1 P- Features::StudioSplineBuilder *studioSplineBuilder1;& r. Y# F6 e6 [& l# i: s+ S
- studioSplineBuilder1 = workPart->Features()->
& p+ B( f) n& J - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
& v$ D. C% b! `( J* N - studioSplineBuilder1->SetAssociative(true);, ^- N0 A; Y) q- g* `' l6 R; A
- studioSplineBuilder1->
& a# [$ s6 c7 H7 K, z - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);2 j% d; O. B) N
- studioSplineBuilder1->& o! H" U9 H) J2 x: V/ j& n
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
6 j8 i# p' E' V( M" g5 \ - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);; I" W7 E/ w( M/ i5 T# k4 J
- studioSplineBuilder1->SetPeriodic(false);; O! t4 h7 Z" @' |7 Z9 Z% V2 j) s- w
- studioSplineBuilder1->
9 k7 Y6 u9 q5 p3 \+ s: T! z# J2 | - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
h3 f# I2 x/ b5 | - std::vector<double> knots1(0);( K' X% V7 F: I. _
- studioSplineBuilder1->SetKnots(knots1);' p, a; T6 C# f: S- z
- std::vector<double> parameters1(0);& |$ I7 _! Q' h, I t' ^, f
- studioSplineBuilder1->SetParameters(parameters1);6 G! t2 F( ]% g* j* K
- Direction *nullDirection(NULL);
- c( }, @- ]+ ]! ^6 j - Scalar *nullScalar(NULL);
9 A* q& c( q) m; [ - Offset *nullOffset(NULL);1 r* T- a% v" t
" X$ H# R: U6 J- std::vector<Features::GeometricConstraintData *>
t$ ]; q7 l4 n/ h9 z - geometricConstraintData(thePoints.size());( J1 a# I$ b+ _
5 h8 D9 i6 {; a2 r" E3 [- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
, O K9 V+ B$ z: `# r - {
' k! L! y* W* {4 y - geometricConstraintData[ii] = studioSplineBuilder1->
& ~. O0 s# I; u, \% o, g - ConstraintManager()->CreateGeometricConstraintData();
5 I" Y, P# }" h7 `0 w - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
9 `4 M3 h: N. w- n, X- R - geometricConstraintData[ii]->SetAutomaticConstraintDirection(1 j! s% [$ e9 D6 G5 h
- Features::GeometricConstraintData::ParameterDirectionIso);
7 Q3 I- s- I0 F: s - geometricConstraintData[ii]->SetAutomaticConstraintType(
^9 c& }/ w. W% ~. o% o D/ V' M5 {0 b s* O - Features::GeometricConstraintData::AutoConstraintTypeNone);+ [ Z& |# l3 v
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
s# Z- s$ y3 o9 O' J0 w - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
! Y; S7 o: j( S4 q4 B - geometricConstraintData[ii]->SetCurvature(nullOffset);9 J: a3 a. C5 x3 u, i% _% F
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);/ u+ V# M) Z1 D4 `6 L
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
7 U/ l- M3 M1 L+ m# @; ^ - }
' c( o; h& q E* @" `: |4 U - 7 ~/ h; U7 t% }+ }4 r
- studioSplineBuilder1->ConstraintManager()->SetContents(( i& Z4 l% Z) E) K0 n
- geometricConstraintData);
& N1 O! H* _9 T" _
; Z M7 \# c0 @* } K5 x" u% A- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();5 Z7 m+ f$ J) R4 I! ]; X
- Spline *theSpline = studioSplineBuilder1->Curve();
: z- F) d3 B$ l3 d. p9 o' ` - 3 r4 I6 n$ G( Q, s* ] { a1 R5 _% E
- studioSplineBuilder1->Destroy();
; a, o* D+ _) r3 s( }& t: f
2 m- ?7 h# v) O0 Q9 `7 V- return theSpline;" v p4 i# y, f& G( H4 x# `
- }
" m% s; D5 @ Y+ J, u. t6 I6 r - 3 m3 d: A& P& p5 h9 Y
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)9 F q( Q) g' z0 |1 t" ?+ \5 U# |
- {; g; w$ \1 A7 P
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");9 q/ q; R% ?( l7 V4 |- g( J; f0 }% h
- if (!thePoints.size()) return;
: M8 B5 r- h/ b4 S' |; r/ U0 t& R. E
4 |* T0 J# a: M2 Q3 q% W- Spline *theSpline = createStudioSplineThruPoints(thePoints);1 z: g9 D& F) x l8 a9 {2 \
" E, a, o1 y1 Q( F- if (theSpline)
W: ^" f+ Y0 m% u, e& d7 o' q% s - {0 W+ t/ V+ k; e
- theSpline->Highlight();$ g4 Y9 a" |) p$ T) y0 h1 ^
- uc1601("Studio Spline Created Thru Points", TRUE);
@7 ~ ^' M0 b6 O: p - theSpline->Unhighlight();
2 o; k0 {5 T! N - }9 g" i; W2 o: p+ B& [
- }- D4 v. g' p- g* e% v' `) M: x
复制代码 ; ?3 B7 G, m }( k" X) i
4 E& C1 N" ?, {5 ~) _; G/ |9 X$ C, u# Y& g& ^" S% k
|
|