|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了( D/ G1 L- t {* D0 n& y/ L, ]
5 T% A$ f9 A0 n9 Z2 | std::vector<NXObject *> objects1;
, P6 G3 P2 I5 s! e objects1 = divideCurveBuilder1->GeTCommittedObjects();/ z) g$ J! f7 l
" Z/ I) a( |; h) g! t Q' Y+ N2 M8 U* b7 O
& y) X6 L; A7 A0 O' }4 C
完整代码如下:
' k7 t7 V" g6 F. @! D3 F" M. [5 X% D8 a* K2 z* w+ u
// NX 7.5.0.323 @, w+ o$ y' @( ~; A, u
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间8 r6 g9 o! ]0 `* n
//8 d8 \& ^+ A+ z2 h5 D t* E7 H
#include <uf_defs.h>
O! g! u o& I6 o3 L* m* F Q#include <NXOpen/NXException.hxx>
9 E) }- ]( j5 t#include <NXOpen/Session.hxx>
% a; U! S, X$ y0 N- Z#include <NXOpen/Builder.hxx>
/ r" S, l0 p5 y#include <NXOpen/Direction.hxx>
: B" f z% l: C#include <NXOpen/Expression.hxx>
* k' q" Y6 _2 g. I2 [, J#include <NXOpen/ExpressionCollection.hxx>
: o7 X+ Z& M3 g#include <NXOpen/Features_BaseFeatureCollection.hxx>: ]5 p8 }% `1 P6 v1 f
#include <NXOpen/Features_DivideCurveBuilder.hxx># o6 f4 O3 p) p) L* U: P. b- }
#include <NXOpen/Features_FeatureCollection.hxx>
4 u$ @3 F1 C* b8 [#include <NXOpen/Features_PointFeature.hxx>
E/ Q5 ~& |+ t$ j2 x#include <NXOpen/ModelingView.hxx>
1 ^5 I) ~4 |$ E# i* J$ z7 ?#include <NXOpen/ModelingViewCollection.hxx>5 ~ }3 Q/ X* l' k8 _+ ^
#include <NXOpen/NXObject.hxx>; ^. g% a4 S" J1 p+ k: C2 @! n
#include <NXOpen/Part.hxx>- P' l: ~. I1 P4 O [: L
#include <NXOpen/PartCollection.hxx>
* _- k" G5 {0 ~. E#include <NXOpen/Plane.hxx>. s: p/ I7 O! k t
#include <NXOpen/PlaneCollection.hxx>
" u5 O, i1 j6 T- `" m& ^#include <NXOpen/Point.hxx>
5 v- U9 t% N+ x" D#include <NXOpen/PointCollection.hxx>/ Z* @3 [* v/ D0 e3 a
#include <NXOpen/Preferences_PartModeling.hxx>
: k! s+ q9 T' }& {' S#include <NXOpen/Preferences_PartPreferences.hxx>" O8 o x2 B& \+ l
#include <NXOpen/Section.hxx>/ i1 L" d; S i" }' t+ W r
#include <NXOpen/SectionCollection.hxx>0 o! f% g$ |. R3 J
#include <NXOpen/SelectCurve.hxx>6 b9 s# L' Z! r
#include <NXOpen/SelectObject.hxx>; V9 C# c+ C6 T9 ^8 {
#include <NXOpen/SelectPointList.hxx>! b* J$ d1 R1 w1 n2 u+ s% I
#include <NXOpen/Session.hxx>
' e/ k4 Q% h! R4 a# N#include <NXOpen/Spline.hxx>
7 d9 X. k) T& a; X1 x#include <NXOpen/SplineCollection.hxx>
2 Q- E `+ o0 n8 |#include <NXOpen/TaggedObject.hxx>
' f* Y: K8 z, V3 Y+ \#include <NXOpen/Unit.hxx>- [) }3 t& |/ F0 S, c/ S
#include <NXOpen/UnitCollection.hxx>
+ q1 E5 S( x4 f6 p7 H5 m/ R' p#include <NXOpen/Update.hxx>, a0 ^/ }- f1 W/ ]( b7 r5 e
using namespace NXOpen;, R! Q& d D7 l7 D' R. U! ]1 ]! x
" X5 G0 S$ j+ p# x$ W+ I* Eextern "C" DllExport int ufusr_ask_unload()) U& v) J/ w1 z! |* e
{
: G8 p& h+ C/ { c, z6 z8 H return (int)Session::LibraryUnloadOptionImmediately;0 H: ~" |+ {' M5 `0 L$ v! L7 _. p
}+ T+ y3 N* a; S* T( O
) g. r' D: O3 t* h# L4 b: l( K
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
* ~6 y3 |4 c( S{
3 D# z A) B1 r) }' q! o& R6 n Session *theSession = Session::GetSession();
$ }( ^9 c) |2 y: |8 |6 U8 w9 e Part *workPart(theSession->Parts()->Work());
9 `+ b5 J3 O5 ] Part *displayPart(theSession->Parts()->Display());9 k- N" T& F7 Y# @! Q) A+ l
// ----------------------------------------------: p1 x* ~$ @. H) |5 p
// Menu: Edit->Curve->Divide...
' J2 t6 @, R% I // ----------------------------------------------. {2 z% F, ]7 {' u& A2 h* [
Session::UndoMarkId markId1;
- T; Y+ C( `" K2 o: Z5 q markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
- n9 K; X* [6 F6 K
5 W% k% ]; H$ p( |5 t Features::Feature *nullFeatures_Feature(NULL);& e" n B! r8 l G" b3 ~8 O
2 B6 m% _1 d8 D3 S5 }0 D, T: R
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
5 W. j3 @' D/ v' c {
* `. k+ Y+ ]7 q* t( e throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
( t: U. k- U8 }$ O" _ }
t3 X) a3 }. U" E0 [5 Q% f$ j: ]* f8 |! f+ |/ d- u) F
Features::DivideCurveBuilder *divideCurveBuilder1;
& X4 Y: R9 Q( s) l+ }' M divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
% t8 C: u* m1 Y. ]& K9 k3 [, ~/ z* N: q% \. g- j
Point3d origin1(0.0, 0.0, 0.0);
q5 d5 L, g7 F6 Z Vector3d normal1(0.0, 0.0, 1.0);
3 Z _4 e R0 c1 C Plane *plane1;
: ?/ U- a$ v" \- r- W! n" c2 F plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);! N3 f% Q3 K+ R$ I6 y
( C+ U: p6 l! L4 v1 I$ }
divideCurveBuilder1->SetBoundingPlane(plane1);
- w9 C2 O! p9 K+ V% O' x& v4 }. T' Z$ j1 x- C% I. I( ~9 P
Section *section1;
! I, E. ?. }( M; C section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
, B( A# G7 {0 V$ r- O
* J5 o h2 d2 t5 k. |; k5 ^ X Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
k! x" o# L" G4 B Expression *expression1;. ^6 I2 i- E1 d% _( m* b! P& O; T
expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
' r8 J& _' |7 m: U/ b/ C, g- q6 D, A6 D& J& k
Section *section2;7 L* v' J9 Q0 I' Q( x, ^9 a
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
% d7 G9 p8 ^3 J, v
( S5 s7 p5 E7 g3 R3 a, | Expression *expression2;& z0 ]9 n, `: Z! u7 X
expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
7 Q. B$ B( t+ K1 K2 Z7 o. k+ p3 ]+ y9 G
divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
. I5 t2 `/ E6 P0 @( j- s& s1 W
# K- k9 i5 h1 F/ U- [ divideCurveBuilder1->SetEqualParameterSegments(5);
& S) J7 L3 c. ?5 v4 p8 }
( r7 r; h2 h. _/ B8 H) r7 L divideCurveBuilder1->SetEqualArcLengthSegments(5);
2 N+ K8 _( C! q
' z v" p$ B& E! t; T& D) C4 o theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));) k" E2 b8 I' R( t1 V! N& g
0 ~: A) j5 U) x) P3 s
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
( g* D( a! Q/ W0 F
5 v* ~8 k% L6 ~& w Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
# u: ]' b) E T5 U) [6 Y" _( O; P Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
6 X$ w- r* x$ b9 h: e! N! v/ x divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);& N6 M1 X" {; t v* u
+ h2 v- b% k6 Z5 a; P4 l
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);! @. _$ @' @( ~* q$ h
+ M1 B+ _( f) G ?. ~# J Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
- x* f v1 G- {) {3 h Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
+ j3 I- @; B2 X+ `# J8 k8 C+ y Xform *nullXform(NULL);$ {7 `/ s2 W+ k. x2 n! {( b
Point *point3;8 J$ ]+ `3 [& v: f7 }4 M8 F
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);& K+ o: T2 P; t5 R* A& @
- H$ d4 j( K& j) l7 u divideCurveBuilder1->SetBoundingProjectPoint(point3);0 k) ] l" n. h! r9 U( h$ F
. {0 B+ l1 r, H. a. E3 | Session::UndoMarkId markId2;
- H4 m, |2 h5 t- w8 F$ ^1 j markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
; f/ |( _% l* C6 t: Q7 }8 @+ t" _6 Q3 l& T6 W& ^: G- g( M% \
NXObject *nXObject1;' G& m8 M4 e/ }" q8 {: B5 B1 X
nXObject1 = divideCurveBuilder1->Commit();
# w3 b6 \& t1 Y( }8 R: Y3 G2 m4 Y/ O; e- S' M: G C( j3 |$ @
std::vector<NXObject *> objects1;
5 B- ~6 C3 C; A5 ] objects1 = divideCurveBuilder1->GetCommittedObjects();
$ f. ?" @1 F$ r M$ Z: B6 e8 }5 ^- p; v. U$ ^
theSession->DeleteUndoMark(markId2, NULL);
2 f0 Q5 _6 T. z+ G* k! A" z2 L" E6 ~+ D( Q" L
theSession->SetUndoMarkName(markId1, "Divide Curve");( ?: I- @5 g6 z/ d4 s
( F% t6 T# w$ w
divideCurveBuilder1->Destroy();
4 a7 t$ k$ E$ b# {2 U1 q9 @1 D# w0 j* f1 {3 U; R, y/ I
try
# H+ U. ]8 E% b7 i' ^ {" ]8 ?& \4 I U" H, P( b
// 表达式仍然在使用中。( X: z( ]8 J8 h
workPart->Expressions()->Delete(expression2);
6 y0 ^0 p) C8 j/ J8 C* R3 c7 E& y7 c }+ `% R1 v5 P* g4 Y, E
catch (const NXException &ex)
8 R; p, C6 M: U+ r& @$ u8 ^ {
2 P3 [" R" ~2 b' X5 \3 M K8 ~6 q ex.AssertErrorCode(1050029);
* i; m h v# d: Q4 M }
4 D8 }6 {$ B8 b8 x* m; _: d( ]% H0 }
section2->Destroy();
9 d, p/ Y1 a @6 S" M+ R
~% T/ G8 {% S! k try
l4 H/ R7 C! s: x% w0 ~# M {
8 ]; L. I: L7 j( H v# s9 g2 h* Z, a8 u2 m // 表达式仍然在使用中。& q- F& f( ?8 i" C! w' l
workPart->Expressions()->Delete(expression1);) W: N8 O7 [4 |; x& W0 z
}
W& H/ _& _0 c8 n# F" a* n: x# b# V/ N catch (const NXException &ex)3 p% p& M) M9 E3 A. k
{
: ^0 ~+ ?0 |& {8 ] ex.AssertErrorCode(1050029); k# `# w0 w: ?' z8 d
}
3 @& q+ H, D+ a+ T9 e0 Y) W" H& J+ ]. N. N( a& @- _# `
section1->Destroy();
+ i4 Z* `% N, C4 w4 R+ e" U5 f$ R. F, Q. Q( x0 J9 U; K3 A- }5 w, M
plane1->DestroyPlane();
1 P$ [3 T) r' b+ Y4 w* O4 |$ s( m; G: ?: u
int nErrs1;
: q5 L- h4 `. l! Q nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);( D/ X3 h3 Y+ G4 u
8 n7 f7 d/ `; F+ `6 K9 } // ----------------------------------------------
$ ]% u6 I% l: p- \ // Menu: Tools->Journal->Stop Recording
1 ^) |6 Q+ \2 l4 K/ s$ @4 y // ----------------------------------------------: D$ J ]. t+ s+ \
}
% e$ o4 }" m, t
# E; j1 o/ \& _: [; V, N& Z
3 j+ x% I$ Z% A7 C/ t+ }4 Z1 r* k/ A" O) b" a. k ~3 S0 R
希望大神指点
% c, l3 |3 Z9 T8 ?# ] |
|