|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了! ^$ m, o% `/ J9 W9 Y9 ~
% Y$ [0 M' k# }4 L, M std::vector<NXObject *> objects1;
+ {/ `) I% p) U0 h objects1 = divideCurveBuilder1->GeTCommittedObjects();
( {$ h# c- t; k* t8 |1 l; M- u3 e! \$ y+ w3 L# {3 B
9 v* X, J, m; F( v) }8 Y/ S9 f
' Z. n' `! i0 `% l; y
完整代码如下:. |3 s, O0 ?0 a9 K& l
2 R: I; D9 V$ Y' S
// NX 7.5.0.324 w6 Z. I& f5 Z! d
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
6 Z1 I. I( ?+ C% L0 V0 B$ A0 h//& n' l/ C# S& ? }
#include <uf_defs.h> r& V; S% J3 f. @9 D. T. Q, |
#include <NXOpen/NXException.hxx>* G4 v3 C- b" q `; H3 s
#include <NXOpen/Session.hxx>
/ _. }+ ~% e3 E4 p1 w) Q* b#include <NXOpen/Builder.hxx>7 [0 u2 \: o# k& H
#include <NXOpen/Direction.hxx>
& C( T/ e; {" [2 D) m7 U#include <NXOpen/Expression.hxx>' P) `4 z) T" F% Y4 z
#include <NXOpen/ExpressionCollection.hxx>
7 _, j w Q/ q/ }; g" d, l, }, {#include <NXOpen/Features_BaseFeatureCollection.hxx>3 x- e7 N4 d1 E2 x2 k
#include <NXOpen/Features_DivideCurveBuilder.hxx>
) k) b. k% m; `6 e1 `* M# n#include <NXOpen/Features_FeatureCollection.hxx>. { u1 i" i5 Z; V) g/ b% C7 P
#include <NXOpen/Features_PointFeature.hxx>
; g) _" h* J& e7 {: F5 o, F! s9 s#include <NXOpen/ModelingView.hxx>
1 N, W! ^, F# Q. S2 @5 @9 M) U#include <NXOpen/ModelingViewCollection.hxx> y0 y8 _" L: u! I3 @' i
#include <NXOpen/NXObject.hxx>/ l# p4 J" p% p5 Z( N1 J
#include <NXOpen/Part.hxx>
& R$ c, t: E* ~0 {#include <NXOpen/PartCollection.hxx>& k! j7 g! X2 p$ @* I
#include <NXOpen/Plane.hxx>6 ]* g7 E' j, |$ N+ Z
#include <NXOpen/PlaneCollection.hxx>6 G, B2 c5 C5 m
#include <NXOpen/Point.hxx>
% S5 d2 R; a1 q5 s `+ U#include <NXOpen/PointCollection.hxx>
/ b3 }0 [9 D1 v5 p* C#include <NXOpen/Preferences_PartModeling.hxx>$ c( A; J) s) e F6 ?7 I9 L
#include <NXOpen/Preferences_PartPreferences.hxx>. ?# y7 v' H5 l1 k; y1 y) }
#include <NXOpen/Section.hxx>9 a9 P/ N! w7 v
#include <NXOpen/SectionCollection.hxx>; N( b- z7 G: f8 T2 g6 z( O
#include <NXOpen/SelectCurve.hxx>
) i' g" m& z" F5 N5 B#include <NXOpen/SelectObject.hxx>- O( s! A! M$ [* Q; H! O) q
#include <NXOpen/SelectPointList.hxx>8 w. i; ^9 G! x3 Z& W2 U
#include <NXOpen/Session.hxx>& c4 O2 L, ]' { n: S
#include <NXOpen/Spline.hxx>
+ X, t+ `, L# K9 U#include <NXOpen/SplineCollection.hxx>- {2 C X- e% V: b7 W9 }
#include <NXOpen/TaggedObject.hxx>9 q# H# B1 U D3 U9 f. m: N
#include <NXOpen/Unit.hxx>8 M9 O+ S; T1 Q0 b8 l" `8 ~
#include <NXOpen/UnitCollection.hxx>
& R& D. F+ q. k c% B1 t#include <NXOpen/Update.hxx>
# V5 D8 M& `; P0 e6 m1 s1 G2 Gusing namespace NXOpen;
7 H- }1 n+ o } ^% {
0 o6 G, }4 {& ?9 I% Q4 Rextern "C" DllExport int ufusr_ask_unload()
7 n/ f1 u: a% h0 z0 n5 t9 w{
& _8 s2 _4 D5 [8 E* F) w* E return (int)Session::LibraryUnloadOptionImmediately;
) }8 l0 ` a+ A+ Y4 Q3 i}; P4 o0 b% J L
7 H5 s; W) ]$ u9 W \5 o d
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)4 N/ i3 C: v$ x7 U- ~( D
{! R: n7 L; p( d4 M0 s
Session *theSession = Session::GetSession();, \& V K& \+ T+ s& P
Part *workPart(theSession->Parts()->Work());
3 R! I& n" J+ ?4 o+ G Part *displayPart(theSession->Parts()->Display());7 O: y% H, {4 D# m; {
// ----------------------------------------------+ |' V7 O: V0 R( ]: h3 ]9 r
// Menu: Edit->Curve->Divide...2 O( E, V: e! N9 \6 U! P# _
// ----------------------------------------------: d$ {. `4 [' X
Session::UndoMarkId markId1;* w; g& q" M& Z0 N4 @* {
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
" K H6 E% Z2 \# h! }" h, ~. p( i) t$ P' H$ A. v% R( L
Features::Feature *nullFeatures_Feature(NULL);) S2 e5 S# K4 J- n: l
& t7 x- c, i7 y0 s2 x# L: ^7 U if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )% w; c# P( k2 u1 ?
{4 H6 q. l6 j/ v( ]& p' I e
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
{: E6 a9 ]5 u3 F- Y) N3 } }' R6 |( @5 |. v5 ^- E
" u$ O' q& u9 q, s+ W4 M# V& [: k
Features::DivideCurveBuilder *divideCurveBuilder1;
* L% s' Y9 I' }* e( M9 ?& B divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);* _- \( K2 v2 E* E
1 t4 N3 X3 k8 X- B5 t Point3d origin1(0.0, 0.0, 0.0);
% R, X1 ?* M% d: M Vector3d normal1(0.0, 0.0, 1.0);4 C' T; `% }( q3 P2 \
Plane *plane1;7 U- |7 r0 a+ }8 u4 {
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
- U6 T( |. ~ H8 Z. Y4 `+ A1 q- z" X: N9 u5 q/ {/ u
divideCurveBuilder1->SetBoundingPlane(plane1);0 y% F# R8 E. I7 d1 v
, |( N" u i: G8 X; H3 n" S Section *section1;
: h) j7 I5 ]6 j) H3 x% Z section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);; `( s, r1 n5 Y
9 [; G" @: L$ o- u3 z4 G" M
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));, k& n9 y) a$ X1 s$ O
Expression *expression1;; r2 Y) s8 A) o3 D6 n
expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
* p, P1 a$ | V) X8 W( C& }
6 P+ M" J" n) N% i3 v7 D: N% |' l" c Section *section2;
/ O1 \ |. v& t4 B0 z# [ section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
4 C/ i7 D+ {9 y1 q. f" c. |! Q6 e9 l* Q
Expression *expression2;
5 g: b. K# U* h! M, ~/ g expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
l- [$ ~$ U# ]( \; }; c) p0 D2 q/ y; Y1 p# p
divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);8 s- p0 K3 k& c) j% O4 a ]
% q6 @' ^" k2 h! R5 k# | divideCurveBuilder1->SetEqualParameterSegments(5);
* s+ u5 W( S5 w. @0 j' K) y H4 t! `0 {4 }1 T: ^
divideCurveBuilder1->SetEqualArcLengthSegments(5);
. p, V3 L5 d3 k! H n- j+ B$ @. C# K o: P/ s+ c1 W' Q: w
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
, Y) W8 R, h, r, C! e, N) y1 a2 U) G( |+ z+ n( X; x1 V
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
' @ M) }$ `5 n: _1 ^" h; W
, _$ A7 w) l+ J* R% j0 ?7 c _ Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));6 ?( ^9 V* ~) t8 c7 A$ Z
Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);1 B$ G& U: Y* B
divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);1 F/ P3 k3 D! f7 T8 ~
. ?; @& y0 q9 q0 j divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);- Y3 P o# T( F
, D+ c- Y. T+ g- _7 J, V2 P7 S2 F2 _, X
Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
: A" L( ~4 v' z- t$ r Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));: V t" f. H+ |4 Z1 M
Xform *nullXform(NULL);6 ^, B7 ^& w B2 L) }0 t
Point *point3;' b8 y. D! t9 u# _! s4 H
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
1 L8 J( Y( E" G& f* e) g
" I2 w+ L- \( j/ Q2 m! T divideCurveBuilder1->SetBoundingProjectPoint(point3);
# U( b# P' W6 T# @. O5 h1 w$ ?0 @/ l3 V' t; s
Session::UndoMarkId markId2;
6 Z, V4 Y( ^( r/ ? markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");2 N; l0 H0 c5 r# _, W c5 F4 W
* L, c. k K' M8 w- x) h
NXObject *nXObject1;
. g1 ^+ i7 r/ e5 t6 S. r nXObject1 = divideCurveBuilder1->Commit();' n6 [+ I Q% c( G
9 b q' T4 ~! f, P. z) z R1 n& w
std::vector<NXObject *> objects1;
" p# P5 B, w2 t" `9 r* m J objects1 = divideCurveBuilder1->GetCommittedObjects();9 M- U* P" G5 Z# p+ }2 Y2 A a
" j, T4 ?3 |6 Q V# H: J( n
theSession->DeleteUndoMark(markId2, NULL);: G/ k/ ?5 v `" q: U
" j6 _, L; ~* U9 U- z# G
theSession->SetUndoMarkName(markId1, "Divide Curve");
8 V; o! N! n ]8 ^ ?
+ T0 U; R( z* e+ j divideCurveBuilder1->Destroy();
% J6 K. G& p6 ~' }/ b7 T
+ S8 F- a( A( e8 G) C% B# @0 t5 N try, M9 L2 i4 b: d! K
{
4 }1 `$ @9 Y, Z // 表达式仍然在使用中。
3 c$ S) i( ]/ t3 Q- f1 c9 ? workPart->Expressions()->Delete(expression2);
5 F9 U8 c9 h% P9 D) { }
' B* a2 P; M" l% |, D3 r9 x catch (const NXException &ex): G$ m$ p6 |2 F* A4 P# t
{' ^; D, Q8 K/ x, @4 M) n3 x6 j
ex.AssertErrorCode(1050029);
& i4 D% X# C" _2 s+ }7 l$ [7 Y }
7 b- w7 N2 w, p5 M$ ]0 u% H7 G: A& f; |" J- L3 Q7 T& U
section2->Destroy();; \+ i: X+ k; [
) d0 t" u9 |8 `* a# y( b
try
+ A9 m3 M% s+ G5 D {
0 R2 h5 e2 h& D1 G" R) G // 表达式仍然在使用中。* ~$ q9 b- ?' M0 W' S
workPart->Expressions()->Delete(expression1);! `: {& P# \( q. w. n
}& i/ J1 I. b4 u# I8 Q3 ^. ^( `
catch (const NXException &ex)
+ Z" j6 k3 T9 p {* n$ }" X! T0 ~) U
ex.AssertErrorCode(1050029);: D# Y" u9 Y; `4 R# [
}
, T& M8 q4 Q/ ?8 T7 f& h" @
, b- b3 t4 T) `2 `5 ?- }8 f section1->Destroy();
+ X1 P- R) o8 d+ Q1 i9 q+ k& U' L( h% \
plane1->DestroyPlane();
& E2 A& W; q" I0 P
! c; W3 _% n3 g* A int nErrs1;" O, \$ g- H2 S; s3 C6 L0 M
nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);! q2 L- i4 [1 g$ t
6 z9 c8 X3 B4 G! Z // ----------------------------------------------3 z& u' u& R( J% Q i; E! t, V
// Menu: Tools->Journal->Stop Recording
3 h" R9 z2 o) K" W; }0 h // ----------------------------------------------
: n% q3 d" b. U4 O: {}
, I+ n) G) j3 J9 I2 Z; c, v% A
0 R2 |) ^& t6 p4 J1 f/ A/ v7 w* e' k) S
: o" p, [3 V0 e2 S$ ^希望大神指点6 r1 ~% b7 ~- v0 k/ h
|
|