|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了
5 A, I+ O, j* y+ N1 Y7 q$ _9 e, x" J8 G4 l0 q
std::vector<NXObject *> objects1;
( ^1 B9 T: }, |! u; O objects1 = divideCurveBuilder1->GeTCommittedObjects();0 r, Y8 p! G+ W$ P# Z/ x% S
. M+ F g9 w6 B3 Q7 E! F$ l; s6 I$ Y$ |$ x) j! R9 o9 z, B1 {) F% N
|0 m& k2 B7 I! x) t$ d" k9 K完整代码如下:
+ S2 }, v; x2 Z; \: v. ^, B/ @- f, @
// NX 7.5.0.32
4 q/ ^, F: R% I// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间/ _; o) X( ?% }: w M4 ^& @
//
7 {# F2 N2 V" w5 Q9 u3 i#include <uf_defs.h>, Q! Y5 `% T* b8 O) \; E$ J2 }
#include <NXOpen/NXException.hxx>
0 V) c3 _. l1 j4 U9 v8 C# D#include <NXOpen/Session.hxx>4 J' V$ G' p( U* z2 W6 P
#include <NXOpen/Builder.hxx>0 F" |; P8 X( I) s- ]8 @' i, m
#include <NXOpen/Direction.hxx>& U( S% i% V5 ?( S1 o- W* C! I; D
#include <NXOpen/Expression.hxx>
% O0 [. T2 p; _! `9 c) f* A$ x#include <NXOpen/ExpressionCollection.hxx>; n( V1 j- s$ B2 E: ~
#include <NXOpen/Features_BaseFeatureCollection.hxx>
, q9 h3 k4 [- |' @; [#include <NXOpen/Features_DivideCurveBuilder.hxx>
) A8 w* n9 R! C+ p! d! V#include <NXOpen/Features_FeatureCollection.hxx>
8 X5 }& ^' e: i+ D#include <NXOpen/Features_PointFeature.hxx>: D- O. Q/ C7 Y# E# k s! K
#include <NXOpen/ModelingView.hxx> d0 {# K' ~) h! X( j/ h
#include <NXOpen/ModelingViewCollection.hxx>
3 n% e) u, q3 T! Q#include <NXOpen/NXObject.hxx>. q3 [7 ~; |/ d" n6 z; o; e
#include <NXOpen/Part.hxx>
3 ^$ A& T$ W3 K#include <NXOpen/PartCollection.hxx>( Y6 c/ s2 W$ T, }
#include <NXOpen/Plane.hxx>
: l2 W* H7 R$ d+ _8 ^! M#include <NXOpen/PlaneCollection.hxx>) g5 ~/ f0 p! M! g. z- \
#include <NXOpen/Point.hxx>
; p7 D6 I4 p% s3 D9 [* ^#include <NXOpen/PointCollection.hxx>
, O1 _8 e1 E. ~9 R& `5 ~8 w3 {' r#include <NXOpen/Preferences_PartModeling.hxx>
+ ~& _1 h0 O$ D#include <NXOpen/Preferences_PartPreferences.hxx>; ?1 w1 r) s# ~2 _, j" t3 V1 c
#include <NXOpen/Section.hxx>5 q' |' }) [5 Q3 N0 g g
#include <NXOpen/SectionCollection.hxx>
6 O7 a5 v' P% g5 G0 P) X#include <NXOpen/SelectCurve.hxx>
/ D: T2 y& e' z( q, T#include <NXOpen/SelectObject.hxx>
/ W" P+ c( O+ x' k#include <NXOpen/SelectPointList.hxx>3 c u, n! n2 G# a8 o& V
#include <NXOpen/Session.hxx>
; U" F- {& D$ W* a#include <NXOpen/Spline.hxx>8 E9 Y/ v/ C3 f, A
#include <NXOpen/SplineCollection.hxx>* P% n' ~% t+ |) M8 ?
#include <NXOpen/TaggedObject.hxx>/ h0 m8 E+ [0 x& Z0 _) P
#include <NXOpen/Unit.hxx>
9 u2 ~& q6 _; v: g9 e8 i#include <NXOpen/UnitCollection.hxx>
" {* P5 U3 t0 ~% U) H4 w2 D#include <NXOpen/Update.hxx>0 }/ ~0 _$ X( H7 e* H' W
using namespace NXOpen;
: O: e3 @9 G' e/ `6 Q" Q9 \3 k/ ] M/ b
extern "C" DllExport int ufusr_ask_unload()
1 y: d& L& K8 v0 f3 @{" g* ]$ r* \# g! q$ v
return (int)Session::LibraryUnloadOptionImmediately;
0 c1 {6 o' Y# F4 x}5 }4 \" ~8 v6 U R
: J0 A2 Q$ G' e& U' z
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)4 r; q0 w) x: @/ d
{
, U/ W5 C: G! s! y( i0 ^ Session *theSession = Session::GetSession();$ h! g5 B1 x9 p
Part *workPart(theSession->Parts()->Work());& B% A Y0 V( e+ p
Part *displayPart(theSession->Parts()->Display());) p$ I/ g& p* x8 A! c0 d
// ----------------------------------------------, K8 \/ W" c& b/ j
// Menu: Edit->Curve->Divide...( `% [2 I; n ~$ M* ^# C& Z1 [" e: b
// ----------------------------------------------
+ x& B8 M9 z F/ ]/ z: ]+ x Session::UndoMarkId markId1;: w+ |8 b8 z" S1 K! k
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");. L4 n& M% v5 L* u; R" D
2 ?' r; O" \* {0 O" L7 D- h. B3 O. @
Features::Feature *nullFeatures_Feature(NULL);, O6 Q6 x4 z/ ^* ^; P
, l) j5 n, n! n if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )/ m8 H+ d/ b9 b3 S4 x
{
( J l% X/ v' g0 z8 f throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
( z8 T7 o- b ^3 B2 B }
5 Z# C8 u3 U1 ?1 K4 y! h9 q
1 e9 }7 e! k. z) l9 Y- Y) j Features::DivideCurveBuilder *divideCurveBuilder1;
" I* {3 s8 a( t" \ divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);5 s4 R$ F8 d) g H! E
/ V/ v6 |3 x$ O2 |$ r! H* m4 M( h9 ] Point3d origin1(0.0, 0.0, 0.0);
- ?. y @9 j* A1 ~: C Vector3d normal1(0.0, 0.0, 1.0);( E2 _ Y" Y. S( w. `+ @
Plane *plane1;" @: f: x+ _1 Z" J
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
1 g! _' `! L! C& B0 {( p# Z# _
% q L$ |3 i8 G! Q% k divideCurveBuilder1->SetBoundingPlane(plane1);* C/ R$ ^0 k2 r& Q2 S! U, B' _
) r- e/ U/ s4 e. X1 t3 a9 j Section *section1;+ Q# n& L1 g+ W3 }
section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
% J! P l. q- d4 I8 o: V3 c2 l" L% Z! ^/ Q: Q- j
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));) `: |( w- A7 k
Expression *expression1;
# }2 t9 l; x+ `- K9 s. Q expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
# \- C5 e7 f# f: e% u
; ?, k$ Z4 q: y* G D, B" R Section *section2;* E9 H, l+ g/ i0 R
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);6 }, B w( l' g9 p+ [7 w
& J- l1 n+ U# d Expression *expression2;1 M* ]3 k# f4 z! [+ j
expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
, s# y2 O! y8 O0 m* Y! A6 i: O( V, k' u7 B( r, U
divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);3 B' p. y/ }% t& P
% x6 l7 K0 O0 v( w" p& n n+ W7 P
divideCurveBuilder1->SetEqualParameterSegments(5);
$ s0 a$ @8 u3 k3 M; \' |5 z5 m0 z# Y) I( q
divideCurveBuilder1->SetEqualArcLengthSegments(5);7 k" r0 ~5 e: ?8 a6 F0 P0 w
' Q' R# K, \4 G9 T" u
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
; ]0 w7 _: X3 V+ \ b- H3 _7 X5 n& k- ~- l& E. T8 ^' G, z J1 [( Z& ?
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);( l+ R, v+ c7 E& |2 [
' [7 G/ W+ L6 T, N Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
. v2 o* y9 h9 i3 E/ L: Z4 y Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
( h( s& ?( C( M8 H9 L9 V" c divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);
1 d( ]# O, @9 \: \# a# _- y2 \8 o
0 o+ u0 g* z/ n6 s divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);8 W8 x! x) U1 E) Z( j" L
v- L# g9 U7 t% p; R" v
Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
+ x( }* O8 ^% B) P Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
3 j2 U2 x: ?6 X. D Xform *nullXform(NULL);% I. w& P% a" u' b( j! q
Point *point3;7 q6 ]4 a: `: u5 x
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);" N z: Y1 D1 U% E* a
4 g* b- e- n; u/ j( s
divideCurveBuilder1->SetBoundingProjectPoint(point3);
* e9 L% Q. l3 o. S5 k
' d( R8 B6 v7 `" F5 [ Session::UndoMarkId markId2;6 j. Z; K' g2 D+ J9 L* Q
markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");+ @+ t8 w/ O' W$ d( T2 l7 I
2 m- c8 \. u# I9 ]+ j! ?; _! U NXObject *nXObject1;8 `7 J# @0 c; W( C
nXObject1 = divideCurveBuilder1->Commit();; Q) i/ G; C7 J: b9 M. A0 n
' c/ W/ f) @; [- V8 ]0 x std::vector<NXObject *> objects1;
3 P2 ]! S; i7 T2 p5 ?9 `! K objects1 = divideCurveBuilder1->GetCommittedObjects();+ J; @. e+ _2 Q5 e$ T$ H0 l
7 r, ]) a( S* u# w( }6 H K
theSession->DeleteUndoMark(markId2, NULL);8 Q( c1 |) s- S% ]' t
) l7 L; M! C3 t% M9 z theSession->SetUndoMarkName(markId1, "Divide Curve");- Y# N6 n8 A2 y
5 @( K8 e3 u( q5 d# s" C, s divideCurveBuilder1->Destroy();7 N1 Y9 u+ ]3 O
. f3 h- B: A& @! A# V try
2 @/ l* i j0 ~ {
( b* s* Z7 h1 r // 表达式仍然在使用中。
8 n9 P. v* O& A% `! _ workPart->Expressions()->Delete(expression2);+ b" W" c8 b" z5 p4 v, C9 {% ?$ h
}
* h w; Y: G1 W) I& d catch (const NXException &ex)2 ?* o4 p' b3 z8 W$ {
{
2 d$ A# B8 k* i ~8 o+ V& H8 D ex.AssertErrorCode(1050029);
& Q! F# M* Q2 x5 D; ^* ^7 |- q- l }# ^! P, F4 C0 b% K& d
- e! w1 a+ ], f$ I( C
section2->Destroy();
! |, L6 z. c+ G& M- b1 j( M8 Z& a4 O( Q5 ^
try
! K7 v0 e" Q6 Y {
2 G0 n, k; d/ w+ P2 O: | // 表达式仍然在使用中。
5 T8 ^# v5 Z- Y3 Y) J5 m workPart->Expressions()->Delete(expression1);
, ?* ^" D# {7 A/ ` }! U& y. a$ F6 U' l! q7 X
catch (const NXException &ex)
* Z9 ?# G$ K$ Y) x3 S, q' @ {3 s$ z. y- G3 L5 x4 Y+ g
ex.AssertErrorCode(1050029);
* U5 S" o6 s5 K& O }
3 B" S6 Z0 `) j5 C6 l; Y; @. P3 N
section1->Destroy();
. Q) i! s( r- @8 |
) Q' { A( O U9 c$ F plane1->DestroyPlane();0 a: |# T: N& U3 \# b! w
( _' \* c5 N0 [ int nErrs1;
8 \" n* I; S; X, p: f4 u9 X1 E; l nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
! Y" d& t( {* W, G( M9 J3 y8 M4 ^) q, }9 T* V3 P! y
// ----------------------------------------------
2 X; h. z: \/ S) a& _, z; C // Menu: Tools->Journal->Stop Recording9 s% r/ [4 k- k1 ~& X
// ----------------------------------------------
2 v# Z _$ S+ R0 j+ r$ Z4 q# J) c}
. `1 w ?: ~+ F) z$ E# Y8 T, i+ l) O$ a* k0 O. D! ?
: E E: e7 r }
; c5 _: I# ]5 t B
希望大神指点
* o/ ?1 R7 T) n: J. |" D |
|