|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了7 W j, m/ A( v" }/ q/ s# a
" f# V( n0 j6 m std::vector<NXObject *> objects1;
2 c+ R) q$ f. L7 U/ Z objects1 = divideCurveBuilder1->GeTCommittedObjects();
) i$ O# a$ F; E* L" A" _* f; N0 d; X! @+ T
6 C' P. O: S, P8 Q+ I+ ~5 E$ d
完整代码如下:
$ \3 u3 ^2 w: p" s8 Q
% |8 y/ @4 H" t. Y// NX 7.5.0.32 {) s0 w) n& ^
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间. c0 R. E; x# ?& m" I) P
//
% @9 f- m& M2 ]: F4 P0 L#include <uf_defs.h>
2 D4 j) q6 j$ y Z2 J3 ~- m$ b#include <NXOpen/NXException.hxx>) V! f9 D! K4 Z: G$ K
#include <NXOpen/Session.hxx>
" n7 B% t1 f9 M, \# j5 T- x$ l) D#include <NXOpen/Builder.hxx>) t/ N# t* J% ^' `( ?
#include <NXOpen/Direction.hxx>' o; O; w5 v$ y9 m
#include <NXOpen/Expression.hxx>
0 h: @2 }* n2 u% y#include <NXOpen/ExpressionCollection.hxx>
% x: S& N4 w' g( O7 n+ p' D#include <NXOpen/Features_BaseFeatureCollection.hxx>! w! P; u J2 x1 o8 e* @" X" Y
#include <NXOpen/Features_DivideCurveBuilder.hxx>
7 d9 o3 B4 ~8 p8 }7 k) S1 [% }, s#include <NXOpen/Features_FeatureCollection.hxx>
" i/ f5 w2 U2 n5 f. G7 C- L/ w1 Y#include <NXOpen/Features_PointFeature.hxx>! U( c& R# E; O- ]% _
#include <NXOpen/ModelingView.hxx>; G" A# O* k9 W3 j
#include <NXOpen/ModelingViewCollection.hxx>% r, ^$ s3 {5 u: @4 A6 X
#include <NXOpen/NXObject.hxx>4 p l# [7 X* A) X" \/ F
#include <NXOpen/Part.hxx>6 G: s; M3 G: T" |4 P
#include <NXOpen/PartCollection.hxx>
4 t' {* G/ i( {$ O$ `$ N' ^! r9 Y- \#include <NXOpen/Plane.hxx>3 a! ?- {7 v9 ?! Q$ ~4 \! s8 C
#include <NXOpen/PlaneCollection.hxx>( }) o0 D" H0 h' Y
#include <NXOpen/Point.hxx>+ K7 u3 s. C& Z
#include <NXOpen/PointCollection.hxx>0 T) ], \! }9 |% X
#include <NXOpen/Preferences_PartModeling.hxx>$ q0 W F. t2 ?" t
#include <NXOpen/Preferences_PartPreferences.hxx>
3 ]! ^) z4 V, w5 S* E#include <NXOpen/Section.hxx>
% _3 C7 E' A3 J" }#include <NXOpen/SectionCollection.hxx>
1 O" P9 D# }& u& d#include <NXOpen/SelectCurve.hxx>% e' b" h& v+ O b$ z @; w
#include <NXOpen/SelectObject.hxx>! G. ^. `# m" l/ t7 F
#include <NXOpen/SelectPointList.hxx>
; L7 b7 @. c+ b" s#include <NXOpen/Session.hxx>
& }! ?/ F1 W' W/ D3 `5 M* p; J( `#include <NXOpen/Spline.hxx>
3 t0 |( h3 n2 t& E6 L#include <NXOpen/SplineCollection.hxx>! f" q0 [% C9 X g* {4 K, E/ V
#include <NXOpen/TaggedObject.hxx>
; |; n2 D4 R' z* p) @#include <NXOpen/Unit.hxx>% \" z I% y0 F4 J9 l/ J! V4 N8 T; h
#include <NXOpen/UnitCollection.hxx>
% e" ] i) u, M) i3 L#include <NXOpen/Update.hxx>
; p/ B: `6 \2 m6 O. D9 _' |/ Qusing namespace NXOpen;
2 }/ [! I* l4 f- e1 b1 V2 Y2 G
' M6 i9 z7 x8 p0 r9 H& [0 Bextern "C" DllExport int ufusr_ask_unload()0 c. a% d/ z) F
{; s8 ]% |+ n( i* f
return (int)Session::LibraryUnloadOptionImmediately;5 q% l2 f1 w1 z. D$ `/ s) H- w
}
% m3 f/ u; `+ z. E
+ o* G& S( f3 yextern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
4 F% b7 d2 Y2 F) H{' @! @1 h' X+ q# W) I9 L
Session *theSession = Session::GetSession();
) k$ H. r3 p5 a2 S# l2 n Part *workPart(theSession->Parts()->Work());; c+ y' H9 i) t) Z; D
Part *displayPart(theSession->Parts()->Display());* Q% ^ D+ |5 x+ Q C/ @
// ----------------------------------------------
+ t, I' P4 \+ W$ {7 Y! c1 ] // Menu: Edit->Curve->Divide...
9 p" C4 ^2 v8 H2 w // ----------------------------------------------
L5 s$ r$ n& V" J" L4 [ Session::UndoMarkId markId1;; P8 O$ A, y( i8 K% i. X: H8 E
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
. b" ?0 `* P( d, ^8 p1 f$ M2 J2 F7 n N) b6 O5 \
Features::Feature *nullFeatures_Feature(NULL);# O4 i) o1 \& D5 Q3 B; S
, p7 H% o! Q9 x- c& h# M) B6 b
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() ): G' e3 v% V* s1 D( }& n
{2 W! D* G" B) o: ]$ a! n7 f6 \2 C
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
( f( H0 i* r5 `; u A: h }
! Z( y; s: j: l
" l% t; S9 z Y7 u ]6 O Features::DivideCurveBuilder *divideCurveBuilder1;
/ C _3 Z9 V k! Z* |( _2 g divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
) q- H& A7 l" \" s+ l5 u
+ {# h8 e) J `; L) w0 D5 W/ c. ] Point3d origin1(0.0, 0.0, 0.0);
1 w4 _: U# M1 F% Y! Q Vector3d normal1(0.0, 0.0, 1.0);- h2 a7 G4 ~/ ^( T
Plane *plane1;
/ U# Z3 R" C5 X" w plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
5 A9 Q0 b L9 H1 Q+ r* l4 X i$ y$ F! T. n4 |/ Z7 ~6 N g
divideCurveBuilder1->SetBoundingPlane(plane1);
/ E" s$ `2 @( Y ^! \1 X1 J- U5 j. E3 Y1 C8 g/ P1 L6 h3 m: a
Section *section1;
+ n: A. o& o* c5 z& ^; h$ ~ section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
2 X/ i4 p9 J, }5 }8 ]
: Z9 \# r C# h- H! P- L Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));# N! L3 b$ U" k7 e( G
Expression *expression1;
' H. p- P3 G/ { c; \ expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
V% @3 s0 G4 x4 \% s( `5 g, H: S8 ?9 p o- m
Section *section2;+ W9 ^1 [% }2 }
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);( g! ^; x9 C! F# z
( d7 M V9 c: C0 p! z; u Expression *expression2;
' \+ M) X# I4 c8 d x) z( ] expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
2 ?4 h- F" a/ q# T; X+ ]2 ^! h* ~# J. P6 _/ F5 d5 ]
divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);- E! n( W) V R, i/ d M
! p5 U$ [% O5 \: B% @
divideCurveBuilder1->SetEqualParameterSegments(5);
$ z6 E; P7 Y6 C, e& ^2 M: `3 N1 d* ?
divideCurveBuilder1->SetEqualArcLengthSegments(5);
. \7 z3 v; a* ~# q7 h8 j& ~$ W9 E4 o( G T$ Z R1 }
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
% }% i8 g1 [, b7 a0 G4 T- N& A8 t6 |+ S
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
5 P; ]: }9 ^. R/ y/ n% I2 U
7 j7 _4 ~8 _& f Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
+ l" v6 r4 L, w2 ?! ^/ ?& R Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);; R2 B. @& ~+ R4 ?, a( @4 t ], d
divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);
9 V' E1 \3 d2 P3 |$ u+ d5 A: B6 ~' u; O
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);
4 |9 Q# }# u9 u8 }! Q, u4 O
6 a4 \* |1 f5 U0 F+ N Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)"))); i6 n) C1 o3 q8 Z8 V
Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
3 x& W; D& L7 j$ t9 I% j7 O' k7 d Xform *nullXform(NULL);9 A; \( Z0 I% M& Y4 |! p, F
Point *point3;& |" N4 e$ x# W% f1 {
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
9 |4 d) w; M9 r# M' M. |7 O5 d) B1 B/ N4 i* l( M( u3 @
divideCurveBuilder1->SetBoundingProjectPoint(point3);
# ~# i. w `8 z4 G( l ?0 J _' O3 X' i. G4 V: Z
Session::UndoMarkId markId2;
* t! U5 c% a4 I' J& W markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
- p/ ?$ K5 J) _% X- r. n5 b- G) L" N- u6 f0 W
NXObject *nXObject1;
/ J* h6 r/ N7 E" t/ G+ F1 C' l: p4 [ nXObject1 = divideCurveBuilder1->Commit();
$ T" j2 k& W* u" B
; S( j; d7 p1 c6 i) q' n- ? std::vector<NXObject *> objects1;5 U; c) V6 T7 h8 {
objects1 = divideCurveBuilder1->GetCommittedObjects();
$ D/ O5 ^. E# W& Y, y1 `$ l/ T/ q
theSession->DeleteUndoMark(markId2, NULL);# s* f# i5 C9 o8 r$ c/ w5 V
) u3 g( L: W. l
theSession->SetUndoMarkName(markId1, "Divide Curve");
+ A+ ?' ?$ X! O/ {/ [) y
" D/ C: V# X% V1 ] divideCurveBuilder1->Destroy();2 G$ F" G# D" M8 W2 T
* u4 |; N" S" t+ C5 m try
% N4 u7 M6 J. A {# ^7 ^& I+ o X* d4 g
// 表达式仍然在使用中。
% p% S6 p! h% b X. z9 \* R workPart->Expressions()->Delete(expression2);
/ t7 l! r, H/ z" i& O }% Q% p a1 ]9 q6 N9 F
catch (const NXException &ex)
" r9 T4 [" }7 l+ S" P% T& ~ {' O% i# a" C3 r! u0 L* ?
ex.AssertErrorCode(1050029);
8 ?# w8 k) H! B) s, w. J- p }1 ?* }4 E8 d2 x6 s- ]
5 b2 }4 o( G2 i) P( F1 H. H0 \; u
section2->Destroy();8 Y( D1 V# j& N% a% s
! V2 ~% L, n0 N* c: p5 C! {
try: r7 m! s2 T! k$ \& T
{1 [4 _1 |/ q% q
// 表达式仍然在使用中。. Y3 C# V4 b0 U2 }2 I. F& V
workPart->Expressions()->Delete(expression1);
' m4 _/ _5 I \3 ^3 h" F& [2 ` }
1 b0 H4 n8 d8 r catch (const NXException &ex)4 ]# D0 O; n W+ n- d# S7 v
{6 A, z% D7 ^: t h+ p
ex.AssertErrorCode(1050029);
3 V2 l' [4 |8 M, R0 I }* I4 m) m8 p+ I, u6 l
1 n4 j& z: p0 J/ g+ i0 q4 H section1->Destroy();
, b, _+ N/ `- g8 B4 q- j: m4 f Y' l0 v1 s% Z6 Z1 K) A& ], V
plane1->DestroyPlane();
! c) `6 ?) X9 x; y
1 R" g8 }* A5 g, Y) q- F int nErrs1;
) N) Q0 A+ Y1 C' W nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);$ U5 w1 ]0 i% D7 H+ y
# i, ]4 j5 c; r0 o; \; [ // ----------------------------------------------
; C0 a T# n& E% n6 n7 m0 b# \ // Menu: Tools->Journal->Stop Recording
! s3 Z' L. m2 n1 m- a // ----------------------------------------------
8 c9 Q# e1 o8 r' e}, ]! b% ~! k2 M! \, \- c
) U$ ^ G' ?4 o9 D) W6 v# k
7 h" _1 V- E, w5 a
% [" s3 J1 c0 c希望大神指点* c( Y/ C7 j+ [+ j: W( `
|
|