|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了
4 D# f. |7 f3 J
; Z6 z n$ K' k std::vector<NXObject *> objects1;$ i2 I% f' ? o9 x7 _$ K( B
objects1 = divideCurveBuilder1->GeTCommittedObjects();7 U4 ]8 e w4 q* ?
, j+ H4 k' J3 u, b
9 q" h5 _, ~' X( Y) H( Z
6 ~/ m! _5 Z, x3 b- E l2 Z
完整代码如下:# V( A# p0 B( U" A! W$ }1 i9 u
# ^7 W/ N; p4 A6 t- D6 g
// NX 7.5.0.32
0 ^ I5 F9 L$ p7 b9 |4 ~4 r3 W// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
8 L3 q5 H0 d: V& z3 b- H8 e//; p/ p4 D( I' k$ _ d
#include <uf_defs.h>
m: H0 v- }2 |1 T! m! H+ }+ _#include <NXOpen/NXException.hxx> | m, ~# P* H+ O
#include <NXOpen/Session.hxx>, F8 } L9 ?! u: f8 Q
#include <NXOpen/Builder.hxx>
* F) q' i+ |6 Q& K; ^3 s- p) s) R#include <NXOpen/Direction.hxx>
( ^) I: @7 z' {: H! A#include <NXOpen/Expression.hxx>
z# L8 T" u9 l% t6 i) j) J7 s#include <NXOpen/ExpressionCollection.hxx>
1 X8 Q9 n* L. h! O0 h/ N8 A#include <NXOpen/Features_BaseFeatureCollection.hxx>
6 P6 P0 f" w# z7 q4 W0 `#include <NXOpen/Features_DivideCurveBuilder.hxx>& q. q3 i* L4 U3 o! S5 q) v# ?
#include <NXOpen/Features_FeatureCollection.hxx>9 R( E5 }/ g# f7 K6 }, D
#include <NXOpen/Features_PointFeature.hxx>. F: }- z7 o& A1 S/ t8 Q
#include <NXOpen/ModelingView.hxx>
" c; i ?: M1 R* ^& G+ J#include <NXOpen/ModelingViewCollection.hxx>
' c6 {' u9 ~4 j0 Q$ x% N: i#include <NXOpen/NXObject.hxx>
) ]5 H9 H, T, P#include <NXOpen/Part.hxx>2 r/ E i( w" q
#include <NXOpen/PartCollection.hxx>* c0 P7 b# z( N* E, g- u7 a# V8 w
#include <NXOpen/Plane.hxx>2 v( ?& w. G! j! m, R
#include <NXOpen/PlaneCollection.hxx>+ U$ [* D4 J' r% I: `6 h( ]
#include <NXOpen/Point.hxx>5 i, O& e' v, Z8 `: G2 D
#include <NXOpen/PointCollection.hxx>
; d4 |; l1 ?8 s# J) `/ B#include <NXOpen/Preferences_PartModeling.hxx>
% V, b' o) H' _7 u; W#include <NXOpen/Preferences_PartPreferences.hxx>- f' `% J1 B6 {- x6 ^
#include <NXOpen/Section.hxx>
2 x: B4 G4 I0 J#include <NXOpen/SectionCollection.hxx>
$ \; v2 ^) J9 [4 `#include <NXOpen/SelectCurve.hxx>
" x9 P: G, \4 {/ n#include <NXOpen/SelectObject.hxx> T8 ~7 L( Q. I5 Y0 q
#include <NXOpen/SelectPointList.hxx>* s9 L3 p1 j" C- s2 M6 ~
#include <NXOpen/Session.hxx>9 K3 e8 [7 P; T: l3 r
#include <NXOpen/Spline.hxx>
" Z$ f4 }1 L: {3 b" E* H#include <NXOpen/SplineCollection.hxx>1 ^( h* E9 `5 }3 F/ Q$ I1 u1 s" u
#include <NXOpen/TaggedObject.hxx>* K; N% o; O/ G0 v O
#include <NXOpen/Unit.hxx>, i2 Y0 A3 q6 N; Y; w
#include <NXOpen/UnitCollection.hxx>
?3 @/ a$ L. D4 \2 \+ ^#include <NXOpen/Update.hxx>2 j' M6 a* t+ q5 p8 r% I4 F/ a
using namespace NXOpen;
' H6 Y- P6 n a0 V
& P/ ^: E8 R! G8 W1 y( Wextern "C" DllExport int ufusr_ask_unload(). a& ?$ z; n' D/ j- ]% ]$ b& m
{
1 n7 B( `, S/ P5 f/ E return (int)Session::LibraryUnloadOptionImmediately;
/ u5 F" {, s# X$ h}
# T: H" ]/ B% V) D2 e) N' T G; q
~0 Z( O+ k1 Eextern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
; p& L! U: P. x: Y& R) a" ]; B( [{( B. x4 }. ]/ v, U. P
Session *theSession = Session::GetSession();2 y- X8 Z9 S! I, [; Q0 P
Part *workPart(theSession->Parts()->Work());0 [7 n( g+ p Q( ?$ v
Part *displayPart(theSession->Parts()->Display());9 ?+ o7 K( g' r8 f: {( |6 M$ H/ g8 _. ?
// ----------------------------------------------: m6 X, X6 W* i
// Menu: Edit->Curve->Divide...
Y- H0 a- r8 _+ ?2 n5 S( A // ----------------------------------------------
8 O5 z; [1 f% q Session::UndoMarkId markId1;3 ] a- r( g c7 h2 I
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
, X9 k1 [, O# |+ Z
! M7 @" D1 o+ K0 ? Features::Feature *nullFeatures_Feature(NULL);
; `# {& T$ A5 d# C. f; ^- K' V+ l, M2 O4 a
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
2 L/ D$ I+ J- U! R' j {
% J/ T: h. q) N* q' K throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
$ T1 X! ]7 `6 n" P9 z( E }
" j8 y+ E& H* p! y5 \9 s- Q& C$ P/ ^" O7 _
Features::DivideCurveBuilder *divideCurveBuilder1;
5 {' S7 j) k) J0 P# B( C5 S divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
+ x9 ~$ _/ T1 P1 S
: ^" i3 J) N, O6 V2 { Point3d origin1(0.0, 0.0, 0.0);0 e: t' D M2 l2 b+ n# u9 H
Vector3d normal1(0.0, 0.0, 1.0);6 s% M9 ^. B. j0 v i3 Y3 r$ V
Plane *plane1;
! r0 z. u0 E4 i0 X plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);5 h! ]: N; ^- J0 W7 H
& J1 d: Z+ ]( g) v( ]9 I% x
divideCurveBuilder1->SetBoundingPlane(plane1);
+ _' M3 ?6 t# `0 r( x
# k9 L ~5 z3 A2 m, m4 k* {* ?( B% d Section *section1;
5 J% o" ^' e1 A& J% `2 Q! j section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);2 \; Y |) j3 G
( {3 a# z. ~9 b Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
1 l2 l8 k: I& _5 u8 K% R& z Expression *expression1;, h; y8 m1 \9 W/ c! G
expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
. r( v! E/ F6 h1 T! \( x8 L X8 X3 s" N/ y& c# v
Section *section2;# S8 i' H! A# Y! G5 s+ U
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);4 O) [4 S4 H5 c4 Y$ O9 |
9 k2 b4 T' z. H H
Expression *expression2;
$ c7 G. C' \4 k* H3 v5 T' l0 S expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);) ~! r: t" s) P1 v
4 h: V' V7 Z3 D: e5 {- \/ g divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
" c4 ]. J* [" e) A- ~7 W: w6 t; n& w0 X$ ]# C
divideCurveBuilder1->SetEqualParameterSegments(5);
/ I. {* D+ o6 i1 g1 u) p" X
- p/ \0 a/ b+ d0 o& q/ } divideCurveBuilder1->SetEqualArcLengthSegments(5);0 d4 O. Z- ^$ S- K
9 _3 R1 p5 w- V( ?& }$ O) [5 D" U1 I theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
4 P7 I5 |2 u+ O: K+ D+ U3 i6 j$ g' ^
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);. B; S6 k# Y* e
4 W# j+ i: j% H Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
: u# }5 ^- }0 m D3 O. i* u Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
5 W0 ^8 |/ H+ _. e" x; H divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);
$ e+ K# S. ]' ?+ w B+ B+ K2 U3 A0 k( v0 N' f J
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);! i$ F5 q3 U! V' R
! \4 [: I$ g/ T
Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));% Q( |9 p5 u. y3 Y- Z' _9 }- h( r
Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));. ]1 Y; |3 P7 z. I; d4 L, E
Xform *nullXform(NULL);
+ P& K$ k' q& {/ K4 W4 }' u Point *point3;
% J. x3 @# k. q, b+ W& V/ S point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
* e) i, A. Z% U3 @. h+ l$ N7 ~" G* p6 J
divideCurveBuilder1->SetBoundingProjectPoint(point3);
6 v0 E1 |6 f' R& v8 S
; Y% S$ ~/ p0 _ a- ^( ~3 {5 S Session::UndoMarkId markId2;
2 g$ `' N$ H3 f( O. K) U8 b( n markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
5 o. U/ M0 ?' Q1 Q1 [7 I) w' m" j* R& Z8 ?5 E
NXObject *nXObject1;
2 M1 m" c6 U) L. R7 N& p nXObject1 = divideCurveBuilder1->Commit(); r$ g/ K+ g. F. |! h' K3 p2 T
: ^6 i9 U( t- q- j C) q! [6 ~! l std::vector<NXObject *> objects1;
9 s* ~/ Z( u0 J7 g objects1 = divideCurveBuilder1->GetCommittedObjects();2 g4 Q ^- U R: T! \+ X" d$ u
/ d# `, R T+ f. G$ W2 E
theSession->DeleteUndoMark(markId2, NULL);
% Z, |* l4 N' s' [7 ^6 y8 @1 o" Y
( X3 J8 { g2 l& z2 J theSession->SetUndoMarkName(markId1, "Divide Curve");/ q$ ~7 G5 w) _ M9 T! T
' ?' d8 D% V8 N" x: g& c7 N divideCurveBuilder1->Destroy();
& e, _2 f& X$ p4 E. o6 y6 V' M1 y I: V4 p3 O
try, X. z- D4 W% `3 J, }. P
{! d5 ]3 F; G y0 L0 S7 ?
// 表达式仍然在使用中。
! E( o( X# d/ I5 Q workPart->Expressions()->Delete(expression2);
\% @+ I# r5 F: I# y' ? }8 P- {) E( R7 f/ D" y) o, h
catch (const NXException &ex)
# x R4 d0 `3 ^% e, W {
# {! v& N* }- Z% b3 t* y t ex.AssertErrorCode(1050029);
$ ~; ?5 k3 U$ g/ V$ w f1 w$ h }- X" C- z+ H+ Z/ |
9 W) y1 U+ h" W; r0 j section2->Destroy();
% f/ L; I6 E: m A2 M& d E; J1 b0 O& U6 Z; w, l2 g# U
try
. E3 s# o1 l% t5 Z7 q& h6 Y% E+ M {
$ h# x- A( G _ S9 D# {/ d" h$ r( B, O8 \ // 表达式仍然在使用中。
0 e% {, ^0 c6 U, [ workPart->Expressions()->Delete(expression1);
4 \) X t# j/ n5 b/ N }7 Z' @3 V Z/ c1 l% @) \8 L1 u
catch (const NXException &ex)- r. c7 N2 L7 r" k6 E
{
- H% C- I$ A4 Y* T H ex.AssertErrorCode(1050029);
% O! i) s) V0 M0 U- q$ ?9 [$ D }1 p* Q1 R9 _: M) V- u5 v
7 f' t( M* F8 o1 Z8 B& N, c section1->Destroy();
* {8 {8 c b* w& K( I* e. \3 m: w
plane1->DestroyPlane();0 ^ e% w/ v) Y t. r
$ F7 b' c7 y% D' j& U: e
int nErrs1;6 u9 U) e8 [% o. b) R
nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
# p& P- E8 y' d/ K/ I. P1 m- N9 n" |6 ]& M) X6 `) T
// ----------------------------------------------$ }$ }) `- \3 q, Z
// Menu: Tools->Journal->Stop Recording# l( ]9 C2 N5 d
// ----------------------------------------------
/ }# _6 w5 W& S' F}. c% @, ], v+ n3 {4 K/ l; G% Q
: v3 F8 q& V+ g
$ V8 z" O0 ~1 H: K) d5 G' `1 Y9 }' F: C% w
希望大神指点* ^9 ~, r: q+ `7 K1 r/ l+ {
|
|