|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线! c: w( V# E8 P2 ^
- #include <uf_defs.h>+ V7 @; ]9 ^4 ~
- #include <uf.h>' }% s/ H4 t; S! P3 i
- #include <uf_modl.h>
& B* b/ \# ~6 _' H5 ] - #include <uf_object_types.h>
1 o- x4 L9 P p Y: z. A - #include <uf_ui.h>+ z9 @" w7 l4 q; B7 c0 d
- #include <uf_modl.h>2 d* h5 V. Z; U# [
- #include <NXOpen/NXException.hxx>! s1 H, m# q/ l* O A; ]8 Q
- #include <NXOpen/Session.hxx>
' l& J, d+ q' P/ F1 K& t$ ?) L7 T$ N6 l - #include <NXOpen/Selection.hxx>3 O$ m: I* S2 F2 A' I
- #include <NXOpen/Builder.hxx>
5 V7 N3 e( T9 r' D' @ - #include <NXOpen/Features_Feature.hxx> Z( Q) s9 z4 ^' |
- #include <NXOpen/Features_FeatureBuilder.hxx>
/ i0 T1 }1 C0 o - #include <NXOpen/Features_FeatureCollection.hxx>4 E* v+ z8 ` C& M
- #include <NXOpen/Features_GeometricConstraintData.hxx>0 W, o; u% a3 M. x$ m
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>2 o; B( c5 |4 z- j# y8 ~1 K; B
- #include <NXOpen/Features_StudioSplineBuilder.hxx>/ U) |5 q1 R2 H' I5 P3 Z* i% t b6 u
- #include <NXOpen/Part.hxx>5 k" }6 C q$ V, ^% z- e+ S
- #include <NXOpen/ParTCollection.hxx>( ^5 J8 ^1 P: |: \
- #include <NXOpen/Point.hxx>
5 W+ O( i. q7 ~0 {/ r' }6 Z - #include <NXOpen/PointCollection.hxx>
. y% J/ O5 J3 `# P% l5 M - #include <NXOpen/NXString.hxx>2 t$ Q9 `: d j; u. y0 V e
- #include <NXOpen/UI.hxx>, ^ U8 p' o+ L0 _& Q% V) j: x
- #include <NXOpen/Spline.hxx>3 W$ o1 Y! [# _& ~+ J1 j! u
- #include <NXOpen/NXObjectManager.hxx>
3 v/ N# d$ Y9 e: ^ - 1 @6 ?) U6 n7 v6 {8 [
- using namespace NXOpen;
; ~% X0 \+ {8 _6 e3 n$ k - using namespace std;( v! W4 x( g- h
- - p7 m5 ?5 N1 V4 R9 \6 t
- extern "C" DllExport int ufusr_ask_unload()' ~9 X# y9 M+ O
- {: E* l# l X+ N* g
- return (int)Session::LibraryUnloadOptionImmediately;0 Y3 [9 {" }# [. z
- }( S. G5 O- d3 P. Y
- / Q6 i: j% @" n$ y% {
- static vector<Point *> selectPoints(NXString prompt)5 i: r/ @$ u/ b0 _" l- I( g9 m" Y
- {$ V% G3 n3 w* j( T, Y$ L
- UI *ui = UI::GetUI();
0 Y9 B7 d5 N1 n- U/ N0 u6 T - Selection *sm = ui->SelectionManager();! y l+ e4 ]6 N" F A M8 L( ?
- std::vector<Selection::MaskTriple> mask(1);- m) `. B1 ^4 e; a) c
- mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);' Z0 O7 v. n' } _& p7 [# N
- std::vector<NXObject *> objects;
$ z) T+ g& T C, b: b - 3 i) k+ h( B8 t0 Y' J' y2 K
- sm->SelectObjects("Select Points", prompt,
4 s- a; n( i' c* l2 p( O" O- g0 b3 Y - Selection::SelectionScopeAnyInAssembly,
6 @: M$ H' w& X1 l - Selection::SelectionActionClearAndEnableSpecific,; L3 T( A1 ]. H- ]# b6 [
- false, false, mask, objects);
0 `' ]5 o# N3 K9 M- V' [( K
9 C# W) |8 \* G4 D1 D4 ]- vector<Point *>selPoints(objects.size());, H& o/ {% K2 t/ |
- for (unsigned int ii = 0; ii < objects.size(); ii++)
/ ^# F' Y7 E& Z% E# [; X - selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
) R" C4 c+ l( S& `
0 X6 d7 x/ s9 \- return selPoints; ~: V' \( [. o3 W1 l* D
- }
0 o, w: Y7 E+ _. C- W3 M# G
+ W' A4 K2 O* _2 k' _: m: G- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)) } y! g3 m% u$ O. [
- {; v6 U6 C: E: p4 w% X
- Session *theSession = Session::GetSession();
2 Y" _ d, w2 j7 h. l; q6 r - Part *workPart(theSession->Parts()->Work());
; s9 C- A' ^+ L- _/ ^9 ^1 r
' t* B" F' s: c: {9 k- Session::UndoMarkId markId1;. {5 ?3 D$ w+ g- a, A
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,& x0 c) T& o4 O9 `
- "Studio Spline Thru Points");4 o. I5 ^/ p* Q$ K2 X2 a
- # U1 [1 ]( J" {0 u& I
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);& w3 j$ D8 w" Y) ^
) ^" z, R& r$ a. y$ p- Features::StudioSplineBuilder *studioSplineBuilder1;
/ `# G6 Q( v) v% y, P9 \2 p - studioSplineBuilder1 = workPart->Features()->' B' N4 {7 E2 T3 u( q
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);$ [. @& A) _7 ?2 z+ [
- studioSplineBuilder1->SetAssociative(true);
$ H1 ]: W/ x6 p+ L4 g# A$ Z: _ - studioSplineBuilder1->( B+ T1 L5 t. x2 b+ N% l
- SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);/ y, D5 l1 s/ s, R; z2 D
- studioSplineBuilder1->9 l2 N7 |' Z- ~! ?# |; d4 z
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);8 B' b7 r# O/ w- W q
- studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);( v! T# r) B% Z# `8 V- {
- studioSplineBuilder1->SetPeriodic(false);
) I( F% n) P# B2 X, D; w- U- w0 J - studioSplineBuilder1->8 m5 v3 w% S o% {( q0 M8 ?# ^
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);6 Y- @6 o) o$ o, K* v
- std::vector<double> knots1(0);
8 E' q5 I/ i- v8 C# R - studioSplineBuilder1->SetKnots(knots1);0 W+ z( i$ ~% i7 d$ L' t4 o
- std::vector<double> parameters1(0);0 l: ]/ v% R1 I) q% \
- studioSplineBuilder1->SetParameters(parameters1);
" g% B5 W0 g2 P$ u - Direction *nullDirection(NULL);
+ n0 H+ n D1 L3 b8 D8 B, m - Scalar *nullScalar(NULL);
" v- f2 Q {6 R$ e& H3 {2 U( j& ` - Offset *nullOffset(NULL);
2 @3 n U- [1 Q' ` - ( k/ J+ P5 a$ g S
- std::vector<Features::GeometricConstraintData *>
1 @4 w/ L% i4 w/ D9 x/ c - geometricConstraintData(thePoints.size()); k) Z( S6 K3 P5 B! S) r5 `
- 6 T3 _ N, z6 p( ~( F1 K& c0 ?. R
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
$ [/ T, Z* t; }) R - {
7 N+ y; H M* _- ` - geometricConstraintData[ii] = studioSplineBuilder1->: B% \8 N9 c7 Q$ H3 G
- ConstraintManager()->CreateGeometricConstraintData();/ U. z0 v- ^- W/ T. Y
- geometricConstraintData[ii]->SetPoint(thePoints[ii]);
* C( K- y# t3 M7 @% ^ - geometricConstraintData[ii]->SetAutomaticConstraintDirection(
2 M1 O7 O+ J3 m4 P - Features::GeometricConstraintData::ParameterDirectionIso);& g5 ^1 }" Q; |. x& W
- geometricConstraintData[ii]->SetAutomaticConstraintType(* B; H" Q$ R0 q2 P$ _
- Features::GeometricConstraintData::AutoConstraintTypeNone);
/ V+ S2 B' e4 W5 d6 R; ~; y7 x - geometricConstraintData[ii]->SetTangentDirection(nullDirection);
" F( U2 [' S9 F) a% q - geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);% Z$ n% ~6 W1 \
- geometricConstraintData[ii]->SetCurvature(nullOffset);# q, @$ h: c, q& M( Q
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);! K1 n! i5 i& @8 V8 ?: R( q, w! U
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
+ s* a! g! q ~, j# q - }
( p5 W/ }2 K- e& r/ l6 k/ D' l$ k - 6 y+ x/ a Z2 H4 b
- studioSplineBuilder1->ConstraintManager()->SetContents() u( X4 g9 M1 Q# T
- geometricConstraintData);
; W! k1 Z' ], z
0 R# x. F Z) D) Q7 D- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();
$ i! j/ H! d, f3 O - Spline *theSpline = studioSplineBuilder1->Curve();
. }" [ U: {6 \
- ~$ I4 k% \' e- studioSplineBuilder1->Destroy();
- }6 {+ d% S, P/ n - " e: j7 } K. z# s1 P: T
- return theSpline;
7 e6 p/ d6 r# w - }
; j v# I l) z
5 o7 v I0 u! Y& L6 u- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)- [" O: K$ R1 D; v& X; v& B
- {& R) | `" _7 u& V1 W
- std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");, A) [2 O7 a! c. E: D
- if (!thePoints.size()) return;
5 l8 d x( ^! [ - 1 c+ ~% C/ w& A, }( W
- Spline *theSpline = createStudioSplineThruPoints(thePoints);
! W& B( g$ F7 A4 }4 f$ a - & r) }- @& W* M* F& M* ~/ O
- if (theSpline)# C& G' C& Z2 c. _9 ?# G n
- {
, W9 {# @& @% {5 M - theSpline->Highlight();
% Y- g3 Z; Q8 `4 ?# g - uc1601("Studio Spline Created Thru Points", TRUE);
1 ]8 g' y9 f- ^- W l% J% A - theSpline->Unhighlight();: ~+ ~7 [# Q: Z# v! b Q
- }
1 U K- j5 C! D% @/ E - }
' q3 |/ V3 }3 S) s4 L
复制代码 1 @! @4 _/ R' K
' G1 [' v2 ?& e \5 s
2 m; _: t$ q5 S3 e
|
|