|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
8 p: I! H+ u* o7 i
NX二次开发源码:通过选择点创建样条曲线5 e+ U& r9 v' k D
+ w. A h* \ b* f
- d# |4 c2 H- B$ h9 a- + [- M. q4 j6 T
- #include <uf_defs.h>/ |4 u) w0 K7 W( O1 F6 T
- #include <uf.h>. x) P, m5 G+ g, M! f
- #include <uf_modl.h>
; h, x/ I E, ~2 l. O - #include <uf_object_types.h>. t/ j# b6 z. W, w# A( h2 w9 T
- #include <uf_ui.h>! A8 r) n& O+ ^% i
- #include <uf_modl.h>9 R: H% N l8 x# v( g& a4 e
- #include <<em>NXOpen</em>/NXException.hxx>/ Z1 `" a3 A. A" q
- #include <<em>NXOpen</em>/Session.hxx>
1 W1 q6 u& _: ?1 C9 b$ e - #include <<em>NXOpen</em>/Selection.hxx>( h9 x a. @' D" V
- #include <<em>NXOpen</em>/Builder.hxx>$ {3 J8 w. f. V6 j. f
- #include <<em>NXOpen</em>/Features_Feature.hxx>
2 n; C; S. o/ ~* ]( {- V/ {7 Q - #include <<em>NXOpen</em>/Features_FeatureBuilder.hxx>8 [% J- H0 O4 h, l5 O) O* w5 t
- #include <<em>NXOpen</em>/Features_FeatureCollection.hxx>1 q [& R6 F8 w3 o; _
- #include <<em>NXOpen</em>/Features_GeometricConstraintData.hxx>, v7 _: G: f7 @3 |% G1 a* U
- #include <<em>NXOpen</em>/Features_GeometricConstraintDataManager.hxx>$ R9 j& P b8 r* M
- #include <<em>NXOpen</em>/Features_StudioSplineBuilder.hxx>. S8 v8 V, |+ g6 J
- #include <<em>NXOpen</em>/Part.hxx>& M2 A4 S/ z% n/ Y6 X' j, c
- #include <<em>NXOpen</em>/ParTCollection.hxx>
7 c# }' H* `( W" X1 }4 m; K - #include <<em>NXOpen</em>/Point.hxx>0 H' J. E6 H; L9 R- n0 T2 d
- #include <<em>NXOpen</em>/PointCollection.hxx># _$ Y+ u' {8 a N* I0 O
- #include <<em>NXOpen</em>/NXString.hxx>
' g3 E v& v5 E, C7 l% E - #include <<em>NXOpen</em>/UI.hxx>
! n; E( P* D4 o k - #include <<em>NXOpen</em>/Spline.hxx>0 G( K6 J$ G' r* e$ ~
- #include <<em>NXOpen</em>/NXObjectManager.hxx>
2 a3 h% _: e- y - 4 l: s+ t. ^$ h& a+ S; t
- using namespace <em>NXOpen</em>;
4 {% ^6 F9 M$ p* D* D4 V6 p - using namespace std;
6 F: X' X6 m( @ K( ~- {
' q; L0 D+ z1 @& [5 o1 ]" Q- extern "<em>C</em>" DllExport int ufusr_ask_unload()& M5 {3 |$ |: m0 t5 q v! P9 [5 l( s% P
- {7 i1 A! W" P/ m
- return (int)Session::LibraryUnloadOptionImmediately;, n1 N: S6 [( [9 W& G1 W ]
- }, {( Q% k( g% W2 c @6 }: _
- ! \' N( P) Z8 u) I
- static vector<Point *> selectPoints(NXString prompt)
4 R% |' [: @- D- K5 f# p8 T! u - {
5 S+ D0 h5 P [$ ]" ~4 N0 ]% a - UI *ui = UI::GetUI();
) N1 H J% f" ]% s: j) h - Selection *sm = ui->SelectionManager(); u9 K& W0 ]- U g. L2 R
- std::vector<Selection::MaskTriple> mask(1);
0 F, a- w& N9 Q! v( e - mask[0] = Selection::MaskTriple(UF_point_type, 0, 0);; C, I: k# R: \4 n" T) y3 Z$ i+ r
- std::vector<NXObject *> objects;) ~$ N* O. @! T# _
9 c$ g- e0 W* G- sm->SelectObjects("Select Points", prompt,1 Z4 k# N$ g* U: F a
- Selection::SelectionScopeAnyInAssembly,
7 m; t" A# K- Y% N - Selection::SelectionActionClearAndEnableSpecific,
( `2 U4 s. o. r% m" q - false, false, mask, objects);( ~) b' W6 O) h# u. j
- * k$ T T6 E/ K6 d+ f$ q
- vector<Point *>selPoints(objects.size());; o/ ]3 f+ c2 O: q T6 \
- for (unsigned int ii = 0; ii < objects.size(); ii++); z3 E: i# `( ~" J( d, H
- selPoints[ii] = dynamic_cast<Point *>(objects[ii]);
0 A+ Q& [8 T. w; U$ ~+ N1 L/ Y
4 t" ~9 x6 v$ C2 O& G7 a- return selPoints;
1 V# m" S& g! @9 h2 j - }; X$ h, q, @) V1 d* s
" p# g! Q% x% m I, v& z' `- static Spline *createStudioSplineThruPoints(vector<Point *> thePoints)
! U" J2 V: A0 j. _8 ?. q3 S4 H% ~ - {
+ V9 z, [! `7 r - Session *theSession = Session::GetSession();
0 H7 S* l8 B- n# G$ e" j - Part *workPart(theSession->Parts()->Work());
g6 v, d" o; p$ `
- B. Q1 n, E, c5 e- Session::UndoMarkId markId1; ~1 [: r6 ^. u6 F: Z
- markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,
; f+ v* K8 d# ]: x' A/ [! T9 z9 ] - "Studio Spline Thru Points");
/ c. r, q' w# @6 { - 4 L4 K! g3 F$ f/ H' I
- Features::StudioSpline *nullFeatures_StudioSpline(NULL);
; U" `$ d3 t3 B: b4 t
4 ^0 g6 z, v# s6 q8 s5 S7 O5 T- Features::StudioSplineBuilder *studioSplineBuilder1;
# j/ s6 a: t7 h& e2 d/ y: ~ - studioSplineBuilder1 = workPart->Features()->
9 ^( p, g) e! c" Q4 A2 a3 S - CreateStudioSplineBuilder(nullFeatures_StudioSpline);
0 P' a8 f. l( c3 l. M% D - studioSplineBuilder1->SetAssociative(true); A8 V/ _" J8 ?
- studioSplineBuilder1->
) @5 `6 Y G e2 t' {1 T: P - SetInputCurveOption(Features::StudioSplineBuilder::CurveOptionRetain);
" J: b, M5 g% |* L0 e) {% f$ Q @! [$ i - studioSplineBuilder1->& ^( D: Q: @ ~# L$ I" N: F. b
- SetSplineMethod(Features::StudioSplineBuilder::MethodThroUGhPoints);
% t9 ?& j' I+ y' ~8 v - studioSplineBuilder1->SetDegree((int)thePoints.size() - 1);
# I: t* m' f2 p; n3 K0 C+ f3 x - studioSplineBuilder1->SetPeriodic(false);: @ ]+ A' I1 K3 [3 e. R5 |; Z
- studioSplineBuilder1->( ?3 m' j& [3 H( f; E' R2 E
- SetMatchKnots(Features::StudioSplineBuilder::MatchKnotsTypeNone);: A( s X/ N6 r. ^ L' S" |9 R" r
- std::vector<double> knots1(0);
R0 n% [; e. G1 @. m% v( f0 [ - studioSplineBuilder1->SetKnots(knots1);
+ V7 x2 \1 p' ]4 R9 c8 _ - std::vector<double> parameters1(0);/ j7 ~2 z, O2 I$ u
- studioSplineBuilder1->SetParameters(parameters1);
$ D# Y( J( b7 y. L% L& F - Direction *nullDirection(NULL);
+ _3 ^3 h5 f L' Q$ k - Scalar *nullScalar(NULL); e2 L8 R5 k7 t4 F! d# V$ `1 N
- Offset *nullOffset(NULL);1 L1 `' L, y7 J: [5 ^! Z9 F5 q: ]
[& J" B) {1 a/ S6 g- v- std::vector<Features::GeometricConstraintData *>
; m" l4 y! p( C/ h9 t/ b5 ?. ^4 ^ - geometricConstraintData(thePoints.size());9 {: Z+ x7 Q2 h; n8 @$ A! |
8 z+ h" D, B/ G( F, K! X- for (unsigned int ii = 0; ii < thePoints.size(); ii++)) @6 e- p: `, ?
- {
* @# p2 e5 K" U% w/ Q - geometricConstraintData[ii] = studioSplineBuilder1->
6 o* K, @* d. a5 S P - ConstraintManager()->CreateGeometricConstraintData();
7 E! X5 h% O% v5 k - geometricConstraintData[ii]->SetPoint(thePoints[ii]);* z* E5 t& e3 p; S% y# K; |
- geometricConstraintData[ii]->SetAutomaticConstraintDirection(
1 K; p. ~# ^8 f# B0 e8 ] - Features::GeometricConstraintData::ParameterDirectionIso);
4 B. C+ B% D' k' c( R, n - geometricConstraintData[ii]->SetAutomaticConstraintType(
: H4 Y( {8 z" |9 Q( n" i - Features::GeometricConstraintData::AutoConstraintTypeNone);
9 P5 x) A9 C5 S1 ~2 w$ g - geometricConstraintData[ii]->SetTangentDirection(nullDirection);- B3 b' T; a* P6 C6 f P1 e
- geometricConstraintData[ii]->SetTangentMagnitude(nullScalar);
. @" z0 g( A$ L u6 X - geometricConstraintData[ii]->SetCurvature(nullOffset);
- s1 l& R+ a) z! z* x+ S - geometricConstraintData[ii]->SetCurvatureDerivative(nullOffset);
7 E2 O1 e5 k) W9 w* Y! V - geometricConstraintData[ii]->SetHasSymmetricModelingConstraint(false);
, x& _$ M- j- C6 r7 k9 I - }: R4 ] n5 y3 _# Q( X7 ?
2 L( X- |% P+ s' f3 L- studioSplineBuilder1->ConstraintManager()->SetContents(
+ h0 x, O# B0 x - geometricConstraintData);
; _7 }0 n, L3 N. L3 N* c7 }
$ C( B) l* I" h1 G, v1 O. p- Features::Feature *feature1 = studioSplineBuilder1->CommitFeature();" k# H2 o* D9 L' q! q, o
- Spline *theSpline = studioSplineBuilder1-><em>Curve</em>();9 |2 X+ [; y+ F
- ! l2 W8 d! J' {& {7 p
- studioSplineBuilder1->Destroy();9 f/ b0 X" X5 h W8 U# j u, y+ n
" h# X1 m& j1 B# Z- ~- return theSpline;6 D, R( k' Q9 O: t0 |9 q3 A
- }( d8 [! R* S2 C( v* P& M" Y
- ! \7 a$ W1 R/ v3 P- \
- extern "<em>C</em>" DllExport void ufusr(char *param, int *retcod, int param_len)+ Y6 `) _' [' I/ C
- {
2 u& {/ [! c$ F, \& @) E2 e - std::vector<Point *>thePoints = selectPoints("Studio Spline Thru Points");/ k8 M, H# k! h
- if (!thePoints.size()) return;
; F' e8 R9 V, B
- |( q8 K4 ]3 v9 u# ?- Spline *theSpline = createStudioSplineThruPoints(thePoints);* |, ]' ]5 Q1 ?+ g a# _
- * A8 p/ e" c( y7 `* C9 |2 t* M
- if (theSpline)
- E" I* @$ n2 q/ W - {$ a4 p5 C3 ~# u9 e
- theSpline->Highlight();
/ w! F% v- ^$ o - uc1601("Studio Spline Created Thru Points", TRUE);
' J2 C) @# o5 @5 v# E - theSpline->Unhighlight();- T( s' \6 v s4 g. N
- }! g R4 g- Z, w
- }( n0 r, Q, I% P
- <p> </p>
复制代码
8 L$ C" d1 G2 y) H5 _9 X/ [ |
|