|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线5 p, k! f0 {# r( E: `1 f
- #include <uf_defs.h>% a, U' p! g: N; x7 M$ G
- #include <uf.h>
' C. @, z4 L6 n1 ~' E! ~0 x - #include <uf_modl.h>/ m* N0 |4 R- I% q( F
- #include <uf_object_types.h>
) y9 x+ e/ T- ^5 x8 ]( T- f! a P9 T - #include <uf_ui.h>4 g$ N- i1 q, Z7 E3 l0 I3 E) J) o9 }
- #include <uf_modl.h>
! g+ C% u2 f( N6 Q/ e/ c - #include <NXOpen/NXException.hxx>* H! V3 c% i S' W K
- #include <NXOpen/Session.hxx>- \# H: M* I. x4 E: j" K
- #include <NXOpen/Selection.hxx>
: L9 O# |2 e- u0 m% P2 ]1 f# U - #include <NXOpen/Builder.hxx># K/ s: t) {7 a& }/ k% g9 n
- #include <NXOpen/Features_Feature.hxx>' s0 S; x' n0 D: ]3 W( R
- #include <NXOpen/Features_FeatureBuilder.hxx>
1 V! ~3 k0 c+ w' v1 a/ _/ N - #include <NXOpen/Features_FeatureCollection.hxx>
0 B4 B. X/ L8 \" m9 X: [ - #include <NXOpen/Features_GeometricConstraintData.hxx>( h% e, M( S' c. j, e' b4 V, j
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
2 i- O+ c6 p, Z Q" c- R - #include <NXOpen/Features_StudioSplineBuilder.hxx>7 ^" y5 v" C4 g- u; p
- #include <NXOpen/Part.hxx>$ ^* w; i9 Q3 s: l8 ?
- #include <NXOpen/ParTCollection.hxx>
8 h/ ^0 H4 ]2 `! [ - #include <NXOpen/Point.hxx>
/ l8 J" }. Z P! m - #include <NXOpen/PointCollection.hxx>
# S. z3 r$ f% H* {5 \3 d9 q - #include <NXOpen/NXString.hxx>0 M/ p# Q) e9 {3 o7 m7 L9 b
- #include <NXOpen/UI.hxx>
6 @) Y$ ~! R2 u- g - #include <NXOpen/Spline.hxx>
' V! v! E5 l7 P$ Z# ~ - #include <NXOpen/NXObjectManager.hxx>
0 c! V* W8 @ P, }* l5 b, _
) w3 s+ L% Z& l8 Z* D- using namespace NXOpen;2 Y. u8 v8 b8 |1 h( l8 H
- using namespace std;
/ @8 m8 Y; M$ u" j - % t' B0 T0 I. }) Y
- extern "C" DllExport int ufusr_ask_unload()
\: K+ H$ p$ R2 d: w* ~ - {" d; I" \) f v
- return (int)Session::LibraryUnloadOptionImmediately; Y# W2 v4 z, \
- }7 }5 N0 F: D- K$ h
- ; j* B0 s" p k
- static vector<Point *> selectPoints(NXString prompt)
5 {. ]* I3 o; m- r, Y; c - {7 M$ l" O7 \( H% N# N; \4 x5 N- d" e" ]
- UI *ui = UI::GetUI();: I, p% B2 [ L+ p
- Selection *sm = ui->SelectionManager();
) \$ K) I, M9 W1 p - std::vector<Selection::MaskTriple> mask(1);
6 [1 r, x. U5 [% o6 F2 m: g' i! S - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
# N+ n# R" m; `; g( F% d. g - std::vector<NXObject *> objects;
3 a0 v3 \( U2 Z( S3 s
4 S' t' I: S8 G$ ~: `- sm->SelectObjects("Select Points", prompt,
M4 g. c/ L; E, x. ~ - Selection::SelectionScopeAnyInAssembly,+ f, Y3 T1 T2 p' r; M/ X1 Z
- Selection::SelectionActionClearAndEnableSpecific,
2 e) I* ]# B" R7 o5 r; p5 ?; s - false, false, mask, objects);
6 J, b7 U4 U1 i- R - : K& y7 p$ X( M; R+ }& {* v) b
- vector<Point *>selPoints(objects.size());
8 p" p" }! q$ V& |) [ - for (unsigned int ii = 0; ii < objects.size(); ii++)/ i8 e: k/ j& I# Y9 L( L4 U0 T
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);" X% m* I! W$ |1 A* d+ v: Z8 i
Z! O& T s) I6 R' l' {* \- return selPoints;/ D( `" x' Z E$ O4 ?
- }
0 H) E+ C' S+ `3 M2 f& w4 F - % O4 f3 c8 N# Y# A* ?
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
( `2 I x* t! N. |) ^8 U# @, ?5 K - {
+ T) |6 _6 h) B( l2 e( Y' [ - Session *theSession = Session::GetSession();
, S" c1 W( q0 j4 z2 a& w - Part *workPart(theSession->Parts()->Work());
5 `% K& k+ o' t, u! ?, M7 a - # e( h/ b* Y! d0 ]! n4 n# b
- Session::UndoMarkId markId1;' x/ E) P4 [) U1 U: u/ {
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,, R3 D" [0 u* t: w7 F
- "Studio Spline Thru Points");" w8 s& I6 i* [ k
. s# P# Z7 L2 E3 w" ~/ H/ P- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
E& J; a/ x, O" S1 q - ' O! X, @) K b- f; V. s7 X
- Features::StudioSplineBuilder *studioSplineBuilder1;
' p6 U) ~/ A' m7 L- K( M _ - studioSplineBuilder1 = workPart->Features()->: b( x9 W* U; W) D: O: T
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);( ]" ~7 x$ O" G9 K4 x3 D6 j
- studioSplineBuilder1->SetAssociative(true);. ^6 W: q5 s. L3 K
- studioSplineBuilder1->
9 {5 G' K* p8 o. ]' Y- }3 @9 ` - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
4 H1 a+ E" w! ~ - studioSplineBuilder1->+ n2 ^5 G9 D$ Y
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
: `- s+ \$ P7 h: p9 `# s# V - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);- j* ~5 w/ U. r+ K: U' X1 @5 ~
- studioSplineBuilder1->SetPeriodic(false);
- e' o- o. s+ q - studioSplineBuilder1->$ Q3 \7 ^) q" W4 ^2 W% ~: ]
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);$ @9 L7 i" l& V! p A7 V# c
- std::vector<double> knots1(0);
" d1 [# t( o7 S6 Y& ^ - studioSplineBuilder1->SetKnots(knots1);
0 u: [; }1 l+ A2 Y0 i - std::vector<double> parameters1(0);
! o: \3 b' f: k0 g - studioSplineBuilder1->SetParameters(parameters1);
5 ]4 l- ^8 M$ S" U' ]! i2 w' o f# c - Direction *nullDirection(NULL);
: F. l, x: {! P1 O3 |* }: Y0 C* {" | - Scalar *nullScalar(NULL);( p1 z2 m- E, u( A, ^6 x5 X: n' [8 m
- Offset *nullOffset(NULL);
5 O# u. l8 q5 U! B9 _/ N9 D0 u, g8 X) R5 U - & e9 P# o3 M, f% h% ~+ C
- std::vector<Features::GeometricConstraintData *>
D9 q7 ]* }3 E A - geometricConstraintData(thePoints.size());& [8 c' f( p0 Q0 ]1 n- J* N
7 k2 h% N) h$ d4 j7 D. Z- for (unsigned int ii = 0; ii < thePoints.size(); ii++)" i$ r0 c% N! \6 q; O' D6 a( C
- {+ u7 F1 ?8 V2 V1 B, N( w# ~
- geometricConstraintData[ii] = studioSplineBuilder1->
2 z! g. U6 O) Q- D8 F2 _1 ] - ConstraintManager()->CreateGeometricConstraintData();7 q2 T0 {% |) h. k, [! F. k
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
. P6 W! ~( g5 ~ - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
{( \1 h9 G6 r8 ^7 L3 x$ o' G - Features::GeometricConstraintData::ParameterDirectionIso);5 ?& h7 Q# y; ?4 j" I
- geometricConstraintData[ii]->SetAutomaticConstraintType(! r/ _4 _+ _9 w3 T1 p- q! P. o
- Features::GeometricConstraintData::AutoConstraintTypeNone); @( z: a3 O z( x# b' o. K0 x0 M2 e
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);; n$ `2 v! `: [) z
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);) X6 @5 R. \* z7 D) U
- geometricConstraintData[ii]->SetCurvature(nullOffset);
( Y! N: p# F& v1 T; o3 n* F - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);% Z- _! V8 W, r3 V$ O
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);9 n. L$ g {: M* J: U; t2 {
- }0 U$ m* O4 A, z
% o: Z5 f9 c- V; Q) p, D- studioSplineBuilder1->ConstraintManager()->SetContents(6 L. ^+ b; N( i; t# l
- geometricConstraintData);3 z0 y3 q5 x) {* c# d' \* D! Q
8 m/ m) E; }0 h9 _) I8 a- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
4 p* Y1 u& m, Z! U$ U - Spline *theSpline = studioSplineBuilder1->Curve();* S2 I7 ]6 r( p# ~% l, H* c
* G" [9 ?/ p: Q+ q% C- studioSplineBuilder1->Destroy();2 C+ I' U' J( g' d
8 W) m F( b! _1 _4 `- return theSpline;
+ V. A: D& m* X9 M4 T& U6 M - }2 y, {7 X3 y" @
- ( E. x1 K- E; d F
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
6 ^" R* n4 R" B! Q a - {3 x: S* H2 n# F1 O' I3 y
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
1 b" E; h3 k) N# M& k - if (!thePoints.size()) return;% Z, `: k: N t& \! ~1 ?3 G7 e
9 N$ Z: q" p2 f- Spline *theSpline = createStudioSplineThruPoints(thePoints);
/ m+ [& k9 U$ ]; P
9 H" H' m) E* B* h- if (theSpline)( K4 l, x' s) ?1 A4 W+ Y
- {; J4 N/ Y" J* W! T
- theSpline->Highlight();
% m; @0 C( n8 O% |0 E - uc1601("Studio Spline Created Thru Points", TRUE);
# `5 J' O$ F3 q( s- r8 i - theSpline->Unhighlight();
. v5 h& q S/ [" [ - }
( R N! I* u! d1 I! F) M - }
7 J2 E; R# S; @/ Y# d* b
复制代码
7 k' ]( Y$ `% h- V& N
9 S, i7 d) B4 f9 E0 M4 @2 P4 Y4 Z+ a6 O# U% Q& `( t! U9 U" W6 C
|
|