|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了
8 B6 a7 }% r) L5 A! y5 O$ o" k% u, V- T8 S0 k6 }6 ^
std::vector<NXObject *> objects1;
0 i# ?6 i+ Y P6 |, J! Z objects1 = divideCurveBuilder1->GeTCommittedObjects();8 l0 F8 o& }- \ v. ^, Q
2 T% a4 v. o3 k0 V/ y
- a G5 v/ B, K. o8 P2 ?' \9 k# `3 a' E: a/ e
完整代码如下:
& Q8 [ s* \: d( U8 t6 ?' p% T) U- [6 Z, V1 r4 }
// NX 7.5.0.329 D5 ^0 O4 l2 W
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
8 e' P& V8 J8 l) S; v; V9 y//# E' ]/ n5 N1 v. y
#include <uf_defs.h>
& q& u2 W5 p1 A% i% N' R8 S#include <NXOpen/NXException.hxx>
4 v( O" i7 i: S. z- P#include <NXOpen/Session.hxx>7 u- M6 C9 e' t- A$ ~% F4 c
#include <NXOpen/Builder.hxx>
" w R' G, l: [6 D#include <NXOpen/Direction.hxx>
* q7 ?# R% f( T9 h& f/ d9 m. m: Q#include <NXOpen/Expression.hxx>
7 N- \4 J. s3 ]! U: [#include <NXOpen/ExpressionCollection.hxx>* A H$ Z0 _2 h6 x/ {
#include <NXOpen/Features_BaseFeatureCollection.hxx>1 k+ @1 b8 T' R$ q! M/ o
#include <NXOpen/Features_DivideCurveBuilder.hxx>
) J8 s- s8 E* z5 C" i, D5 A- y#include <NXOpen/Features_FeatureCollection.hxx>4 x. P0 G e. X1 C0 v
#include <NXOpen/Features_PointFeature.hxx>0 m/ v4 z9 j8 [1 f
#include <NXOpen/ModelingView.hxx>
; Y% F) o( E5 T& r#include <NXOpen/ModelingViewCollection.hxx>, q* {. ?9 X% B* b$ f
#include <NXOpen/NXObject.hxx>
/ D- s/ X! q* J#include <NXOpen/Part.hxx>
5 ?0 n# |8 ]8 n0 J8 k7 v/ N#include <NXOpen/PartCollection.hxx>
: E" Z: C, p% o; p* }& B( n% r#include <NXOpen/Plane.hxx>" M0 r1 _, U4 ~: O- [) D
#include <NXOpen/PlaneCollection.hxx>& W* E% w, P/ D7 L- A7 u) X" @ j$ k- W
#include <NXOpen/Point.hxx>
8 y1 x8 `: m e* u# g; c" I0 _#include <NXOpen/PointCollection.hxx>
9 H4 l- @& t6 u V- [. f; [#include <NXOpen/Preferences_PartModeling.hxx>
: w9 `# n# v; _4 C4 x#include <NXOpen/Preferences_PartPreferences.hxx>$ N. a$ k* w: Y! O) p h
#include <NXOpen/Section.hxx>
0 e4 }- ~$ G1 S; R#include <NXOpen/SectionCollection.hxx> {( `. Z0 _# s
#include <NXOpen/SelectCurve.hxx>$ i, L9 b9 t5 R) X, l9 m
#include <NXOpen/SelectObject.hxx>$ r& L1 M X7 V6 o
#include <NXOpen/SelectPointList.hxx>
1 S* m9 m' o7 v#include <NXOpen/Session.hxx>2 k! q$ `, s/ E" J; s5 G$ T
#include <NXOpen/Spline.hxx>
& x9 h: H9 v, ?: }0 T, V, r#include <NXOpen/SplineCollection.hxx>
1 C; _- O8 q1 |4 s# T#include <NXOpen/TaggedObject.hxx>' }( h1 v4 K; {, k6 Y* u
#include <NXOpen/Unit.hxx>
1 r/ [ q5 T- g% _/ o0 W#include <NXOpen/UnitCollection.hxx>
" Z: c( ~6 Y, u" f! l#include <NXOpen/Update.hxx>8 h; n: a% I. [4 c
using namespace NXOpen;. k6 o" S4 { r2 j! b) v! \
$ E+ A. b7 g# _# I- Iextern "C" DllExport int ufusr_ask_unload()
& T4 N$ a& I; M( J7 O( I n{0 i# {) ?" {6 _8 J- ^! W' {5 k2 s
return (int)Session::LibraryUnloadOptionImmediately;+ I& W# j1 [0 f! H6 h! g3 H
}
" _# I, O( ]3 H% M# e0 J
8 ]# @" |" e8 ~( F% fextern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)2 P$ ~( x0 M( V* X
{
- a7 K4 E1 S5 h& z" ` Session *theSession = Session::GetSession();! ?+ n. M I5 |
Part *workPart(theSession->Parts()->Work());" h" ?) [0 h$ g$ u! f! s
Part *displayPart(theSession->Parts()->Display());) r$ \9 ^0 ?% ^& p0 S2 C8 e. L, C
// ----------------------------------------------7 u% K& m a1 ~" r
// Menu: Edit->Curve->Divide...; g1 U* v* H9 s) S$ D
// ----------------------------------------------
2 _6 {9 }2 v- V1 `% l) c9 [5 t Session::UndoMarkId markId1;
- X* F+ A# Q3 L( U. g- @. X( u# u3 J! J markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");4 F+ h7 G9 w! h0 |7 a
6 C; M& g' s/ h4 A1 B1 Z Features::Feature *nullFeatures_Feature(NULL);9 f, n3 C# J4 I d/ Z" z
7 X- O2 m3 t7 v, w if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )8 p0 ?+ S7 R }' p2 w2 i2 v
{
$ m* g$ o/ A' y throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
& e! I3 Q5 D" q }
. H" V7 \7 x; E( ?: ~" N6 C2 Z T" |: V. V4 t6 C) o
Features::DivideCurveBuilder *divideCurveBuilder1;
7 f; G! n. I1 n7 U" D9 w, d2 y1 O divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);7 ]9 j; R. _3 _/ A4 W0 s
2 ?8 U9 r$ d& |5 j- G Point3d origin1(0.0, 0.0, 0.0);
- E7 ^' [/ ^ a) y/ V6 U Vector3d normal1(0.0, 0.0, 1.0);( n# {0 N q# P& ]" l' M# t
Plane *plane1;. r6 w8 d1 y( a# B- J9 W
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
* e* w2 d3 W! e$ R$ K5 h3 Y2 N' g4 y0 S5 R6 z1 S
divideCurveBuilder1->SetBoundingPlane(plane1);
/ n' k5 p0 E% W" ?6 d7 t$ v, R" y+ ?( J t, `6 a7 v
Section *section1;
' v7 ~; m: N8 e! a$ f5 B, O4 Q section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);5 C1 g' \& `, P) Q
# c, v; C! m, Q3 f
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));6 ?2 v7 L$ C# e9 Q2 o6 `
Expression *expression1;
# c+ p4 r8 ?$ _* @7 G+ b, W4 ]$ x expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);7 A9 ?6 ]9 _. K1 @5 s2 E
- g" C) J5 |( Y
Section *section2;
, ` n- |$ d% n section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);7 Z8 I$ {" a& u. u5 j
* y1 R& v2 H6 i5 J O Expression *expression2;
F$ {' n* o. x expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
! i. v$ G8 |. Q/ E$ f* d
8 h; T, Y+ M/ G/ s2 ? divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
2 C- D' x" P! Q( c. S, I# [" @9 B8 ]3 S( [
divideCurveBuilder1->SetEqualParameterSegments(5);
# {0 L- ?( w2 r. M1 q
/ B, R- ?9 R* n2 t3 \0 m/ i' V divideCurveBuilder1->SetEqualArcLengthSegments(5);) g/ n/ F; v# K) s6 x
7 c0 w7 h7 s0 n" o/ P; d
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
2 D6 ~, b- m+ {/ r$ h( A7 U
9 B; F3 j4 m2 L+ }( {& v* ^6 l4 ` divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);! y; s0 t h5 ~/ c9 ^! R
/ C) s& R, n* B" l/ v0 s8 i
Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));% ~1 o+ t: p& ] g1 M( x$ o& f
Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
# ?9 {6 I, d% k/ K! u divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);! m7 K- E6 g1 i6 Q* a/ ~
0 t/ N6 U1 e# R divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);3 [) J2 D9 w* p" A5 d; @
9 J$ ~ ^* G9 w3 E/ k, y Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));9 N/ ^- f! L; m" x" x) Q
Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
3 K4 @ N' }" D7 W. B Xform *nullXform(NULL);
+ I" P2 n% w; A' D! @; D Point *point3;5 }. d% O. W9 i" P3 g
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
" l8 l2 w" h D( u# d: ^6 {
) \2 r! a8 _8 v divideCurveBuilder1->SetBoundingProjectPoint(point3);
$ Y: @% K# n) |* W% B% `; w8 p) f7 `5 y2 S* E% F
Session::UndoMarkId markId2;5 ~! v) A) o( \8 J
markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
- Z; r( e9 T& W$ l. r' I( ]; Z/ }
NXObject *nXObject1;5 ~& e' m! f7 S
nXObject1 = divideCurveBuilder1->Commit();
S( u9 G+ N1 g+ ]. D( s9 Y; u: P% _2 D: N2 l: U
std::vector<NXObject *> objects1;
$ g' ^) Z( S5 v4 ^- P' u% B objects1 = divideCurveBuilder1->GetCommittedObjects();
6 S- U) Z, j, o. ?, X9 X( L1 p4 P; a1 J/ F( \* e# d; G. ]; Y; ]9 U
theSession->DeleteUndoMark(markId2, NULL);
2 B. f' Y9 [) Q8 l8 Z& }
. H4 r) k: A) N$ s, g theSession->SetUndoMarkName(markId1, "Divide Curve");
) N1 k( H; V5 h, w* l' \8 M
9 J9 ?$ ~7 U$ U* K' i7 z | divideCurveBuilder1->Destroy();" `5 n0 e5 H- k& k& T0 F: Q2 o4 ^
+ d5 ?1 b- D- p$ H1 R try
9 u3 Z& q9 O, O$ n" ^" d {
# R8 e6 D# Y) a* [0 ` // 表达式仍然在使用中。# e( a, j( O' A) K, m& Y
workPart->Expressions()->Delete(expression2);# T; G/ [0 F. B" l! u& v+ S
}6 [/ n& g$ c+ U/ p) s0 n
catch (const NXException &ex)4 |8 m0 ~; p+ p
{
o& n# r2 i+ v$ _ ex.AssertErrorCode(1050029);5 P# X% p; s3 i* q
}
( {9 B& g' `4 h2 t
* g7 j; s$ K1 c) D0 Z3 t section2->Destroy();: i7 U. p) M! x( B6 }- C7 E
% X4 o! l7 L ?- ~/ C
try
$ p: g) H6 S0 Y; R) i3 v6 S7 R {
. W+ g+ S& c, Z // 表达式仍然在使用中。8 k, S& K! }% }, p/ H y$ K
workPart->Expressions()->Delete(expression1);
- R6 Q, h5 L0 _( Q1 @& F1 [ }
) h8 j# K) ?: |6 g catch (const NXException &ex)
# e1 @" |6 p# x {
# {+ M; d$ M, ~; [$ M5 }1 [6 Z3 A( J ex.AssertErrorCode(1050029);
2 {% ~5 n8 O% R: h& v6 m }
8 A/ J8 k! O+ K5 G5 k% b
6 r& F$ M- Z3 Y5 H9 c9 ` section1->Destroy();
1 r- w- i- g3 c/ ?: i0 E( P( N- ^: M7 {2 i
plane1->DestroyPlane();
Z v5 g# o T7 ?/ u& y
8 \% b) z9 l$ B$ `2 O$ w int nErrs1;
/ C V( E$ g) X6 H. f nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
5 \4 o5 m7 @7 a" l6 y. q8 w9 `1 Y2 n3 T2 q1 j2 I- n
// ----------------------------------------------* h+ d2 @% z1 Q. A+ ]6 ^
// Menu: Tools->Journal->Stop Recording; D% E( q; `2 H
// ----------------------------------------------
% f+ Y& }, b# z5 }& p4 v}& _/ |: H& b7 X1 S; r
9 Z, |2 N" I) B9 i/ H: k/ Z# v" i1 B' T* K3 W0 X6 b) g, ?
% {4 ` f7 `) z0 w5 v( A5 B希望大神指点
1 Y, U. ^" K7 r* b" s1 ?+ v' Z |
|