|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线% G" l% a0 v- C& y
- #include <uf_defs.h>/ ]5 V2 ?; w2 _* c* K
- #include <uf.h>
8 i$ e3 w! U( D Z; p - #include <uf_modl.h>+ l4 S$ }, ~/ D* y) w7 h4 E
- #include <uf_object_types.h>& H1 n3 M+ H' @ f! v% y3 @
- #include <uf_ui.h>/ T8 V8 ]7 N' E- Z
- #include <uf_modl.h>
. n2 f6 G# {; [2 _5 m0 }; P - #include <NXOpen/NXException.hxx>
/ r% ~" L) X5 d! K - #include <NXOpen/Session.hxx>
+ F; j7 C, c3 t9 z6 [' Z d9 E" i. w - #include <NXOpen/Selection.hxx>" f+ S! @- _( a* q: \6 R# l
- #include <NXOpen/Builder.hxx>
; Y( k# t- j% }& e/ u - #include <NXOpen/Features_Feature.hxx>
" k/ p, ?0 A3 `% ~" ~4 W - #include <NXOpen/Features_FeatureBuilder.hxx>
2 z+ G g0 O" U! t - #include <NXOpen/Features_FeatureCollection.hxx>3 ^+ ]4 p/ s4 q3 r- E
- #include <NXOpen/Features_GeometricConstraintData.hxx> x+ C" c' `8 x* n+ Z) q* C# R
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>% [3 _5 W+ p7 |8 z2 [ Z- P
- #include <NXOpen/Features_StudioSplineBuilder.hxx>
2 T& A& F( O( z2 ^; u" e* C - #include <NXOpen/Part.hxx>
& @5 I0 P7 y, \/ b - #include <NXOpen/ParTCollection.hxx>) m5 ]1 }0 X- w& m. m6 k" `
- #include <NXOpen/Point.hxx>
5 I) |& Y8 @8 N }' Q8 P - #include <NXOpen/PointCollection.hxx># y, y' J. W/ P) a. u+ [, m# W
- #include <NXOpen/NXString.hxx>
% N0 {0 A( E7 v, d: C - #include <NXOpen/UI.hxx>
g+ \& ^+ c* M) z - #include <NXOpen/Spline.hxx>
6 m p, r& g; r/ y# A2 G - #include <NXOpen/NXObjectManager.hxx>& |8 H' h0 N, O$ j$ E, a' M
! I; |+ b' a( O- _- using namespace NXOpen;: _ D! e& K) y5 a* V
- using namespace std;; `9 ~) w& S0 A+ w: ]7 d
/ }9 x. e' i% c6 d _3 f' _- n- extern "C" DllExport int ufusr_ask_unload()
& T/ ]! A' M, x- i' M" \ - {5 G6 X4 G1 L: Z& Y% z
- return (int)Session::LibraryUnloadOptionImmediately;6 U( s/ P' I. ]# V+ e2 b
- }
1 X+ @- C& E. e3 F - * H/ K0 Q5 y6 Y' L4 `
- static vector<Point *> selectPoints(NXString prompt)
& _3 ^1 O9 v0 D- b - {; I2 h7 ]( u9 K( {4 r" H% {5 q
- UI *ui = UI::GetUI();
3 W- r" r5 T T# N. u - Selection *sm = ui->SelectionManager();
. E; b+ w3 a' V - std::vector<Selection::MaskTriple> mask(1);
: L9 S o4 n1 _7 l% Y9 i8 B - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
/ o" q0 m6 O; B; B) N/ a/ J6 c' c - std::vector<NXObject *> objects;
* u' D. b) s8 ^% t6 B4 A
Z1 `: @, y$ S% {+ a1 M- sm->SelectObjects("Select Points", prompt,
; @7 O) `; ?4 ]+ a* D [ - Selection::SelectionScopeAnyInAssembly,
+ E8 I2 N* ~3 e# ] - Selection::SelectionActionClearAndEnableSpecific,
5 t5 Q/ g6 J8 Z8 j+ ^3 l - false, false, mask, objects);
* u' p) A( ^+ a* V
" ^7 g/ b# f4 A8 Q- vector<Point *>selPoints(objects.size());1 I; I# {3 L6 {8 t* g/ |, g
- for (unsigned int ii = 0; ii < objects.size(); ii++)
}% c- `7 }5 l7 B- M8 D- Z+ N - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);% j$ p6 c; d0 {& x
! R! p3 f: ?+ s( g. m# z% |- return selPoints;
2 y" Z! ?5 p) P( Y8 J& [# h - }$ Y( R; n8 E$ u/ b
- , r% p N i8 w* [4 M
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
) O/ r J! m. U. D3 o* A - { Y2 u1 [- ], e! w8 x/ u3 B
- Session *theSession = Session::GetSession();( ?$ C( Q4 [, E5 O
- Part *workPart(theSession->Parts()->Work());5 q" m# [) i" x8 H
- 2 C9 g5 u1 p+ Q3 a* e' p3 M
- Session::UndoMarkId markId1;
1 x, W" m" L, |4 Z% }- u Q - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
) w, }* g5 W3 v8 x6 P" k1 B - "Studio Spline Thru Points");
4 W& c% d4 Y3 f- i
4 B! G k; L; T' o2 T1 n- Features::StudioSpline *nullFeatures_StudioSpline(NULL);: s) L% y, K6 Z7 w
- . O; R! R# C- L' E: Z
- Features::StudioSplineBuilder *studioSplineBuilder1;4 S' ]' {# y9 a* `# c( V+ a% z( S
- studioSplineBuilder1 = workPart->Features()->
( t* Z4 ?6 w9 ]! t- ? - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
7 ^- p9 e3 E4 B - studioSplineBuilder1->SetAssociative(true);( l9 {5 t2 k. N7 c5 M1 U
- studioSplineBuilder1-> G) q _1 c, V9 K2 I
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
% n6 g) `# |/ ~: Z$ u) [( B - studioSplineBuilder1->
1 q& s- O7 ~) d - SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
. F- o$ [3 [2 {' R. ^/ g - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);- Z. P: g: | v/ m3 N% h
- studioSplineBuilder1->SetPeriodic(false);1 D( q% H4 v4 ]
- studioSplineBuilder1->$ i. A% Q1 y) b. Q/ d+ E
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
+ b) g' J& o. c( I$ B$ T7 z - std::vector<double> knots1(0);
: O' h3 d; {3 y# G - studioSplineBuilder1->SetKnots(knots1);7 x$ w. M3 ]1 O
- std::vector<double> parameters1(0);4 T7 i! C( o; L5 x2 ]
- studioSplineBuilder1->SetParameters(parameters1);
9 V! x5 `0 o1 X- `+ a; B - Direction *nullDirection(NULL);2 n4 B6 j, {$ D- \
- Scalar *nullScalar(NULL);7 j7 a- N0 k' u" N$ x
- Offset *nullOffset(NULL);
9 H; |/ H) `3 n& b9 `0 z# Z - 0 V1 u# m; I4 }; O
- std::vector<Features::GeometricConstraintData *>2 j* q7 e- a5 W! P: W$ ]# } E
- geometricConstraintData(thePoints.size());
# D/ ]3 H1 j1 F( Y$ _ - + v4 p8 n; j! m A1 R2 e, y/ d
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)" J2 S. i6 i( T3 d- J$ p
- {( Z+ F% P7 a- J( I, K: l
- geometricConstraintData[ii] = studioSplineBuilder1->& l$ F; v" x4 r2 B& Y- z5 I' v; t
- ConstraintManager()->CreateGeometricConstraintData();: A8 Y, D3 W3 q3 k5 P
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
O( n# A2 r4 l. ?' T) r' H- h - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
& A: J1 W; N x9 N0 ~. P3 ^, c - Features::GeometricConstraintData::ParameterDirectionIso);
Q! L7 k* I% L5 Q! @% ^" m9 L - geometricConstraintData[ii]->SetAutomaticConstraintType(- }1 i- }( J; v4 {
- Features::GeometricConstraintData::AutoConstraintTypeNone);
* {% |4 I8 K/ L0 g: _2 l - geometricConstraintData[ii]->SetTangentDirection(nullDirection);( A$ w( s y2 Q8 u" [8 N: W6 O
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);9 U0 X+ k5 C/ c% }) ]) P7 K, Q3 S P
- geometricConstraintData[ii]->SetCurvature(nullOffset);% U2 g: Q- M) d1 Z$ B8 i
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);. p1 ?8 d+ D, }4 P7 F
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);6 K$ k( V3 n& e
- }
* T- o+ S1 }2 }, V - o: K* x" X7 w$ t8 j |
- studioSplineBuilder1->ConstraintManager()->SetContents(
1 P6 d$ ? n. l9 b - geometricConstraintData);
/ F( V% o: k N! l/ f0 n - / c( {/ q) z g; `9 b% P5 l
- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();, E X7 C- J' B' X+ F, J% m
- Spline *theSpline = studioSplineBuilder1->Curve();
, K5 ~: k4 C4 C3 ^; p1 {1 C( l
* m( Z5 A3 H0 m2 j- studioSplineBuilder1->Destroy();
/ i& d; R: p7 U/ T1 p: _, ^% \
, E% e5 W- x( t1 O3 l- return theSpline;9 ?7 e/ F8 V6 T! i% o% h
- }5 x! M3 _4 b5 i- F3 o
- & O0 `( Z3 O) b# r) x% d; {
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)* v1 R- O8 ^+ s' q2 g8 ]
- {
( | E1 k5 ^5 S' m4 l2 @ r/ } - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");% a, e w. e: B& o
- if (!thePoints.size()) return;
+ a/ i* K: b/ a+ |
6 Y$ Z1 u- E' \: x& l5 {- g- Spline *theSpline = createStudioSplineThruPoints(thePoints);
6 w1 V6 n! ^8 R. t# i1 e5 P - 5 W9 s) e3 ]: u. f3 O/ T2 e
- if (theSpline)
; O6 z4 z* `# Z0 {4 T" { - {
' S+ b y5 A/ x W' [ - theSpline->Highlight();
9 I- X( T' m: a( i - uc1601("Studio Spline Created Thru Points", TRUE);0 i7 ` d6 D; k. v% d$ ]7 D! B0 Z
- theSpline->Unhighlight();
/ _% J1 _0 _/ U# u7 F" ^ - }
& K* j3 }* Q' B) ~1 }8 i - }- M& s8 K3 e, U: w) @: h
复制代码 5 \4 s$ v5 E7 f V `. n/ q
1 ]4 ^( z" z! t1 F! Z! y
( t; r9 l2 _8 g |
|