|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了. }" S5 R" J* @; b. I
2 e* S1 `2 u7 J/ q: {/ a" B; Q std::vector<NXObject *> objects1;
! b$ _& D5 ]* e4 z, I1 t objects1 = divideCurveBuilder1->GeTCommittedObjects();
# u- ? ]9 `. W, d7 e' t& Y
' L6 X/ P: `! }
, P! h$ G: k) O8 a1 E
$ @: {4 ^- W$ p1 H" Q1 v1 {2 P0 r完整代码如下:
" S" A$ j4 n3 @! U9 f9 Y4 D4 M
1 e4 E" T# u0 A4 j0 ^! b! b2 ~1 i// NX 7.5.0.32# U' _& P# @, t9 N# K: i1 Y" V
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间( L& r: N2 ^2 |1 Q" t7 @3 ]
//
% d' x1 A9 {7 a( @! ?4 D#include <uf_defs.h>2 F$ {0 D. v1 u
#include <NXOpen/NXException.hxx> U+ Q; J. D" {/ N) m
#include <NXOpen/Session.hxx>
1 X& D0 d! c, z) O2 q1 c#include <NXOpen/Builder.hxx>
" a! g" j1 E$ Q5 } E ^1 A#include <NXOpen/Direction.hxx>
7 z+ s" s7 B$ {' ^#include <NXOpen/Expression.hxx>
! f' v8 M0 v2 }# Y4 P#include <NXOpen/ExpressionCollection.hxx>
; t4 p* _/ C' k3 r0 H5 j7 k+ w/ L#include <NXOpen/Features_BaseFeatureCollection.hxx>
* N# p4 V7 J& X#include <NXOpen/Features_DivideCurveBuilder.hxx>
) S# {, Z! f" \+ H S/ z0 }#include <NXOpen/Features_FeatureCollection.hxx>
, S- X' F3 E8 z8 _% A5 {3 G#include <NXOpen/Features_PointFeature.hxx>
' M6 f8 D6 _6 {5 T( k" ^#include <NXOpen/ModelingView.hxx>" r+ o/ w( E; X
#include <NXOpen/ModelingViewCollection.hxx>5 f P; n/ W0 H4 A' H
#include <NXOpen/NXObject.hxx>( j0 \& D' p4 e5 r" }; z9 s
#include <NXOpen/Part.hxx>9 X7 G" p2 o r/ P; h) ?
#include <NXOpen/PartCollection.hxx>
* u+ F1 e$ B0 n$ a+ j/ {; U( @#include <NXOpen/Plane.hxx>
. ^) g- k K$ C C#include <NXOpen/PlaneCollection.hxx>
& }% B) r( Q5 M! G# q8 q#include <NXOpen/Point.hxx>
7 ?1 g4 V; e2 y- c# {#include <NXOpen/PointCollection.hxx>5 ^- L& d. Y" Y6 ?1 i: G8 J
#include <NXOpen/Preferences_PartModeling.hxx>$ b+ s, P0 q) x; ^' \% @+ S8 W
#include <NXOpen/Preferences_PartPreferences.hxx>7 Z% b3 O7 Z& S! m1 A, H8 y6 o! z
#include <NXOpen/Section.hxx>
& o/ I5 o5 N& _- {. y5 X6 D+ o; _( z#include <NXOpen/SectionCollection.hxx>* E' l* V0 J# E+ f) b
#include <NXOpen/SelectCurve.hxx>
/ w; q$ O1 }0 L5 B" D2 d#include <NXOpen/SelectObject.hxx>
4 H( [& C+ M/ q$ ? W7 Q. T: N& c7 J#include <NXOpen/SelectPointList.hxx>" ~, L4 Q, N& P0 m0 y
#include <NXOpen/Session.hxx>7 m$ W9 b: k4 u6 l% T- b+ W, M/ t% ~. e% n
#include <NXOpen/Spline.hxx>
. h2 m T+ W7 N+ x4 O#include <NXOpen/SplineCollection.hxx>% B: B I. J6 T1 D0 w5 c6 ?4 b2 s1 `
#include <NXOpen/TaggedObject.hxx>
4 A8 a* i8 O1 m% D/ Z#include <NXOpen/Unit.hxx>
3 u7 T* R5 @" W8 `8 o: q8 t#include <NXOpen/UnitCollection.hxx>
4 F' B# `% @7 ?+ Y, @) z- \#include <NXOpen/Update.hxx>
( G. N1 r' p+ z7 pusing namespace NXOpen;; y6 X3 w. {- _# e
" H x; I2 M& Oextern "C" DllExport int ufusr_ask_unload()/ V( i3 V2 V( b$ j/ z- @8 z8 ]) l
{
. Z5 ^" \1 S: y7 B return (int)Session::LibraryUnloadOptionImmediately;! i+ j6 T. T: }7 j9 [
}/ }6 R9 W. ~/ p
& b8 g. M" N( R) s4 i j, dextern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)2 b8 N$ J' ?% t" d. O% O5 E
{, z0 s o! ~7 F& ^) K }2 P
Session *theSession = Session::GetSession();+ ]" i- |, D: S: a; C
Part *workPart(theSession->Parts()->Work());: R I$ H" s4 E1 c8 Z5 `- I# k% l
Part *displayPart(theSession->Parts()->Display());
2 I5 @$ i- Z _% b, g7 |5 [4 V9 a // ----------------------------------------------- v% Q5 b. X" x0 u* [. p
// Menu: Edit->Curve->Divide...
8 i9 w# Y+ Y0 e& a7 g. v // ----------------------------------------------
0 M3 Y0 r, u' f4 G. @ Session::UndoMarkId markId1;
6 t+ r: J/ ~) b1 y. z* k markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");. d# W4 k0 z9 L! z F9 t+ [
. S+ I' k( L$ @" M7 v7 u7 S% o Features::Feature *nullFeatures_Feature(NULL);4 T0 O1 V$ M: r6 d4 u G* L: [) d, O
% K! b" p' G% W. |5 h2 U0 W
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )5 w" W$ g& Q$ C8 ~
{
0 P h9 H. G5 r( O throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");. W R) ?- q) b: O
}
$ j- L- m3 K, _6 l# \* w+ Q5 p- H
Features::DivideCurveBuilder *divideCurveBuilder1;9 T I3 N0 ~, A
divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
: e9 x3 Q( i* N# n/ w* I+ ?1 R1 f
Point3d origin1(0.0, 0.0, 0.0);
/ `# k( z) r, o8 d% b% A1 A Vector3d normal1(0.0, 0.0, 1.0);
- c1 s" r4 f3 E" {8 B( R8 l Plane *plane1;6 l. `4 y9 K! D, W! a% l
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
& V) {- t3 V% ?( ?* I
% c' I, U* Z; s- y divideCurveBuilder1->SetBoundingPlane(plane1);
$ x4 H; s- ]; F2 w8 R) L# H0 K
@; a5 \9 o G: G: K. D/ X Section *section1;
* x& M1 m2 W0 `0 k section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);4 B1 G* p: d- H/ p9 s+ [0 `5 h& \# Q
: G$ j2 K8 `/ {2 i8 P& o Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
% z9 z% Q# |' d H( Q Expression *expression1;
^ P/ E, S% {6 t1 t) k; x6 v+ a* _! l expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);) f% Y# P5 N- F) e f1 I; X. y
7 r$ t! g6 i2 U& d \* i6 k/ W5 E5 C
Section *section2;
* h( S# c Z8 Z section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
; q8 [- G1 u8 P9 u- Q* v# z4 {! e @( M
Expression *expression2;
' B$ T; _7 n5 d8 b3 _: c expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
- a8 i0 M& H0 s4 i. s( R' d
- g: x) u4 b6 b; H! [ divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);( ^: y6 [6 B( V5 F
. ?" E4 {- l; @/ n- Z F) I divideCurveBuilder1->SetEqualParameterSegments(5);4 i- y- Z Q6 E5 k' L
. p4 A2 `' G6 t7 m1 B7 L7 N
divideCurveBuilder1->SetEqualArcLengthSegments(5);3 u- o7 y9 ?( a9 G3 o0 E$ b, _
6 e& W- X' }0 T
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));; F h' i5 A' T# h
3 ^6 h* e( B/ N5 J: G
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);4 d! g2 _6 o( @0 A
/ h6 w6 `# ]; ^8 G( c8 l" I7 Q/ ?: g Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
6 y0 w, x# |* z7 n! o7 R Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);4 m. V$ ]5 F9 _/ a2 e4 v
divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1); B; n! I4 t+ L
1 z. Y* v; {) x0 y' o3 S divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);1 T Z+ ] `" L
9 H# |. w" z" H* Q, C Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));0 `1 k$ s1 A. r+ N4 t/ o4 U+ b9 [; q; J
Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));0 D9 G1 ]3 q$ V+ x$ Z+ q7 p* ^/ R
Xform *nullXform(NULL);8 [7 l: o1 \% T, w: Q
Point *point3;
Y' Z( j$ K! g/ ?4 n( M4 T. L" f point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);6 s& B; e/ r7 ]6 O) E
1 u0 H* d0 o! p* t: g$ v9 W divideCurveBuilder1->SetBoundingProjectPoint(point3);
[- ?0 C. y$ T' j$ \ r7 X0 o0 R2 ^5 f" x- m8 u$ M
Session::UndoMarkId markId2;
* K# D9 C- k8 z9 O markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");5 h( I" D9 _5 ?* x) K2 l& K. s0 G
+ m e$ g( }: j$ u6 W NXObject *nXObject1;5 O" q8 W/ _, E. v9 _
nXObject1 = divideCurveBuilder1->Commit();3 Z# L# P1 F& y6 k8 l! B7 D* l+ A: b3 K
' L$ {" B6 l' ]# p' R* n
std::vector<NXObject *> objects1;* Q5 f* M- J0 Z8 M1 A$ V
objects1 = divideCurveBuilder1->GetCommittedObjects();
/ {; f& p- N! d, P0 Q4 i% C4 q' u5 e/ L
theSession->DeleteUndoMark(markId2, NULL);
, N+ V! y4 F/ `0 n8 I6 _ N5 C( a# {: P6 a1 @2 `
theSession->SetUndoMarkName(markId1, "Divide Curve");
. a0 ]2 W0 p R* K2 p3 l5 S5 ~1 l+ s; N5 e% j% [
divideCurveBuilder1->Destroy();3 e' d# `0 X% C" p+ \! d9 n3 @
% a* ~ a2 R0 k. L5 ]
try6 \/ ]& p2 A. @' W
{8 f+ ]# C$ X' z: ^1 M
// 表达式仍然在使用中。8 o+ u# B9 r: ]& T4 B
workPart->Expressions()->Delete(expression2);0 p# y4 h) Q9 D+ u, \
}+ b, T& {6 z+ g! w- t
catch (const NXException &ex)
1 h3 x' c! t. h- E c {: c/ e! ~& g- z% r: w, p# {- S
ex.AssertErrorCode(1050029);# L; {1 e( O, m- \) l4 f7 p
}
- b' ^3 _2 C3 \# W* q5 n, G
6 |: t4 C5 x9 j; C6 p4 E# ~) d section2->Destroy();. o6 B/ c; d D w F A# |
5 C @% Z* P- E& b& y* ?' k2 n$ P
try
0 Z6 ^* A4 `( Y; f* i+ c% g- C* b: Z {
0 f9 n4 Z3 T. f" m8 s // 表达式仍然在使用中。
0 j& s& d" a' G! x3 M workPart->Expressions()->Delete(expression1);. l! k b& O6 T1 r; u
}2 Z+ X9 h* I4 l X4 d$ J, Z5 j
catch (const NXException &ex)$ A- o. h, O1 i g
{
}, m# F# ^1 R* k' X# K ex.AssertErrorCode(1050029);
; t; g6 q7 H" }- M }3 |0 g$ d+ C; P, j4 j# i& R& x
3 F; U u6 e8 C! E& a g1 x section1->Destroy();
9 F% ~ b0 V7 K- r# h$ W }% @4 e, ^
plane1->DestroyPlane();0 u$ c7 d) M- B e5 \% g' q
x0 d3 }$ U+ ~8 ~, J' j4 M
int nErrs1;
- {7 ] [# v7 u; i+ y nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
8 ~% f7 `, x$ H! F5 a- R
- j2 k! _+ p; z" D; d( V4 a // ----------------------------------------------: y1 m; W9 x z, \+ n1 W+ j
// Menu: Tools->Journal->Stop Recording: q# f; J! i1 i- K
// ----------------------------------------------& t2 k/ `' V4 s: [' d/ \
}
/ ^' K# L! E# V# R- a: }0 Y6 i* s$ Q# \* A1 s4 a* _' Q! l0 n
( A& ^. C" f8 q& }/ u6 i% {" L
/ n: O6 U+ A7 L3 v/ S希望大神指点
/ |% r j# x. M; F$ q V7 q8 k" ` |
|