|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了3 m) x4 w8 c& T: n
" f0 D: v. D% v. G5 [
std::vector<NXObject *> objects1;3 G+ W8 P% Y: z8 d
objects1 = divideCurveBuilder1->GeTCommittedObjects();: V) D H$ l' }( U: w8 n: E
( H3 M- s. S2 \% j, T1 F% F
' s: u9 \. z. @
+ N! Z. s( h4 X: p; M4 b0 Q完整代码如下:
$ Y6 ]6 v2 E* ~3 e5 O/ a" G' e+ y3 I- Y
// NX 7.5.0.32
i) ^! W+ P, G// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
4 _- t( G! }- v//: @1 ?" w. |: d" N
#include <uf_defs.h>5 f$ g _1 G8 U; M& r, ^
#include <NXOpen/NXException.hxx>
, G7 \% j/ a; Y/ `; s#include <NXOpen/Session.hxx>
Z/ @, f. y6 x) w#include <NXOpen/Builder.hxx>) y" D4 y. O7 R
#include <NXOpen/Direction.hxx>
+ W! J% i4 ~6 J7 s; G- ?#include <NXOpen/Expression.hxx>) @+ k) i7 d# d/ Y0 ~; ^ R7 [
#include <NXOpen/ExpressionCollection.hxx>
M! k ^; G' @0 R: T#include <NXOpen/Features_BaseFeatureCollection.hxx>
, Z6 c$ L5 x, O( w& B% a% ]#include <NXOpen/Features_DivideCurveBuilder.hxx>
! B" U1 g$ A1 a" X' Y#include <NXOpen/Features_FeatureCollection.hxx>: p; H; M4 w; v, V" b$ q
#include <NXOpen/Features_PointFeature.hxx>* H" F0 [ u Q7 `4 j3 ~* F* s$ b
#include <NXOpen/ModelingView.hxx>
% g; r6 |5 k& |9 E% P#include <NXOpen/ModelingViewCollection.hxx>
) P9 o! N6 p' a( g, o5 P#include <NXOpen/NXObject.hxx>: k8 ~, I5 ]+ A5 ~
#include <NXOpen/Part.hxx>' `4 j& F6 t" I- w
#include <NXOpen/PartCollection.hxx>5 @% h9 K- {; I9 V
#include <NXOpen/Plane.hxx>
# H* h, a' M8 _1 E; Q: y#include <NXOpen/PlaneCollection.hxx>2 N- l" h2 [+ m" k2 j$ H
#include <NXOpen/Point.hxx>
. o, Y0 P- j l- A#include <NXOpen/PointCollection.hxx>- X9 {4 \3 Y9 G% g& \
#include <NXOpen/Preferences_PartModeling.hxx>, U+ L4 Z& \+ _: D# ]/ y
#include <NXOpen/Preferences_PartPreferences.hxx>
+ L d- s ^) a& W7 u9 f; s3 H" ?. [#include <NXOpen/Section.hxx>
' f7 |4 y+ ]9 Z2 H- f#include <NXOpen/SectionCollection.hxx>
$ t/ N6 F( Y) t) v5 n, {0 l& ?#include <NXOpen/SelectCurve.hxx>
- S9 q9 `3 r7 L#include <NXOpen/SelectObject.hxx>
; X7 r1 U& O. o: S5 M#include <NXOpen/SelectPointList.hxx>
+ N0 r& J4 X; V- |6 e#include <NXOpen/Session.hxx>9 w- J% m% @$ l3 a- G0 W/ s
#include <NXOpen/Spline.hxx>
" v8 T) D3 J5 \8 P3 c F#include <NXOpen/SplineCollection.hxx>/ ~0 k6 j D1 Z+ |, m
#include <NXOpen/TaggedObject.hxx>6 `- b' a, ]* c3 \% `2 a
#include <NXOpen/Unit.hxx>
5 H2 |5 M& w- h3 s/ P+ R4 _#include <NXOpen/UnitCollection.hxx>
4 v9 W7 ^9 e# p% T* d4 e7 u4 F#include <NXOpen/Update.hxx>7 k+ m, D& n' f( _- K9 L
using namespace NXOpen;
" V# m: G; @* f, g$ m
4 c) q) r: k7 h5 Q2 i; \: qextern "C" DllExport int ufusr_ask_unload()
+ k% C, M* s" q: a3 I7 E8 a+ ?5 {; J{
+ U! k, G) Q- ^4 ~5 w return (int)Session::LibraryUnloadOptionImmediately;5 ] j5 y" |9 ` E) ~
}
# Z- U" j7 u% n3 H1 U8 j* Z, ]3 f! R% k/ ]% H
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen); l, ]6 ^" p0 c% P
{
h6 P6 H5 }/ \( n' N Session *theSession = Session::GetSession();+ ]/ Z* z! Y+ P# e
Part *workPart(theSession->Parts()->Work());
5 `' Y) _# c0 y: N+ f. W Part *displayPart(theSession->Parts()->Display());
0 A2 H" F1 ^; d7 s/ f // ----------------------------------------------, ]3 v: H0 \ d4 {) q5 o2 [
// Menu: Edit->Curve->Divide...
0 N% P; x) X }5 ?( O7 U+ U // ----------------------------------------------% k3 D B# x) l7 {3 U; L. S4 i% z
Session::UndoMarkId markId1;8 Z( e3 l, z, W5 t1 I3 h9 }
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
\) s) H8 S! e* Q5 a& j+ {# @1 q
Features::Feature *nullFeatures_Feature(NULL);3 j4 l1 N4 s( r; `4 D
- A+ ^* N1 H7 \6 }4 U, L
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
5 R# {2 H% ]; M/ X1 v& _ {, [! X4 V5 T% h7 N5 T* K! }
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");' x. j6 q' N' n3 r
}* g1 H+ ]. @1 L5 o# \
' i# P+ u+ ]& E Features::DivideCurveBuilder *divideCurveBuilder1;
& O# [9 c3 A% S$ t divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
9 i" k5 i. l( g' W8 [) \. a: m5 p0 G, G+ i2 v
Point3d origin1(0.0, 0.0, 0.0);, |9 A! y/ f$ C7 Q* j3 L
Vector3d normal1(0.0, 0.0, 1.0);
5 A# j5 L* z# e& G Plane *plane1;/ f: X! R, W+ k& z6 q: n
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
; E9 r* E) Z. _( `2 S7 z0 B3 m# S
5 V6 h6 V, e1 m6 W divideCurveBuilder1->SetBoundingPlane(plane1);% q1 i, F. L6 p) c3 r# l: Q
$ H0 x" J1 i- p/ o" N0 V6 u7 M
Section *section1;
2 t- e- U8 I, r" T; Z section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);8 C* V+ W ?2 Q4 T9 q7 c
5 P" i* d3 r; W/ q$ [9 O. A
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));7 [5 Y/ A X; O( V0 g. V
Expression *expression1;1 [0 l4 |/ |! [, O$ a: X* x5 `
expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
4 g) @6 M5 [3 n* p. ?
9 D$ P" z+ ]+ E# X% K5 m Section *section2;
) A4 O- H; i0 s+ @" a+ I$ w section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);1 K7 M7 @, V7 d; m( {) ]# D7 I1 z5 P
3 x' l1 A/ P9 \. g4 v Expression *expression2;
' O! t7 K9 _& g# E% T( b$ ? expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
' X6 D/ |* p8 Z
9 t6 ?4 L2 u* x. F+ y; n& w, w divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
$ Z& k9 {& P: t8 ?" Z: @1 B$ o
4 ~2 |* D$ {8 E7 P divideCurveBuilder1->SetEqualParameterSegments(5);
% q. x6 A, B) Q. D# D$ W- |; F4 ]4 l
divideCurveBuilder1->SetEqualArcLengthSegments(5);# g y- }9 E& ^6 n+ O" c9 A# D
) @) V( y1 D! e9 b4 e
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
* f$ h9 a+ S; E2 V* }. J7 K* m& Y9 e* X: V1 y( |2 a: r
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);. l" q& w, d5 c
$ A+ U* a0 c5 t0 ]% H, [4 o Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
% @7 N; }' G" y7 Y, p Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);7 L d; U" k- I1 e5 G7 |# S7 H. [. @, X j
divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);, ^& o8 D7 A6 J
7 g7 t6 g5 S' H" O) k7 U9 T4 _
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);
" M: l5 P# ^8 f$ p" d5 m! t/ L- M3 g3 P @* G" b% W
Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));% Z8 I" e+ r9 d0 D! C' f, i# ?
Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));/ {9 L9 E+ |) G: n, Y/ O
Xform *nullXform(NULL);
& J) W5 H2 b2 _& R2 Y# a Point *point3;
* I( }& G' T8 G4 ^3 A) } point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
9 o/ `$ t% U) z; ]7 L, p o8 T
+ @: @2 ~8 P9 q7 a3 |; ~ divideCurveBuilder1->SetBoundingProjectPoint(point3);) q$ v1 Q7 C- x; K0 f
$ F# l8 u& v. c0 m' @ `- |: A, | Session::UndoMarkId markId2;
5 D% q' l/ O& m markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");- X! i1 F! L3 i/ J
4 h ]: c) H$ m0 `7 ?6 X2 c/ Y NXObject *nXObject1;
9 a+ y5 t" [4 q. m8 U) j# S nXObject1 = divideCurveBuilder1->Commit();6 S* u+ u R4 k. {, W
# Q: v7 l+ P u" ^2 I: e std::vector<NXObject *> objects1;# o1 F5 J5 a1 a" ?/ G
objects1 = divideCurveBuilder1->GetCommittedObjects();$ Z) H# P! p: c$ B
7 {# y& m& b5 y$ r# U s; ? theSession->DeleteUndoMark(markId2, NULL);/ ]2 t" N: M" n5 D
: `4 \) S- b9 ~9 \2 k K( t n k theSession->SetUndoMarkName(markId1, "Divide Curve");) l {( E" N* Y; D' q" ^- J! ~' Z0 @
) ]: ~& e7 T1 }2 X) ~ divideCurveBuilder1->Destroy();
9 a- G* W$ N, k1 w+ b- n% U; t+ Q* k
$ u- e2 N" W/ F7 J' E& j try( f, g4 F0 s9 K S. c( d# R
{% W: {- N$ f7 K8 _
// 表达式仍然在使用中。# D' d4 q5 `' E( m9 l
workPart->Expressions()->Delete(expression2);# E' F( h5 t# i+ d) h3 S$ [& E8 Z: C& U
}
: z, x! F3 O$ T/ o- O ~ catch (const NXException &ex)
' O- M5 W, f% F6 l, ^8 e, K, g& F/ a! r {4 A, G% A* G$ E$ I- G$ h. d* l
ex.AssertErrorCode(1050029);
. E( ?/ J5 k9 T/ R) c6 P+ g }
2 }4 G g/ N. i$ D' Y
0 f2 b- T& z/ h' f: O8 m section2->Destroy();+ W* e0 X" m9 N( K
5 @ T, \% ?( p2 d# o try; f$ `% i5 Y6 P6 o
{
' i5 B! ~" Q M6 l# V // 表达式仍然在使用中。. T, E; ^4 d; l
workPart->Expressions()->Delete(expression1);
1 L* q5 E4 F, ~* A+ Z }
0 T) g% I# F; `) D, O5 I catch (const NXException &ex): y( v' `/ V' y* w R2 a
{! F. s7 r! W4 ]2 J) ^) ]3 R
ex.AssertErrorCode(1050029);7 H5 }, G( [7 j7 N; y
}: u; m9 f, o9 X M* A
3 p' q2 }0 @" R6 q! \
section1->Destroy();
[7 R6 Y9 G1 {
6 q1 a- r5 m$ S( J" g: _- E0 w plane1->DestroyPlane();% j: T8 n+ U J+ h' E/ j
1 P0 Q3 M/ s6 N2 o8 o
int nErrs1;
) g$ K3 D' Y% U" v; [( _5 q! a nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
1 x3 r% M: U. o2 K4 u
# c' L& g) {, Q0 p+ O6 L* ~7 h // ----------------------------------------------3 a& Q4 Q$ Y4 ?9 o" k7 P+ R
// Menu: Tools->Journal->Stop Recording9 w: `; b$ m ^% W0 c
// ----------------------------------------------
: O# S, i% a& {, h: A}
D6 H1 n" v2 A, M) F
. Q( Q5 \9 o8 k
& Q2 Y% ?; o7 x3 r) X2 D4 O9 R. V& n, K! _1 d5 y) ~
希望大神指点
7 O3 a5 K# n% i8 K! v. z" z$ G |
|