|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线/ Y& f! j' l K* |: N
- #include <uf_defs.h>* O8 v5 N" W% _% N, I5 c
- #include <uf.h>2 f' {7 o/ ~) {* ?" t3 L5 M3 L
- #include <uf_modl.h>
* d- n) r2 j7 ?% ^0 N - #include <uf_object_types.h>
5 G n$ q- o8 B& D - #include <uf_ui.h>
' l$ E, b2 D5 N+ j7 j* Q - #include <uf_modl.h>" K' F: W, ]5 a3 _
- #include <NXOpen/NXException.hxx>3 @7 G4 q& f1 E4 B/ z- v- h# q1 ^. _
- #include <NXOpen/Session.hxx>3 W4 f: | {* ?( Y" V. P/ p8 n4 m
- #include <NXOpen/Selection.hxx>
, R! W% p5 Z+ c - #include <NXOpen/Builder.hxx>
! P( w/ @9 y: l- X# {: W6 F3 L, ? - #include <NXOpen/Features_Feature.hxx>
; \& N0 v, x/ `) S% B8 `$ Z9 V - #include <NXOpen/Features_FeatureBuilder.hxx>
% c5 B$ p% N# R/ R - #include <NXOpen/Features_FeatureCollection.hxx>
( U6 ] q. U5 ~. N - #include <NXOpen/Features_GeometricConstraintData.hxx>- ?* l, a- H/ D! r' }4 h
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>/ F. u% q8 R: j" e+ G
- #include <NXOpen/Features_StudioSplineBuilder.hxx>: N! K, w0 j! u) R0 N+ H' R8 l9 M' `5 U
- #include <NXOpen/Part.hxx>7 R7 U- ~0 j: b8 F: \# Z8 J% ]
- #include <NXOpen/ParTCollection.hxx>* J4 [9 {8 E3 ~, r7 ~
- #include <NXOpen/Point.hxx>
$ U4 c4 H1 b [" q/ p* m - #include <NXOpen/PointCollection.hxx>
% S) f8 N$ l2 O+ c/ Z - #include <NXOpen/NXString.hxx>, R4 k3 a' z0 M$ C
- #include <NXOpen/UI.hxx>4 [ [$ I, E# S
- #include <NXOpen/Spline.hxx>1 z# q( H* Q- g4 I1 q
- #include <NXOpen/NXObjectManager.hxx>
) `& K! m( V5 ?. O% J
- ?: f& e: A/ p- using namespace NXOpen;
4 |" a: U- T7 K - using namespace std;
# |( b! a+ `# J, Z - ' t8 q% g; Z8 n2 H
- extern "C" DllExport int ufusr_ask_unload()" l- r+ J- A# O8 q# N
- {
% a7 V0 x4 C- z5 R1 B! ?, T k - return (int)Session::LibraryUnloadOptionImmediately;% j' L5 p7 G3 i+ y
- }1 i( q0 j& b; c) ^: h$ R: z
- 8 c$ ]) E8 f! W1 ?1 \ n; B2 A; i
- static vector<Point *> selectPoints(NXString prompt)
' R* m4 Z# n2 l7 k: j0 Z, d - {' n C# B; j* l4 `1 d, b2 j {
- UI *ui = UI::GetUI();
0 `) D! z: _' J5 Z8 {7 U - Selection *sm = ui->SelectionManager();1 J3 Y5 @! K1 Z' L4 _' }; |. L
- std::vector<Selection::MaskTriple> mask(1);5 u( `8 [9 X# H7 h* _: P" [; o
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
& o3 ?5 ^& X) N - std::vector<NXObject *> objects;8 ?! Q$ H- N0 z1 z; P2 V5 Y
- 9 i9 }! c1 p& e
- sm->SelectObjects("Select Points", prompt,
6 i2 W8 O5 [& S9 ]# Q# n - Selection::SelectionScopeAnyInAssembly,
7 Q+ h2 r6 B' D! W1 K - Selection::SelectionActionClearAndEnableSpecific,1 Q6 O8 b) U' h+ t" R" _
- false, false, mask, objects);* L) m% W- l6 q7 p$ y
9 [2 N1 }+ ]8 |6 N% b: s" P' Z- vector<Point *>selPoints(objects.size());
V) s7 t# h" ^9 Z9 A: N5 \8 ^ - for (unsigned int ii = 0; ii < objects.size(); ii++)4 z7 k: h0 a$ V% x- N) F
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);1 N" v2 l) }! q& Z
- m- ~: N5 B# e7 B) V% E: ~/ a
- return selPoints;
( U; W) I8 p* F; C5 W8 O+ j - }+ l# `1 `* t' q, K
- n) o( m& p' Q3 s" w
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
h9 X& Y3 e+ n - {7 G8 M" P: Q4 q# p
- Session *theSession = Session::GetSession();
' h. e! J- {) y. l8 z. s - Part *workPart(theSession->Parts()->Work());$ k+ J4 t1 P; j7 W& f. V9 H! ]
- z( `4 e' `9 [( I4 i/ x- Session::UndoMarkId markId1;) {. g2 |" Y& I# j8 J! n8 X
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
# `8 ?4 a! x. g' A - "Studio Spline Thru Points");+ s" x0 N4 R( f8 \ D9 y z
- ' B! C; `/ l' |1 z4 d& ]- x% y
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
( i* ]$ ?( i5 P/ N$ L8 `0 G - 2 L$ _) d2 F) B
- Features::StudioSplineBuilder *studioSplineBuilder1;) J" d% D8 Z* ~* R# c$ [
- studioSplineBuilder1 = workPart->Features()->
( l% Z7 u4 Y# f. C, R - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
+ t/ w% r5 Y2 W - studioSplineBuilder1->SetAssociative(true);
$ a5 a8 R" W& m" y0 {* j) `" f- l! \ - studioSplineBuilder1->
5 l8 d; @- x" U& W. F - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
: e5 V- M- m: B2 O+ G - studioSplineBuilder1->9 O' ]2 y" P G& X$ @
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
+ }- G1 q% @, [/ `& h - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
' S' G0 A) z* U$ C" z" k1 A - studioSplineBuilder1->SetPeriodic(false);4 Q$ F1 I# P: G# \ t; s
- studioSplineBuilder1->
; s) P, F/ q2 m9 |; u! n - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);4 H# K. x3 u0 c8 Q- b
- std::vector<double> knots1(0);
) z4 t$ d9 N) j- F - studioSplineBuilder1->SetKnots(knots1);4 I! G8 a8 H+ ~) e' @$ [3 b
- std::vector<double> parameters1(0);
5 B1 O3 L, ^7 l - studioSplineBuilder1->SetParameters(parameters1);
! `3 x* P: C, }/ R+ r! C - Direction *nullDirection(NULL);
9 q) }% B, v+ q: l& B8 } - Scalar *nullScalar(NULL);! J+ _& ~4 ?. P5 x% B; W
- Offset *nullOffset(NULL);, @; l4 B; M. b: G$ `* k
& o- k4 S/ q* o" `+ { x- std::vector<Features::GeometricConstraintData *>
5 j6 k! ~( F! ^3 ^ a3 z. n - geometricConstraintData(thePoints.size());, O+ x- o! f" J1 t" p" k, |! S
! d4 f6 M ]7 Z# g- R9 f2 ~# S" Y- for (unsigned int ii = 0; ii < thePoints.size(); ii++)/ ^, R, Q8 e0 Y0 D; R; a
- {
7 b6 P7 c2 U6 S* Y7 Z, \! K - geometricConstraintData[ii] = studioSplineBuilder1-> k% Z/ Q* O2 ~& w
- ConstraintManager()->CreateGeometricConstraintData();/ w4 [2 H2 k" f3 J! G7 l# F2 `$ Z: T
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);% v( H$ M9 s2 _& w
- geometricConstraintData[ii]->SetAutomaticConstraintDirection( i4 I8 b1 P1 H: ?7 V/ B+ ]
- Features::GeometricConstraintData::ParameterDirectionIso);& j" M# l: l4 l
- geometricConstraintData[ii]->SetAutomaticConstraintType(0 i6 s1 J( B* u2 T3 v" M& ^ X, m
- Features::GeometricConstraintData::AutoConstraintTypeNone);# B6 |0 {' y3 J0 Y0 z( D
- geometricConstraintData[ii]->SetTangentDirection(nullDirection);
4 M7 T; U' }6 V$ l# s' k0 N/ W; C# X - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);7 R. _* j. ^3 {7 \' S% \
- geometricConstraintData[ii]->SetCurvature(nullOffset);/ e) s7 C9 T6 ?3 B+ \
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
3 G p0 u4 T# [' t - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);7 I/ Q$ d0 @5 g4 n E# I
- }
) Z3 H3 }' q% o$ b& h - ; z" |# T$ @) w7 V
- studioSplineBuilder1->ConstraintManager()->SetContents(
* @7 U9 ~1 G& e4 h* @( O3 E" z& f - geometricConstraintData);
' u& I1 s' d* ^* V
; t3 q/ F( V/ J+ B- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
. A1 v6 z6 n: w. Y8 e0 k - Spline *theSpline = studioSplineBuilder1->Curve();
# `- W' Q6 l4 E; ~( \; X
3 l0 N5 O) {* r; e, w/ L! P- studioSplineBuilder1->Destroy();
: E4 m# d2 d, m) [ - $ Z' S5 X7 x+ u$ q
- return theSpline;
+ A1 Z( V3 A8 h q: ]5 N - }
6 l, ]: J& _1 j8 g# k
3 h' q H) a2 j. a( u$ R; f- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
% U* [- N/ A. w& p7 s$ x& ~: M - {6 A% x/ c( i, P- O, l
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");, x1 S1 o- H/ S# w4 u
- if (!thePoints.size()) return;
, x0 F5 c4 W* f6 g - & _$ ^# f& A$ |- Q5 g
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
" b! m: P; R0 x! V' _
+ ]) M$ n; d, B# a( ~% C- if (theSpline)" W6 Q0 O5 e) [ v: ^7 g
- {
2 _/ w, _6 K2 H ^+ ~3 ]; @6 H - theSpline->Highlight();6 G O0 y: \ M: X: d) u9 F
- uc1601("Studio Spline Created Thru Points", TRUE);* l# ~6 M) r: u9 a3 j J4 u1 `; D4 A
- theSpline->Unhighlight();) @" D& x3 F X1 Y$ r: H$ Z, T) \
- }; w6 R/ t+ f/ s3 L% Q9 w0 P( k
- }& @9 E3 V6 P, @6 T8 x
复制代码 + |. m' z8 c9 S
( v }( d. ^% J- Q, f7 w
- y/ d( V. r5 x! S2 c' b3 L |
|