|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线: i, R* F( h4 Z/ a I) N) N
- #include <uf_defs.h>
3 Y3 s2 J$ M% h+ \: @1 k3 B; N1 [7 p - #include <uf.h>
5 h- X Z2 z: P* U1 R, J - #include <uf_modl.h>
1 K. v3 E* l) M% Z4 \ - #include <uf_object_types.h>
5 S, G9 i# T# r8 p; L. _ - #include <uf_ui.h>
( `+ s: L& P5 R - #include <uf_modl.h>
# `" k; X, Z, J" C - #include <NXOpen/NXException.hxx>
5 I! g+ o8 A D% L3 F - #include <NXOpen/Session.hxx>
2 P5 Q, E0 }1 y: W1 p - #include <NXOpen/Selection.hxx>( o' ]- g# `/ L
- #include <NXOpen/Builder.hxx>
, ]1 v4 T7 G5 `# C - #include <NXOpen/Features_Feature.hxx>* c& R" Q2 L0 Z2 u0 C' u
- #include <NXOpen/Features_FeatureBuilder.hxx>, e! f% \ _9 T5 c& a; z
- #include <NXOpen/Features_FeatureCollection.hxx># M6 m8 E4 W& ~9 h9 }/ ~5 I
- #include <NXOpen/Features_GeometricConstraintData.hxx> b! P, ]; ]& `5 h2 V# w
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>
+ r4 F; x- s% [, q7 n |; ^# c' C - #include <NXOpen/Features_StudioSplineBuilder.hxx>
) M# n7 q/ e) c! Q# I7 F3 s - #include <NXOpen/Part.hxx>
9 s8 {& L4 v6 h+ {! \& w+ X - #include <NXOpen/ParTCollection.hxx>
2 R9 M1 s: \1 h- j! h: j, R5 g - #include <NXOpen/Point.hxx>
* p' J# w+ V! f! H) U/ p - #include <NXOpen/PointCollection.hxx>" C4 S) Q( z: I7 {" m2 v R9 [
- #include <NXOpen/NXString.hxx>. z4 D# [5 Y" e/ q' p" ]! {
- #include <NXOpen/UI.hxx>/ E, n4 |* k+ H9 r. _
- #include <NXOpen/Spline.hxx>
, J) L# A }' D0 P, | - #include <NXOpen/NXObjectManager.hxx>
+ e9 ]- {2 r+ @! \' r+ u - ' r, L" T4 k( o# ]) K* o/ h6 R; K
- using namespace NXOpen;
( J$ h' L+ _0 d - using namespace std;+ w) k' F% t3 O- j
+ m& Z" U% U: b' B, z# y- extern "C" DllExport int ufusr_ask_unload(): c. F3 y8 K5 u3 A6 ]
- {
* M# X+ w; ?; Y6 S8 h' z - return (int)Session::LibraryUnloadOptionImmediately;# l5 b6 `$ L' H" ]9 R
- }/ r3 D5 G% P- N9 S: X, V2 q+ s
- / L) R, U. f+ C+ e# E
- static vector<Point *> selectPoints(NXString prompt)
( [1 Z3 h3 i# B5 }& E8 }9 m - {3 b y- B( H% x6 e) X
- UI *ui = UI::GetUI();3 c; ~$ q% w' ?# k# @$ Z; V
- Selection *sm = ui->SelectionManager();
@% h, a3 K ~8 E - std::vector<Selection::MaskTriple> mask(1);
+ b8 w( S0 p1 V1 X - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);
0 [0 C+ |2 S$ ?& ^1 ` - std::vector<NXObject *> objects;! b8 [3 ~0 ]( X* l
- / \) C6 c! T2 ~1 c. |% F7 C; }! V: ^
- sm->SelectObjects("Select Points", prompt,2 ]/ d% ^) V9 @8 e* I; N
- Selection::SelectionScopeAnyInAssembly,
& y( v2 Q% |, }$ R9 M - Selection::SelectionActionClearAndEnableSpecific,, A: |" x7 U' L" D% D2 M
- false, false, mask, objects);( ^. X1 ^ K3 v* T% l7 q' _0 D6 U
; Y) t" I( {* Y a- vector<Point *>selPoints(objects.size());( ^3 }* w1 K# j% U6 z( U
- for (unsigned int ii = 0; ii < objects.size(); ii++)
4 v% d" @5 O6 w( J/ C }' m- P - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
4 A8 T5 K/ d W; V& {* Y9 Q) |
) M7 S) I! y9 ?+ _/ n6 d- i- return selPoints;4 d# `+ o5 S0 ]6 q! N6 @6 M- P
- }" G$ S: D' o2 d5 k$ ^0 K
- 2 T$ E5 P! D0 s' |
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
5 o8 N. r) v4 O- C: K - {
) t5 [/ ?; n2 @; {, c - Session *theSession = Session::GetSession();
: U1 |& K. e% }, w& ?7 C - Part *workPart(theSession->Parts()->Work());& F$ O# K. R$ B6 _6 S2 X
- 2 ^" w' V% h2 S% V) L0 j
- Session::UndoMarkId markId1;. h' q7 K8 i6 \! e2 a- J. |: ?: [
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,7 x3 S% W- C; }& e3 V
- "Studio Spline Thru Points");# [9 P+ e! ]/ K+ G: |
9 L G. k9 n8 n- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
. p8 L1 s6 x$ L3 k8 ~
; w0 e9 E% \6 U! T' @2 r8 E" D* w- Features::StudioSplineBuilder *studioSplineBuilder1;
% u# l. e6 j, x9 b - studioSplineBuilder1 = workPart->Features()->9 ^: H, n; `2 @3 R8 k
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);4 }4 L1 ?1 J4 e7 ?4 j8 E
- studioSplineBuilder1->SetAssociative(true);- o7 R, K, b+ I! n2 p
- studioSplineBuilder1->: m4 F5 \, D/ a- `
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);3 ?, s3 c: d8 Y# c
- studioSplineBuilder1->7 H6 ^4 |4 R/ h1 d
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);9 f+ `. n. H3 J) g2 c
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
/ a4 K/ k- N# v- b: Q8 ] - studioSplineBuilder1->SetPeriodic(false);
8 k( o8 g' J8 x; z# D* r6 r - studioSplineBuilder1->
# D" h0 C# S! {. O9 t/ M N - SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);
1 H0 b- x4 j9 _- ~& m8 O: ^ - std::vector<double> knots1(0);
$ b! {# r8 w9 s1 x. X/ b: s$ S2 Y - studioSplineBuilder1->SetKnots(knots1);
7 @: B3 Y5 U' T- D/ ~6 P# H7 Q* L. l - std::vector<double> parameters1(0);
" P: u3 T4 o7 f: t R. I - studioSplineBuilder1->SetParameters(parameters1);
/ g% ]% U* R( Q: Z; f - Direction *nullDirection(NULL);/ D5 V7 O8 E/ C
- Scalar *nullScalar(NULL);
) F- M4 Y4 G7 X v - Offset *nullOffset(NULL);( o3 w0 |/ n9 u5 R1 {% D
) ]5 S2 e+ {9 l* M1 y0 T- std::vector<Features::GeometricConstraintData *>
% o2 |, f# b6 \7 A( |+ s$ k1 f - geometricConstraintData(thePoints.size());% ?( Z% i& S5 y) q! F8 _
- 1 f5 Y' s6 b6 R5 Q
- for (unsigned int ii = 0; ii < thePoints.size(); ii++). |, }, J% b1 Y x# Z- ^4 |* n) K4 o
- {+ \2 f) p1 ]" t
- geometricConstraintData[ii] = studioSplineBuilder1->
" _0 V( A8 `5 Q - ConstraintManager()->CreateGeometricConstraintData();
; w: @: X% W7 M( \9 K - geometricConstraintData[ii]->SetPoint(thePoints[ii]);% w! ?# g8 S7 W1 D# r8 d Y
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
9 O. R1 c0 i2 O! R - Features::GeometricConstraintData::ParameterDirectionIso);4 o" O# N7 V% ^: r: q
- geometricConstraintData[ii]->SetAutomaticConstraintType(/ n5 o! Z, v/ Y6 I9 H% s
- Features::GeometricConstraintData::AutoConstraintTypeNone);
; q7 \7 _# q6 ^4 z" F; N5 b - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
5 J* S, _* Y1 x7 H: d% n - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
) U" u9 R' K) y* p3 N' o - geometricConstraintData[ii]->SetCurvature(nullOffset);4 G* K8 v9 S& J0 D) J; R
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);; P2 t- [0 b* [- D" R" u! z0 }/ F
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);1 s7 j0 `$ {: y6 a/ S
- }
+ C4 F" e( W" b: r. \/ y - $ z) P, Y1 f8 t; I2 W5 t Z
- studioSplineBuilder1->ConstraintManager()->SetContents(5 N- L8 L P& [# N
- geometricConstraintData);
2 ~* g. f. X' Y! L0 h* V6 G
) e9 L8 R; R; i, Q3 H- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
4 |8 Y3 s3 T# w! A6 J, g4 N - Spline *theSpline = studioSplineBuilder1->Curve();' v6 t; {4 k7 G( k
. J* i1 J; Y, F' | ?6 k* j- studioSplineBuilder1->Destroy();3 N; r- t, w1 t6 R& i: ]7 l
- 7 `4 `) k$ d( q9 [' P }
- return theSpline;
+ K# ~3 ?4 M& p. Q) X - }
4 E" F! W# K6 o1 `% C - . u- t# r6 ]0 G& a* G& K7 j
- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)/ K, b' y3 Q. ~( h7 ^
- {
9 [% a. |$ R& p6 _( l c; F$ b - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
( u) j; J& k+ P/ Y, E f - if (!thePoints.size()) return;
( D( m# H, Y R- f: U* y
! ^( W" E& J2 }# f9 |: Z6 I- Spline *theSpline = createStudioSplineThruPoints(thePoints);
0 M E$ d* [* `8 {4 k3 D6 J" i+ C - 3 @1 W1 U& {* ~/ H w
- if (theSpline)$ }5 H6 V' U9 |" B3 i: J
- {
* b$ t. h" k( [ - theSpline->Highlight();
$ s$ a( v# X* z. L* E8 N3 m& c - uc1601("Studio Spline Created Thru Points", TRUE);2 f, n) d5 r( H: C8 k
- theSpline->Unhighlight();6 N% P3 r" {1 m- B2 g" o6 O
- }- g' W x* \+ b+ Z3 D
- }
8 k% x8 C [. y* r4 |$ A( p
复制代码
1 z* e# Z( J* z4 z0 {/ e# g
' r* l5 V. g; ]' {5 L. v: g# k+ L. L( U& b* d# h
|
|