|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线$ J2 L: r5 x( X: X! {+ u' a
- #include <uf_defs.h>
# o8 I* R/ F! ]) ?+ S; u - #include <uf.h>$ s! ^3 U# c+ H& G4 U
- #include <uf_modl.h>1 C, E5 {+ h; Q$ l$ D8 {
- #include <uf_object_types.h>0 W$ y; h2 Z& x% E
- #include <uf_ui.h>
1 `/ X4 z R6 O - #include <uf_modl.h>
, b. q# P9 I3 N; W- z - #include <NXOpen/NXException.hxx>
0 g( s+ g! @1 y6 ] - #include <NXOpen/Session.hxx>5 P9 y4 ?* X" p( l. N
- #include <NXOpen/Selection.hxx>' F: V, Y& X' B# H9 s
- #include <NXOpen/Builder.hxx>
- }. S- O" I" M - #include <NXOpen/Features_Feature.hxx>
1 Q* T: B t+ L6 J - #include <NXOpen/Features_FeatureBuilder.hxx>
8 V: E7 j; k1 O3 \) E* f# f, D - #include <NXOpen/Features_FeatureCollection.hxx>
$ B! v9 A& }9 S1 d6 _+ ` o4 @1 \9 ^+ o - #include <NXOpen/Features_GeometricConstraintData.hxx>
* x" K$ \& J. s: Y9 {6 A - #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
0 t; ?5 ]6 |$ \ - #include <NXOpen/Features_StudioSplineBuilder.hxx>
6 I# h. r$ m0 O6 k. s$ Q - #include <NXOpen/Part.hxx>1 i6 V) b( Q G3 }5 p
- #include <NXOpen/ParTCollection.hxx>( S% F& R" h1 o- D( V
- #include <NXOpen/Point.hxx>
6 F" W5 P+ v; V& Q - #include <NXOpen/PointCollection.hxx>
( i8 \6 o7 z: O) e! ^/ x) N/ I - #include <NXOpen/NXString.hxx>
- X) n3 f8 C. c1 K( d1 t/ Z - #include <NXOpen/UI.hxx>
4 c9 L* U3 a8 e7 d4 @ - #include <NXOpen/Spline.hxx>: ~3 L3 r* U+ y( o. j8 q
- #include <NXOpen/NXObjectManager.hxx>
4 |: H$ |9 ~( @8 v- y( ?& N9 s- k - 6 |# n7 Q+ W3 q1 }# N
- using namespace NXOpen;
2 T. J, l4 u& b* a, r- Y - using namespace std;( F, y# Z& ], w( [) W# O& Y
8 H% w" e* B4 J5 z- extern "C" DllExport int ufusr_ask_unload()
7 o0 n, S& c1 T - {
! N7 J& R' x3 M% {6 Q0 Q5 | - return (int)Session::LibraryUnloadOptionImmediately;) _: N& F, ^/ s, O/ s$ t
- }* ], o$ u/ M. P6 L" |7 r
$ [5 H: b! t, V4 u5 M' f- static vector<Point *> selectPoints(NXString prompt)5 E$ d N) a) _- J' r( Y, a
- {: s! v% q6 [" Y
- UI *ui = UI::GetUI();/ I! C% d/ x0 E9 V) F: ~; @
- Selection *sm = ui->SelectionManager();
8 m) f; ]) `3 a+ O" H - std::vector<Selection::MaskTriple> mask(1);
* ~9 b |. l" F( `$ g" i - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);; t- {/ v" \# }- n; |9 g0 s9 N
- std::vector<NXObject *> objects;* _: e. G' H M* l. f, `
) c5 q5 K! [0 ?( D- sm->SelectObjects("Select Points", prompt,$ z+ ^, S+ x7 q: `4 u& j* U
- Selection::SelectionScopeAnyInAssembly,6 A# }! ]4 G4 G8 b& p
- Selection::SelectionActionClearAndEnableSpecific,
8 J' U7 B/ f4 }* {( T - false, false, mask, objects);$ X/ @+ O/ k m0 _9 b
8 ]5 R% i/ I- y/ Y- vector<Point *>selPoints(objects.size());
T6 v# V4 m- ~% [6 v - for (unsigned int ii = 0; ii < objects.size(); ii++)
# D, l4 n/ ]2 t$ Z; p; r6 x - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);+ {* c/ Q: ?) X- \( u
* n) ?, u# \0 E2 o: j- return selPoints;
% z8 L/ M# ]9 R. F. H: x - }7 a& J9 ]$ n' b! Y7 G7 I$ U/ E0 d- g
) k' y( Q. X( u+ \- g6 k- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
0 P5 Y9 l" D7 g9 I1 [ - {
" p0 h% n* D2 |1 p- ? d' d - Session *theSession = Session::GetSession();
6 j; @3 n0 M+ r( A* m - Part *workPart(theSession->Parts()->Work());" t' \/ u& n7 E/ ?+ m0 z2 t2 e
- ; |6 j4 a N7 D" ^" a
- Session::UndoMarkId markId1;
& u; V8 s; b+ m. p' i - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
: i4 S7 N# W$ w4 @ - "Studio Spline Thru Points");" Q! |5 b; B2 P# h& }
- \" }: ~7 J6 f; I5 d/ f9 W
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
$ v* k7 z* K. v% ~
$ F% Y% b0 e3 n% N+ p* S3 _- Features::StudioSplineBuilder *studioSplineBuilder1;
/ K" Z" x' A6 d' t$ f' k - studioSplineBuilder1 = workPart->Features()->
# y% q) _: A0 J0 e - CreateStudioSplineBuilder(nullFeatures_StudioSpline);' P/ D l% @7 o; |* h
- studioSplineBuilder1->SetAssociative(true);- O! Q( d5 v/ j o2 \7 a
- studioSplineBuilder1->( G' g* a1 {( @, C, U+ t- L
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
4 R$ h: h2 d- ]2 {0 i( C - studioSplineBuilder1->+ [2 T2 {7 |* o8 {7 v
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);, U! B, c$ m q# q4 W- @$ T
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
; R2 T( g9 N; v - studioSplineBuilder1->SetPeriodic(false);, j- v" z! S+ v: r9 Z
- studioSplineBuilder1->' z7 X! G/ a. ]+ e1 J# M/ r z
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
" O$ {: a7 @7 t" } - std::vector<double> knots1(0); b3 x& g B' O6 @3 d% B6 i2 ^
- studioSplineBuilder1->SetKnots(knots1);
9 v; |# d3 n9 r& e1 o4 D/ U' A - std::vector<double> parameters1(0);
! `" @/ ~5 s) z) d7 ?6 R) Q - studioSplineBuilder1->SetParameters(parameters1);
4 T; A, `: ^" J" {& b - Direction *nullDirection(NULL);
9 q. e" l2 r7 J' q7 U1 w }) f - Scalar *nullScalar(NULL);: }+ ^1 F8 P H
- Offset *nullOffset(NULL);+ t$ {, m* V9 v+ B8 j) K) n- w& m
4 ?4 p8 p! ^* \& X5 s- std::vector<Features::GeometricConstraintData *>
& ^4 T6 z8 E% [7 O. \- }5 Q0 N - geometricConstraintData(thePoints.size());# l+ m& b1 N3 j( w
& o+ u* t& P* S# [0 u$ y8 k+ N% _$ H; M- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
( I& `7 h: w6 { s" s - {- l1 I5 k2 S2 {2 n# t# H, C
- geometricConstraintData[ii] = studioSplineBuilder1->6 v s+ ]& l0 a) p6 {/ y* G; G. d
- ConstraintManager()->CreateGeometricConstraintData();
6 x; E; a3 O$ E/ q) S - geometricConstraintData[ii]->SetPoint(thePoints[ii]);# S) g; z# N; L, _2 d, u
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(: e- [7 u* u( W# \- Q- A$ B
- Features::GeometricConstraintData::ParameterDirectionIso);
. o+ a2 i8 u" Q% n+ Q - geometricConstraintData[ii]->SetAutomaticConstraintType(/ r& H8 @& m& T7 X' F" H8 f
- Features::GeometricConstraintData::AutoConstraintTypeNone);
+ s& r# z, W% P. ^/ P$ Z6 d8 ] - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
8 }" Z- k1 q& V" A4 `8 v! |4 ~3 ] - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);* p: i) t9 l" _2 Q. j/ e0 ]! w5 {
- geometricConstraintData[ii]->SetCurvature(nullOffset);
0 O! e0 ]) c0 }1 ` - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);4 `4 W7 v2 A$ L o1 L2 Y
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
. M u8 D/ {& U8 H7 L" E+ ^5 U( O - }
3 L, F3 L( U6 n' N. E
& E" `$ P" x9 i' ~- studioSplineBuilder1->ConstraintManager()->SetContents(+ p6 n f Z; l0 A
- geometricConstraintData);
% j# F: v5 s, K. J" w, b. u; @ - " [ Q* f$ y* s l8 p& z: G
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
; }' n" K' @) S; y5 d - Spline *theSpline = studioSplineBuilder1->Curve();
, {, f. a6 p s& z, o/ U - 5 t; C- f, M, L& V
- studioSplineBuilder1->Destroy();
0 V# A' q4 W: d7 q$ H/ O _5 M
: I2 O- f6 e+ c& V- return theSpline;
2 M5 b9 z- L* I( w8 a - }% c" \0 q( } p1 z1 \
- - {( }# D7 O. e! G9 j v$ ?; a! f$ O
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len): m6 t7 X6 q( E
- {* t3 Z4 I+ V$ A* n
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");) o& h7 D) T! [
- if (!thePoints.size()) return;
) W( Y- E5 y9 X9 K+ d; W8 c. Y
1 y7 s \2 I( q& r) R7 a/ v- Spline *theSpline = createStudioSplineThruPoints(thePoints);4 Z4 K3 K. v% a6 X9 f$ [; ]! g3 X
$ q! n9 r4 D( K8 C- if (theSpline)& o" ] T* l" @0 F; y
- {: x; Q& H3 g/ T: k2 A
- theSpline->Highlight();
* z6 R/ [' `, k$ A1 y! R7 S - uc1601("Studio Spline Created Thru Points", TRUE);
7 k8 V5 V- n+ F. o - theSpline->Unhighlight();
) W( u7 s; Y9 r) M5 ` - }* }) t( D, [+ d$ {: P
- }! Q. x3 W8 x" v# J+ x* b' x g
复制代码
" G( J, v: h* h! T9 R" l9 G' Z C! B7 `' c6 u f9 j
7 s u R9 H; M, k; x
|
|