|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
NX二次开发源码: 通过点创建样条曲线
7 R8 K- ?, U/ H5 [3 c- #include <uf_defs.h>
4 \3 s. o% Z T" L4 x; x2 W ? - #include <uf.h>6 C! }0 \& l: {0 I
- #include <uf_modl.h>
4 ]6 K; ^! _0 \/ l$ k2 @ - #include <uf_object_types.h>
+ g! f9 x) `9 b2 ^! F4 A' F- I - #include <uf_ui.h> v4 n1 E, p( r# S$ X1 u* l
- #include <uf_modl.h>
. p+ G* z0 d( r J& i- a7 ? - #include <NXOpen/NXException.hxx>
4 Z1 h8 v9 I" G9 |. T# G - #include <NXOpen/Session.hxx>
5 ^) g: D) _* @$ O" U" x - #include <NXOpen/Selection.hxx>( D1 H& N. m7 ?, n: D, T
- #include <NXOpen/Builder.hxx>
- n- E& \8 X4 q0 Q4 R$ s$ O - #include <NXOpen/Features_Feature.hxx>. v" V. ]9 b9 g3 p. c, ?& E2 }
- #include <NXOpen/Features_FeatureBuilder.hxx>
8 D# H# [% n# R8 G - #include <NXOpen/Features_FeatureCollection.hxx>
8 \" x# r8 l% c, M - #include <NXOpen/Features_GeometricConstraintData.hxx>/ A2 N; T; m, o
- #include <NXOpen/Features_GeometricConstraintDataManager.hxx>4 Y8 T) [2 I, A9 ~) {, m) O/ B
- #include <NXOpen/Features_StudioSplineBuilder.hxx>4 I7 t5 p$ ~: t& O8 l' d
- #include <NXOpen/Part.hxx>
9 }# J# N& |4 c+ y) Z - #include <NXOpen/ParTCollection.hxx>
, G/ _: d$ l( S3 L7 y) p( _% v8 \ - #include <NXOpen/Point.hxx>1 V' v. g- ?% w% j; u2 I1 b4 A
- #include <NXOpen/PointCollection.hxx>
$ R0 E' _: }# x8 i ^ - #include <NXOpen/NXString.hxx>5 p" p# U2 X- p7 k z3 `: x
- #include <NXOpen/UI.hxx>
* p/ T8 g- S. Q. H8 N( l4 Y1 I - #include <NXOpen/Spline.hxx>) X* C/ f0 ~7 d- j" B2 I
- #include <NXOpen/NXObjectManager.hxx>
* c$ s3 U% ]# l& ] - 2 o, }6 ^& ^ t g+ s/ m& m
- using namespace NXOpen;1 y% v' U- D$ G' w( A
- using namespace std;
g9 b) k4 U1 V' K/ x - . |- _8 D$ ^5 `" d( a j6 X
- extern "C" DllExport int ufusr_ask_unload()
+ G l D6 Y9 W9 N2 [$ ? - {
/ x1 M# b6 b& x) { - return (int)Session::LibraryUnloadOptionImmediately;- }" k2 Z% h3 D# i/ n( D# @" V
- }
( C7 X3 l" \+ p - 9 E+ P$ Y" L$ @
- static vector<Point *> selectPoints(NXString prompt)9 P- r( @: s6 \7 ?; W3 x
- {
5 k8 r0 Q( E0 }/ E8 g) C - UI *ui = UI::GetUI();
% Y! W5 o' w* a3 S2 ^ - Selection *sm = ui->SelectionManager();
+ I1 D. z- Q! p- K- G8 X6 K - std::vector<Selection::MaskTriple> mask(1);
% j w, S: x# r0 M. p6 ^' e1 E3 } - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);! }4 `, p1 `: i' c3 Y4 H- l
- std::vector<NXObject *> objects;
$ G1 l6 g& g& \' N - 7 d. q* V2 Z& _" T+ M5 t
- sm->SelectObjects("Select Points", prompt, T, `4 O4 m% z, p' J7 ]4 Y6 w
- Selection::SelectionScopeAnyInAssembly,; a% I1 I6 W- r( v+ D5 ]0 e# w
- Selection::SelectionActionClearAndEnableSpecific,
5 F9 {& E) o1 y! l - false, false, mask, objects);( D# r9 r3 I' N$ x
5 H" w& n1 T4 o! N& b9 w- vector<Point *>selPoints(objects.size());( r9 a% x2 C! t5 F9 h7 ~9 t
- for (unsigned int ii = 0; ii < objects.size(); ii++)+ L% u/ m) `9 }: V) K! q2 G
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
& K5 U. ^. u( t" [ - ; e( `- I- F; F, F; P# t
- return selPoints;; R* |1 W/ @( [+ v) q) Z
- }0 F* z. m2 o5 {$ H: C
- . D4 @ @1 { V2 s
- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)0 S/ j8 [' _2 ~# b5 N$ y/ H0 `
- {
1 F2 }4 }7 b: F3 c) u3 [2 e - Session *theSession = Session::GetSession();6 {+ I3 F- o: r4 R4 a
- Part *workPart(theSession->Parts()->Work());8 V4 q( D& s& @4 a1 A( w+ M4 J- P
- L! Y6 \5 V( o- Session::UndoMarkId markId1;
6 x% i' {+ A: o9 c8 d5 V - markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
7 E9 w- K, J7 @( x0 H% ~7 @# k - "Studio Spline Thru Points");
7 Y9 v! q. b7 t( S# \, ^ - + x" |- G/ U6 C- w$ O
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
$ Y( ]3 _4 ~4 D0 v" H4 y4 {! N - 8 w$ l/ A7 t# A& |. G: o, Y K; C
- Features::StudioSplineBuilder *studioSplineBuilder1;
2 W) I" l& ? q+ q# D+ g4 I - studioSplineBuilder1 = workPart->Features()->8 g; b: W6 z! c* P+ j2 \+ O3 I1 U1 e
- CreateStudioSplineBuilder(nullFeatures_StudioSpline);
9 U# \3 v' s9 C6 q - studioSplineBuilder1->SetAssociative(true);6 ] Z* B$ K9 p5 u
- studioSplineBuilder1->
1 h6 @5 ]% j& S - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);+ D( t: ]$ S7 D) N- p$ @
- studioSplineBuilder1->3 h% a }2 T9 O3 K
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
) n- l3 q% G c8 q$ j - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
7 c8 z$ A8 {3 m+ J% m- K- w - studioSplineBuilder1->SetPeriodic(false);
3 f* Y @4 S! E- s" n - studioSplineBuilder1->" E8 t8 T- p# o
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);4 E% P9 e/ q$ ~; _/ t2 I
- std::vector<double> knots1(0);+ X5 C; G9 [: V( s0 U
- studioSplineBuilder1->SetKnots(knots1);
: x' M9 }8 w! `; N7 N - std::vector<double> parameters1(0);
. J j. Q) i# v' ? - studioSplineBuilder1->SetParameters(parameters1);& X! I. z8 T* Q% O' M. ~5 A
- Direction *nullDirection(NULL);+ M4 |9 C, n2 H" Q7 P
- Scalar *nullScalar(NULL);6 D) M4 Y! g0 G
- Offset *nullOffset(NULL);
( J ]% Q6 _; C' ]+ t3 v: V - " z: A$ d+ a% B+ W$ h
- std::vector<Features::GeometricConstraintData *>
- C" H* Q+ n! H3 z. c: A5 M5 \% ? - geometricConstraintData(thePoints.size());5 Z. d% |8 S! ?& q# X2 z
- : } R+ N/ ]0 b: `- K
- for (unsigned int ii = 0; ii < thePoints.size(); ii++)
6 B$ S) ?' u# |4 Z - {
1 ^4 h+ |2 o+ f, b! D' H; x# @ - geometricConstraintData[ii] = studioSplineBuilder1->0 o' n X- }5 w9 l) y! y2 z. {6 T
- ConstraintManager()->CreateGeometricConstraintData();
& z: e4 U% e+ @3 [# `0 I - geometricConstraintData[ii]->SetPoint(thePoints[ii]);" N% p) Y7 V+ V! `. W
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
2 F8 \3 q4 u- X9 R: }" | T9 U - Features::GeometricConstraintData::ParameterDirectionIso);$ ]8 l! M4 c$ C+ n: V" q; L
- geometricConstraintData[ii]->SetAutomaticConstraintType(+ `! V0 o+ }' l# c: ~
- Features::GeometricConstraintData::AutoConstraintTypeNone);
" ]9 a7 J/ w' [- `! ?! S9 S1 i - geometricConstraintData[ii]->SetTangentDirection(nullDirection);, Q& E, o6 g) B+ Z$ A
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar); ?' m4 j1 V0 S* B" ?6 W
- geometricConstraintData[ii]->SetCurvature(nullOffset); s' i* c. p# [1 |& E* @5 c3 E' O
- geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);: d# P* H0 S0 f* J
- geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);- E5 t: K; b! I# ~
- }
- D" c# Y+ |# g! D - 5 e; P; s: Q1 A
- studioSplineBuilder1->ConstraintManager()->SetContents(* H" }1 G! y: A* ?
- geometricConstraintData);
/ M9 o8 Q2 U% G2 R7 P
; w7 Y3 S% d! `; \6 C7 r; `- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();& A- n+ `. {9 a
- Spline *theSpline = studioSplineBuilder1->Curve();
; C9 q5 V! @' \7 l' E2 [ - 7 A/ y. I2 R U3 F- i
- studioSplineBuilder1->Destroy();+ p" t# H, N- H3 ?- j
, y) ?$ [# S V' a- return theSpline;' A8 T- H1 \, ^/ f( h; h0 D- g
- }
' y: I6 E' K; o* G
& }) |, p! T& _( g" o* G- extern "C" DllExport void ufusr(char *param, int *retcod, int param_len)
& G) V! @5 Z- ~9 e; P - {
d6 A! n0 Y" I* e1 S, ]* x - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");
) O8 x- O! a! V) g - if (!thePoints.size()) return;
P: G' A. e2 r - : u. x5 Y+ b& @8 Y3 W
- Spline *theSpline = createStudioSplineThruPoints(thePoints);3 v% S+ m" R: Q' l9 Q. ~
& q2 [0 g4 E6 O# P& c6 n/ v7 k# j- if (theSpline)5 {- V L! O1 P; `
- {
( H ]0 o1 ^$ k/ O. L - theSpline->Highlight();; S: n* x& A, V# ~
- uc1601("Studio Spline Created Thru Points", TRUE);: j$ ~( V5 d4 v1 T* n* O
- theSpline->Unhighlight();
* N+ N2 h" X( Z, O' U - }! N. d. H. d( ^6 Y. L6 O
- }
* ~' @) x$ ^ ~0 H+ j& ^8 r1 V/ n. r
复制代码
- q; Q) o2 k1 {
2 _3 @4 E. J$ a) r2 f/ S% m7 Z k' y4 L9 @% R" d# ~+ g
|
|