|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线* ]2 h1 r1 @! c3 m, @& |/ Q1 m& ?- b
- #include <uf_defs.h>
+ u- t0 F. M9 l3 f - #include <uf.h>
- n3 u% m1 p: S) @) s& k - #include <uf_modl.h>$ E5 {- X! P" R, K
- #include <uf_object_types.h>
# Z* M, A! g2 G% b g - #include <uf_ui.h>
7 r0 r( e5 u( X+ n. R - #include <uf_modl.h>
+ x2 A5 \& U- G - #include <NXOpen/NXException.hxx>- W& d: t- }1 f( X% L
- #include <NXOpen/Session.hxx>
3 K3 R0 G; `6 C$ I: S - #include <NXOpen/Selection.hxx>6 J7 v; v6 U) e! W- [$ W& V" d
- #include <NXOpen/Builder.hxx>) X& O# y6 f9 G$ F- D
- #include <NXOpen/Features_Feature.hxx>
C. T6 \' ?& u( H. L - #include <NXOpen/Features_FeatureBuilder.hxx>
8 h3 [5 n+ B/ L9 Q* w - #include <NXOpen/Features_FeatureCollection.hxx>! O1 R; I( K# Q
- #include <NXOpen/Features_GeometricConstraintData.hxx>/ K: z( o8 t( C- @
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>) n. D# N W# Z, B3 Z
- #include <NXOpen/Features_StudioSplineBuilder.hxx>7 E" ` X5 P! x% n6 v! \7 e& B
- #include <NXOpen/Part.hxx>8 t2 X) z7 u% I+ Z- Y
- #include <NXOpen/ParTCollection.hxx>2 R3 i" C# g h: }& f
- #include <NXOpen/Point.hxx>% R! ~8 p7 R% D# {. U. O
- #include <NXOpen/PointCollection.hxx>
$ Z- C% k F& ?2 Q; O- i: f+ G - #include <NXOpen/NXString.hxx>* ?+ b0 I! ?: R6 }" @+ t& O
- #include <NXOpen/UI.hxx>
; `: i/ n6 p/ e; W" t- B g, O1 O - #include <NXOpen/Spline.hxx>
0 t* C+ a& W6 n# T - #include <NXOpen/NXObjectManager.hxx>; k7 O# x: R/ d
- 6 N4 }4 q% T4 {( h
- using namespace NXOpen;; y$ b. C+ q2 G" c/ v
- using namespace std;
1 \6 ]4 q& `/ z- B b! h3 R
! H9 b: a$ ~; _& i& j5 u- extern "C" DllExport int ufusr_ask_unload()
, I( _, V2 T7 ^$ g1 |( |4 r# J0 D- P - {
- ?$ z8 }' g) D; _ - return (int)Session::LibraryUnloadOptionImmediately;
. ^/ b( H2 U! J/ w9 t - }# Q: y+ G1 S" V4 \# m
& J! e, y9 T- u7 V" p- static vector<Point *> selectPoints(NXString prompt)
$ L v1 t9 }4 @" @' |) F, f( o' i - {* T5 E( F# ]" A( P' P
- UI *ui = UI::GetUI();; q4 h6 Q7 S6 b5 Q& G$ H% @, T
- Selection *sm = ui->SelectionManager();1 y' @3 \' `- T: t. w: F0 L( {
- std::vector<Selection::MaskTriple> mask(1);
. _( c( l* l; K! J0 M - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);8 Y, f+ M9 K( C7 Z( |! l+ \
- std::vector<NXObject *> objects;% D" Z7 m) j4 U5 a. D+ |1 p
- + Y4 Q9 E% r9 r9 ^: ]2 n& A
- sm->SelectObjects("Select Points", prompt,
, y+ n5 v' I: U1 \' Y - Selection::SelectionScopeAnyInAssembly,: x" I# Z: ]& E/ P" Q
- Selection::SelectionActionClearAndEnableSpecific,
5 d+ N* e/ q9 V - false, false, mask, objects);
9 O( ~. ~3 g! Z4 s1 |$ N2 ]
4 [4 p; ?+ I$ f& k1 Z9 m- vector<Point *>selPoints(objects.size());
9 z j, j9 H( i V9 k" q# Y - for (unsigned int ii = 0; ii < objects.size(); ii++)* m1 R8 U9 x9 ~- F; s( F6 r. \" w5 W
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);2 y, m% o# c( f$ ~9 u* G$ z
7 K2 W6 S. l; e- return selPoints;+ {# a4 M6 P/ v/ f; C
- }9 Z8 y7 b9 ?( U* _' ?
- & ?% {8 V4 O; t' @* d. t; t% b
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)3 n8 S d6 f6 N+ P
- {8 h; T+ S* \: z9 X- b
- Session *theSession = Session::GetSession();
; H t5 F; T! p1 r0 k; x* s - Part *workPart(theSession->Parts()->Work());" T2 Z& C- z4 C$ B; y
- / V2 x/ Q6 @+ E
- Session::UndoMarkId markId1;: c; k( Z9 `7 P1 L
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,3 b: a1 i4 L% H. X
- "Studio Spline Thru Points");
* E, i9 Q3 `- j$ k, a% S - 8 G: d% A# o3 I$ v
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);5 `, c$ d8 d. ^2 i
: ?0 M! j' ?. m- Features::StudioSplineBuilder *studioSplineBuilder1;
* a5 D! a2 i9 t" i - studioSplineBuilder1 = workPart->Features()->
! f+ v$ d0 [" C$ M4 [$ H - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
: W6 w% [$ f; N5 z8 e - studioSplineBuilder1->SetAssociative(true);
7 t; A' O$ u) {$ y: ?* ?. r9 B - studioSplineBuilder1->
. ~: K( \! s2 d8 @ - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
8 `7 Q- [3 U2 d9 N6 f5 w- ^* g' @) \ - studioSplineBuilder1->* c3 L* ?# }1 w/ z
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
8 z' M! W$ K2 j3 ]: M( d - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
& t: [" }1 S4 B; W - studioSplineBuilder1->SetPeriodic(false);
! e1 ^7 A% u3 m! U - studioSplineBuilder1->+ C! M5 V8 i1 d) O% }" W
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
$ y4 d! R. v; w" A0 j# n" p - std::vector<double> knots1(0);
7 B ?" X$ F1 F- B" [* a3 O - studioSplineBuilder1->SetKnots(knots1);
8 q, \, P0 M l; s4 H/ e6 c/ o - std::vector<double> parameters1(0);
+ t/ c; [1 U6 V7 ?" k" c - studioSplineBuilder1->SetParameters(parameters1);
4 d. [% n! S2 G' \3 b ` - Direction *nullDirection(NULL);
8 F& K, m; G- Z' p% Q) K - Scalar *nullScalar(NULL);- v. o. y. C' @ o! p9 B+ |
- Offset *nullOffset(NULL);
6 s v7 m; f* P& j' v& ]( B- H - - F- ~* ?0 T/ A
- std::vector<Features::GeometricConstraintData *>
& A9 W7 D* w# H( W# `2 d! a - geometricConstraintData(thePoints.size()); U2 ]5 s( @0 n4 I
* r; P4 ^ A( M: Z9 Y# v0 ]0 y- for (unsigned int ii = 0; ii < thePoints.size(); ii++)+ l# f9 ^8 \8 h0 ]
- {
* B% J7 b# |' J5 `0 V h1 C: A$ g - geometricConstraintData[ii] = studioSplineBuilder1->
5 G5 ^9 _4 U1 ~8 X - ConstraintManager()->CreateGeometricConstraintData();
( x/ v3 g) n3 V( y/ a# n - geometricConstraintData[ii]->SetPoint(thePoints[ii]);
; o3 u ~7 s: ^; q; q } - geometricConstraintData[ii]->SetAutomaticConstraintDirection(5 o/ V, O R4 I* M. b0 }
- Features::GeometricConstraintData::ParameterDirectionIso);
* u) q) i4 M0 ]- a. ?4 R7 \; @ - geometricConstraintData[ii]->SetAutomaticConstraintType(
. Y" \) m' |8 R0 w3 `+ z - Features::GeometricConstraintData::AutoConstraintTypeNone);
1 K) i& [* q7 T7 V0 Z/ I - geometricConstraintData[ii]->SetTangentDirection(nullDirection);2 d$ \ ~2 b, Q+ g8 v1 q3 S
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
$ T! g" H2 a2 e1 N7 @9 x - geometricConstraintData[ii]->SetCurvature(nullOffset);4 \( |! x G! T+ g$ } a) l' x# g
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
3 Y( o6 \1 k. G8 O - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);. w" I" E: }7 a4 p: }3 g
- }
. |& K6 Q' {0 @& K* Z& _' _% ?/ ^
+ w" D) ?. Y6 e# S- studioSplineBuilder1->ConstraintManager()->SetContents(/ v" i- i- | Y) W! o5 Q
- geometricConstraintData);: w8 q8 z2 i4 q$ z/ L' L
0 l2 D! @0 c/ F3 r9 {" \; @- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();6 G4 C$ P+ [* z K6 G, d3 ~
- Spline *theSpline = studioSplineBuilder1->Curve();
2 o; h1 a* Z8 C' H
7 ]9 X6 b' `" _; C) H. S# |6 p- studioSplineBuilder1->Destroy();
; Y) r2 r. X$ ]2 x# E
" @: D' w8 m- l. b- return theSpline;
5 n# l5 D" ?. t: }" ^0 l - }
) [ ~& _6 J) r: V - 7 ~% H8 N% D/ t. d7 P% W
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
1 U0 \6 l6 {7 o; h - {' h; m9 T# @/ _# N0 @) A
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");0 _+ \8 R4 W' D4 P# [/ a
- if (!thePoints.size()) return;. x3 I7 G$ Z. g1 U; A
3 x& n5 p2 _" n+ G7 f" [- Spline *theSpline = createStudioSplineThruPoints(thePoints);; p5 r) P7 o- Y& u- ~
- 7 S# |( t/ Y7 @8 S: v$ E
- if (theSpline)
3 p/ z {, m; f6 Z - {$ L! H7 {: I% z3 P! W) m
- theSpline->Highlight();
' Q+ m; j( P$ V U - uc1601("Studio Spline Created Thru Points", TRUE);
* T6 t) t! E# Y5 b$ e - theSpline->Unhighlight();
) ~0 R& N g1 `, n) w5 m0 O - }, u# \; k5 s2 o" s* T7 Z: T3 U* X
- }/ ^2 m- C# r# c9 C( t
复制代码 - L7 s( F3 ? q) l
" k4 `0 Y3 \" G: U* i) E' M
, _* L2 K' _7 q! X1 l |
|