|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了
9 M+ j; w: B) A' `; h, v$ ?# K% F6 M, d% m. G
std::vector<NXObject *> objects1;- `3 v: i6 ]) ]/ L; n3 e* g' g! v# y
objects1 = divideCurveBuilder1->GeTCommittedObjects();
! d, O# x# E [
; h4 {. U3 q" l* j/ r! \1 r8 Y1 ] S3 E. d; h
$ \1 O- Q' ~9 a5 Q
完整代码如下:
! z4 l$ _: o/ X$ P2 ~4 |7 V, Q
: ]" T( Z9 E ]9 z* l// NX 7.5.0.32; h5 F. A3 [( E# ?1 _
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间- ] m4 S$ P0 A# X, F/ S
//
, Q- d8 |5 G) ?) j#include <uf_defs.h>7 p) b+ @3 Z+ ^8 k# l
#include <NXOpen/NXException.hxx>, F! @) }- N6 @
#include <NXOpen/Session.hxx>
v1 h3 R* h6 ^. c#include <NXOpen/Builder.hxx>
4 \, o. c! |1 I$ W! z, O#include <NXOpen/Direction.hxx>7 L( P$ q- g" F' U: J
#include <NXOpen/Expression.hxx>9 B8 h7 A0 D$ X1 O0 q' z
#include <NXOpen/ExpressionCollection.hxx>: u! j$ m) i) T3 r( J- Z" O
#include <NXOpen/Features_BaseFeatureCollection.hxx>, i/ }/ m4 J( f7 Q
#include <NXOpen/Features_DivideCurveBuilder.hxx>
$ `# ?. X9 ^2 |& R7 F4 O; m! q- N1 u#include <NXOpen/Features_FeatureCollection.hxx>
, M2 l: p4 ~6 v3 F* n) {( I& l#include <NXOpen/Features_PointFeature.hxx>
/ t8 f: V( h* n0 O#include <NXOpen/ModelingView.hxx>( `3 G3 M6 Z2 w2 {5 [ n
#include <NXOpen/ModelingViewCollection.hxx>" A4 g' x9 x# e
#include <NXOpen/NXObject.hxx>, S% C+ C9 G6 r1 l; S) ?
#include <NXOpen/Part.hxx>
9 u( g8 S/ ~2 j+ e# I#include <NXOpen/PartCollection.hxx>6 @+ ^1 g$ a; k% T
#include <NXOpen/Plane.hxx>
( b" n) s! z7 B9 J+ e* {#include <NXOpen/PlaneCollection.hxx>
0 _( N- `8 ~* m+ z# \6 f( ^5 U#include <NXOpen/Point.hxx>0 |( {' ^& w; x) k
#include <NXOpen/PointCollection.hxx>/ e" v# o: W) c7 {. n& o
#include <NXOpen/Preferences_PartModeling.hxx>
- f, W0 {4 e8 M' B#include <NXOpen/Preferences_PartPreferences.hxx>1 ]( Q6 A% @; S' ], k' e
#include <NXOpen/Section.hxx>
4 g6 o: o0 N9 V5 L# ~ E( [5 i: \/ h#include <NXOpen/SectionCollection.hxx>0 q" {5 Y) K8 U s$ ?
#include <NXOpen/SelectCurve.hxx> c1 O7 r* M& k$ m+ b( u' h2 r. U
#include <NXOpen/SelectObject.hxx>7 f# Q8 k9 k! s: P
#include <NXOpen/SelectPointList.hxx>" |7 `0 Y/ |% e: f: u8 V+ `1 y6 g
#include <NXOpen/Session.hxx>
& m/ `# }3 o: z7 \#include <NXOpen/Spline.hxx>& O2 Q# f6 T! i9 w7 q! ]
#include <NXOpen/SplineCollection.hxx>
* C0 X \5 T2 `#include <NXOpen/TaggedObject.hxx>6 J% O3 B2 e) [5 F8 R. h9 w
#include <NXOpen/Unit.hxx>
" b+ u: f$ w5 k+ P#include <NXOpen/UnitCollection.hxx>
$ @- K& F! \8 P; V. Z# _1 r#include <NXOpen/Update.hxx>" r% ?/ ~6 J% V7 y; T6 W+ f* R
using namespace NXOpen;7 w; v) V5 z, ^+ G. F
% G2 V( c9 A h9 j" t
extern "C" DllExport int ufusr_ask_unload()' e" G- c; h' C. l1 j
{$ i; V4 K; h6 ~9 Q) f f* R! T
return (int)Session::LibraryUnloadOptionImmediately;: ^. _& [- N+ j: W5 F7 S0 R# m5 |
}
1 S: h' t9 B. ^( ^
5 l+ e, H9 C3 w& k+ N, J& c, e: rextern "C" DllExport void ufusr(char *param, int *retCode, int paramLen), Z& [8 L9 M5 i7 U: W
{
9 m9 o4 `0 N4 w' ~, w* [ Session *theSession = Session::GetSession();) K' E, L J. o) c7 Q, W9 T4 e/ g/ m
Part *workPart(theSession->Parts()->Work());, E6 Y |- B. x1 n
Part *displayPart(theSession->Parts()->Display());
1 \/ d' f1 K3 A* |/ i- E( \+ c: K // ----------------------------------------------' T* a( d* R2 [
// Menu: Edit->Curve->Divide...
1 `4 E7 a2 E$ l- p // ----------------------------------------------
" N) M' Y' Y" d4 d7 n Session::UndoMarkId markId1;
: a7 A0 x8 W' i markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");% H1 ?8 Z- H) c1 ?( R6 U
# C, p4 V7 [4 }& C1 N+ u Features::Feature *nullFeatures_Feature(NULL);
o( ~ [$ k' K/ P! a# l( D7 D% G& F/ V. V
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
5 U5 c5 k3 [) T/ |* D5 H8 u1 j1 ` {# i5 n3 |: P& e+ e$ m f0 T$ B9 [
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");5 f7 }9 C- P/ ?2 B2 o% p. M" i+ ~! t
}
+ _" b( |5 T) s4 L% [/ ^+ x# |* U
1 x( T6 @- B* K2 U i) ^ Features::DivideCurveBuilder *divideCurveBuilder1;) V6 W: @% o; a2 ?1 d+ }& b) b
divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
. G- ]* h& `2 K& Q+ }7 n4 i" ]/ H/ V( k g
Point3d origin1(0.0, 0.0, 0.0);
, Q8 t1 D8 @9 ` b% v Vector3d normal1(0.0, 0.0, 1.0);
" d9 S, f2 G7 {8 G6 N! \# ` m Plane *plane1;
5 w; H6 {9 Z" {4 b7 E1 B plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
6 S) Y- m6 X$ L( _) }! ^; Z. a1 o/ h; u$ M3 [: Q2 D9 T' x6 L
divideCurveBuilder1->SetBoundingPlane(plane1);. L) j t/ s$ G
) u4 D: \8 V9 G+ h8 v Section *section1;
& _3 o" K0 s8 U6 T# V6 I section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
. E# e: J' C9 a& p9 v4 U/ c5 }" G1 N' F7 R* X
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
1 r1 V4 G4 H/ {" F( F4 K Expression *expression1;& {1 R0 Z" V, b! k
expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);4 g5 M; O6 d$ i
4 {* a' e6 \7 g5 E4 O, R Section *section2;
. F7 Q+ Q9 r+ v) b, P' o" e section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);7 E/ E. Y' Q; l4 f8 j
5 [" e. o8 M! T" e E& b Expression *expression2;! | b4 d- B' e0 S" [
expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
: h$ G4 l3 m1 c6 W6 K
& J2 j2 k/ O7 @' x9 A; v/ r8 | divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
) n: k; Q: v' T( e3 w2 j" O5 F* D8 V6 |: w
divideCurveBuilder1->SetEqualParameterSegments(5);
q9 o4 v2 W( l* q- v9 }7 Z- a
0 X H* G4 t! W7 U divideCurveBuilder1->SetEqualArcLengthSegments(5);
1 _7 S" o/ b/ b g" x* W2 g" Y, c* U
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));% W5 @; M" j7 r6 Z' S- J0 K
$ f7 \4 i0 P: I* L0 A
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);3 W! g3 {4 l" b1 T
4 B1 v w! {* I: m" S( s8 B$ N+ e/ s. {
Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));: w* [. z. Q3 v, t
Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
+ v0 X" b" @* u! _ }9 }% N$ G divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);
6 K0 R2 O- v0 G! V$ o" g
8 O* F: x+ O' X5 m: _9 n5 Y divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);
2 N1 I; D* r! {7 Q5 `8 F
+ i. t0 X1 r/ t! H2 ~" Z0 B Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
0 Y% G P* m. L6 b( q% Y Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
% F9 f3 _3 I8 V0 c: o# T: S) o Xform *nullXform(NULL);
( f, K; {- [4 y Point *point3;
2 }. h0 J% p1 V' e$ I$ W point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
# s' ^% @. C+ q
4 i8 I& A2 q6 u divideCurveBuilder1->SetBoundingProjectPoint(point3);9 [( V1 E/ ]6 i& _' ^4 d H
5 G7 p* o- ~; b; H& r3 {$ k3 W
Session::UndoMarkId markId2;
& b& g: F7 Q: o& T, N. `/ ^ markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");# ~- T6 S6 R: B* L0 E1 @
) w0 J7 c+ K" D# ?" {; P5 \ NXObject *nXObject1;
: A) Q: J$ w" K& A0 e- h2 c6 f* g nXObject1 = divideCurveBuilder1->Commit();
2 V4 A% |/ e# z% t1 l/ F8 D1 d m. _# y
std::vector<NXObject *> objects1;
5 J! I0 o! ]8 t objects1 = divideCurveBuilder1->GetCommittedObjects();) k+ O$ X: v4 j% o
7 p6 w, ]: }7 D" W
theSession->DeleteUndoMark(markId2, NULL);
4 ]( R- C; _# U' _+ _" l' d$ b; D! L& r
theSession->SetUndoMarkName(markId1, "Divide Curve");; x' J, O% M% S4 @4 ]$ c6 m" i
5 d9 `8 X: S4 B5 f% \
divideCurveBuilder1->Destroy();
6 J* D: K& `+ s6 }5 n5 j3 ?" V5 q o1 q( D% M, v7 F! l0 u
try
+ [; q6 w6 S+ k0 W' t& Y1 s {4 S+ Y; S& T0 t8 Z8 M
// 表达式仍然在使用中。
+ c# Z% o7 f, E' W! p workPart->Expressions()->Delete(expression2);
4 G( P6 S) H. [ }
5 o$ q# Y! x& _# Y catch (const NXException &ex)$ Z) ~5 M" `- w9 N5 F9 q
{
" @6 {+ A; Y5 d$ W. O ex.AssertErrorCode(1050029);" E4 P* z" s% O; G
}
7 x9 ~ Q) I# a5 x7 k0 z% Z! R8 r! R" ^. {
section2->Destroy();
7 |0 Z5 Z( {. A" z
( ~2 s( N0 j3 D3 C. _; m6 i try* P0 [, C7 p) X. t
{
7 S8 U- k- Q& ]1 Q // 表达式仍然在使用中。
2 e0 o5 O9 e% }+ E8 H: ?. j+ U4 u workPart->Expressions()->Delete(expression1);
, W3 P& R- P$ I4 v$ J k0 K }
B8 S( o# W. j$ ]* E catch (const NXException &ex)
' P/ f. P% O F7 \ {
# R- @+ X* R% S5 P2 g( k ex.AssertErrorCode(1050029);/ W u% t8 J2 y6 V( y' o$ c" b1 l
}# p- y% R; F7 u( _9 s1 b" Y( u
% g# m2 _- A- X4 n- Y section1->Destroy();/ Y- m: `: U! e4 |: \ b. b
9 T1 B& @5 X# Y @ plane1->DestroyPlane();
4 b# J3 @2 G+ I. m& P3 F: P& G0 a$ x$ O' z& |1 t, U) e. V
int nErrs1;* A3 n1 k5 c$ h& `( m
nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
7 v$ B5 _: n- b5 w) I* o: i
$ W( A1 x1 @! | // ----------------------------------------------
& t) ~% Y# T# G, H! z) d7 W/ y // Menu: Tools->Journal->Stop Recording* q* k- |, {: w8 k D. h
// ----------------------------------------------( ]/ [$ G; t3 b f9 P( m; g) S
}* e9 `& U/ l* I2 J8 E+ F/ l
; z5 q: I M; L" _6 i$ t9 e' v; ~
1 P6 L7 n4 p& Y1 b7 Q/ K8 V
, T% j) n6 j; ?% o" ^) b2 H9 O希望大神指点6 L+ w5 B: `# ]! K2 L
|
|