|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了+ U$ [- m9 f5 I7 {6 y8 @+ ~) g0 r
1 V- `0 M5 V( ]7 g' C& Z) V9 O std::vector<NXObject *> objects1;
4 w0 l# J/ H+ v Y objects1 = divideCurveBuilder1->GeTCommittedObjects();2 d4 {% z1 U6 G
9 g& p& a# [* s
4 E6 h* c% N# l' G8 {* S: s$ |8 c# T B9 \) j/ r# A
完整代码如下:
" o8 F* M( b' \/ M0 s7 ~: `
) }& p$ c0 A# f// NX 7.5.0.32
4 C: K2 K1 R. F, V- P0 N* @// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
' p3 k; ]8 u3 b" P- o//2 C+ s. o1 S7 a' m0 Z
#include <uf_defs.h>2 s9 H) q( F% [+ R, \
#include <NXOpen/NXException.hxx>
) a% E/ D* z! v: b2 x, m#include <NXOpen/Session.hxx>
! ]9 N3 a! o* X+ ?/ |/ G$ x#include <NXOpen/Builder.hxx>
7 B6 Z1 B0 W2 j3 b- `" e1 |#include <NXOpen/Direction.hxx>+ N. ^/ o5 v& h; V" O, U
#include <NXOpen/Expression.hxx>
; {- f& M1 x& F9 Z) \' d- K+ ]1 p#include <NXOpen/ExpressionCollection.hxx>
! _$ c5 ^7 K3 ^# B9 Z f#include <NXOpen/Features_BaseFeatureCollection.hxx>
4 o9 c8 w3 L6 k5 p7 r#include <NXOpen/Features_DivideCurveBuilder.hxx>" m# x' S9 g+ c6 Q2 v6 f' ]
#include <NXOpen/Features_FeatureCollection.hxx># q+ j; w# o! [& r; A; z
#include <NXOpen/Features_PointFeature.hxx>
" l# _ p! i: z! u7 z( P H#include <NXOpen/ModelingView.hxx>
' a* a6 [4 | o5 D' P9 S4 N% g#include <NXOpen/ModelingViewCollection.hxx>
% @& G5 U1 D' z* ]& {7 W#include <NXOpen/NXObject.hxx>
& I+ ?# R6 I) y" J C2 S' I' N( l7 k9 Q#include <NXOpen/Part.hxx>; t, i2 ]/ b& G5 G2 } Y$ \3 v
#include <NXOpen/PartCollection.hxx>/ R7 `9 X0 K7 ]5 U% {1 O9 R
#include <NXOpen/Plane.hxx>
5 S- U+ k6 s2 N#include <NXOpen/PlaneCollection.hxx>
$ b7 e5 K; U8 u5 K. V# X! |, h#include <NXOpen/Point.hxx>
! L* f4 A' V0 a5 q#include <NXOpen/PointCollection.hxx>. H0 M1 G' B% H9 S9 X& e
#include <NXOpen/Preferences_PartModeling.hxx>
0 F: p6 ^- k0 _9 ^#include <NXOpen/Preferences_PartPreferences.hxx># Q7 r. J4 q2 n% ~
#include <NXOpen/Section.hxx>
) t4 m$ ]5 }: Q0 r% r5 A#include <NXOpen/SectionCollection.hxx>/ |1 Q) U7 m N9 R4 m8 ~
#include <NXOpen/SelectCurve.hxx>
/ m- v3 o6 X# C& I3 Q#include <NXOpen/SelectObject.hxx>, m# L" j: E) G) m3 o
#include <NXOpen/SelectPointList.hxx>
" O) W$ b' O; D* m#include <NXOpen/Session.hxx>
: i! O. R5 {! q+ t- ?3 E#include <NXOpen/Spline.hxx>
# B% K; N8 Q2 ^. f3 M#include <NXOpen/SplineCollection.hxx>% h) H( f+ i9 Z4 y8 ~$ a4 N
#include <NXOpen/TaggedObject.hxx># T8 u5 d2 b) T1 N* s
#include <NXOpen/Unit.hxx>
/ V$ q- o% H4 g7 e#include <NXOpen/UnitCollection.hxx>
8 L9 C, @) }/ W, _#include <NXOpen/Update.hxx>5 f5 o9 m4 @9 {$ i4 O5 n( z/ d+ t& M
using namespace NXOpen;
2 c0 n, t0 A3 W+ Z( |! k5 z9 v$ F
- x' i7 O6 }/ ^* r3 z% Textern "C" DllExport int ufusr_ask_unload(): r! ~* W5 l( F; I* S J
{
# ^) m3 A" T) [# A8 t: q% v8 \ return (int)Session::LibraryUnloadOptionImmediately;
: p% q5 ~- r7 m& z2 k4 A+ k}
1 U5 ^! O4 N6 B. B" B! `7 ?# [, A. i. F Y' b* L
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
2 X1 Z) l ^ x: J{
7 Z; U3 a# e, d# J, i" D5 l Session *theSession = Session::GetSession();. D" N+ b5 G! ]3 R$ E8 G4 q& @
Part *workPart(theSession->Parts()->Work());
- ^9 U% X3 q9 B2 g/ U Part *displayPart(theSession->Parts()->Display());
" X8 M& ~. B/ G1 B" c% O // ----------------------------------------------
3 g \; S1 Y) |2 i5 v // Menu: Edit->Curve->Divide...
^8 G% X: g9 H // ----------------------------------------------
1 H8 o! H2 S. h7 v% Y6 C: Y! W5 R Session::UndoMarkId markId1;
7 t0 s7 v: D8 D9 f5 q, f% Z( t markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
; c9 a$ z+ w0 U% t( d* G# v6 F# G" Q$ l/ c! q: E8 j! [
Features::Feature *nullFeatures_Feature(NULL);! i) z9 H# j8 ^- j5 c
4 b$ \: }, r) S8 t C3 d if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )& c5 N! L1 C& e# \* c4 ]% e8 \
{ R) A$ N# S6 }! b0 K
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");. x/ R" H7 o$ T* ~
}* [2 y8 v5 F5 F! B+ E( T3 C: x& ]* [
; s, a; g0 p: P$ D2 j+ S Features::DivideCurveBuilder *divideCurveBuilder1;6 H( y* ?/ W) `! z1 B/ K7 B" d" x
divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
C# }0 i9 ~2 {1 X3 O0 ?% S1 f8 u1 F6 [1 f: U/ X8 }
Point3d origin1(0.0, 0.0, 0.0);
7 ~9 Q! Q7 p+ e2 ^# I# \4 X* A Vector3d normal1(0.0, 0.0, 1.0);2 [7 e: W8 z( C% ~7 @; O8 r. N1 h
Plane *plane1;
& l/ {6 `* }( H8 { plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);8 a+ d: f( z ~3 W6 l. | I- q( x
$ p' l8 G/ a# w ~5 r
divideCurveBuilder1->SetBoundingPlane(plane1);+ c% x; G0 Z: B- Q; l; |2 M6 c
. T0 X$ p! R* K3 A" \9 L# z
Section *section1;
0 t! C% d: C! G section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
3 S0 F' p+ e) L3 F( T( E6 v- F4 {" Q4 A; x2 t+ h2 o' N+ w7 s! a
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));' w# o. ^% g9 h& \% r# {" `6 O2 o
Expression *expression1;
- C- H' o, q& _# b1 m# z5 \ expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
# H& u7 t! B/ F8 e
' Y. Q$ d* V7 T Section *section2;1 Y! M- V* o7 _! C" b$ _
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);3 n% l4 R+ P5 E% Y
. _1 G* Q& {7 X Expression *expression2;
2 s3 ^. d4 m* x$ k; @ V# N& x* r expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);7 C+ s: Q0 h/ r# ^3 T
% ~* \3 Y% p+ W8 {: e( f divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);+ S5 P7 R3 W2 I* t
) T; b' D" i; v" I# ^
divideCurveBuilder1->SetEqualParameterSegments(5);" m: H! I ?, J& ~/ X j
7 a( i2 p4 K" y, a divideCurveBuilder1->SetEqualArcLengthSegments(5);
3 A; u u- C: ^+ F3 k
- V3 G& I! [9 M8 ?; Y1 J theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
, Y8 m+ r* e2 x/ X/ o3 r5 {0 O5 r) s' a/ I8 d; z Y8 y
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
, n' ?2 s4 s3 r* k ?+ U8 b
4 v: R/ r0 Z# G1 q% H Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
+ o8 O0 Z9 |3 B9 Q& @5 @ Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
7 Q3 A% J; X& E* r% v7 H divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);1 E# e+ Q7 ?3 X
$ O" F/ \7 F G" ^
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);* u, v3 X# S; y
+ C& A: {- E& d Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
& y4 p! U1 V6 |7 j8 v; Q7 J" ^ Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
5 ~; W) A& S( c2 X U Xform *nullXform(NULL);, q5 i' G- B4 L: c- e) e. I9 k6 `
Point *point3;& l- A( ~* i ?; E( t* R& E
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
' c# D, j% ~- L0 g; k$ j" ^
& r) U8 j; \: y9 | A7 @7 g divideCurveBuilder1->SetBoundingProjectPoint(point3);1 k) P* c% |* l N$ k. o0 I
" {: q2 F5 G. t( e/ j( Y7 B- Z8 `
Session::UndoMarkId markId2;
4 F7 ], I6 q3 ~" d( r) s, h4 T5 k markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
: q; U8 F& q- U+ ~( m8 u! s7 ]% q8 ? j, U; K8 r0 F+ l
NXObject *nXObject1;
$ ^$ I) U4 A+ s6 [& l# K' g nXObject1 = divideCurveBuilder1->Commit();, x) `" I ^# Z- t' k! M
' r f$ M3 ~( V! R/ p6 h
std::vector<NXObject *> objects1;6 O- g. s" q) X5 Y- I
objects1 = divideCurveBuilder1->GetCommittedObjects();
( I- M, |) ^+ d0 h. g( N; j7 ~* ?
/ c1 `6 O, \; R1 W* a- W& F theSession->DeleteUndoMark(markId2, NULL);9 l0 g4 u5 E# j$ I3 F. h9 R
2 Z6 L; R# }7 h$ O6 a% I theSession->SetUndoMarkName(markId1, "Divide Curve");
9 w$ r% s# w" V- s+ S
. P4 o( b* Q/ x. \3 |9 T" S divideCurveBuilder1->Destroy();
% j3 x# V% T) G. D9 @1 _, Y& P. u; n* I) r, a
try G- R* ?/ l; }; X3 E( z! w; R/ ~
{- V/ w0 M$ J8 Y. W5 ~
// 表达式仍然在使用中。) Y, i6 n9 n/ ^' ^9 }& C4 H- P/ e
workPart->Expressions()->Delete(expression2);
% ?0 }7 \! x5 p* m }
% _2 b3 v9 I n, ^8 g% N catch (const NXException &ex)! h( C% F- c, O3 T2 O9 m4 e
{9 j1 ]; d; T" Z+ k1 x- B" g
ex.AssertErrorCode(1050029);
# B' x; v5 i2 r# h }" p& p3 x( M4 ^) j1 u
7 W3 Z! Q7 a/ p, Q2 K section2->Destroy();
8 |. h/ h+ |( B, v# ?! I
/ m% L7 c: ^$ X) C- f* K try2 a3 Z' k/ ^! b9 m
{
# p& o G- k4 T4 U // 表达式仍然在使用中。$ G& K, \( F8 m) [: ?
workPart->Expressions()->Delete(expression1);6 `5 q, r1 g( t2 o
}7 ]! Y. x0 d2 C. d# P
catch (const NXException &ex)
2 Y! R' a# s. w {! h* S2 @) x1 _ ]. k3 P
ex.AssertErrorCode(1050029);9 C$ @# a: R4 u+ S
}
3 Y0 W9 o4 O! s0 L5 _& b% B) n' X: S+ b9 V+ O
section1->Destroy();9 U" \8 p' _- \5 I* V5 W3 c
( n4 H$ P' ]2 F4 F. A+ M
plane1->DestroyPlane();( ?7 V% ]& o3 s) D/ e; c% K0 Y# F
# _# G m9 ^$ W* i
int nErrs1;
: N$ b2 b+ P& ?4 ]* c1 l nErrs1 = theSession->UpdateManager()->DoUpdate(markId1); e$ v0 j' S: V5 Q4 g; `+ u, I
4 b! }1 U$ @& E% G4 v0 v. x- v& \
// ----------------------------------------------* X8 l/ z; z* p
// Menu: Tools->Journal->Stop Recording
) G: f! f1 Q0 \+ u6 X // ----------------------------------------------% ~9 r( y, |, ^' I, C: v- F
}2 s! Y y! ^! K; S. W
( ^; j( |5 ~' i2 A3 U. g7 e% S8 L
6 w \+ q& u4 H" C
, J- \* p, w8 w8 V希望大神指点! I' t7 i% C* C* N; o2 u# _
|
|