|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了
& X0 [+ N: O7 V) j; x2 c
2 `) F! R4 L+ X5 c, T std::vector<NXObject *> objects1;$ {: _5 l ?: T4 k
objects1 = divideCurveBuilder1->GeTCommittedObjects();4 w, _! S7 j, Y& ~7 s
3 y8 _0 j! `4 c2 P
( H/ d2 B. b% ]: _3 i
0 G$ {0 v/ A5 G3 X2 r) j: _! V- g7 V. a
完整代码如下:
6 R% r* O) T! d- _& _; u% ^( `3 Q/ \8 s. r3 l9 o
// NX 7.5.0.32
) v2 }8 w* m8 I// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
8 u( Z' I2 ]/ x( r1 y! k//
: ]3 Z; U" C' J#include <uf_defs.h>
- h6 t5 C4 J: |: h( S#include <NXOpen/NXException.hxx>! e6 r# G2 m$ N! N7 L
#include <NXOpen/Session.hxx> u$ j5 }9 l$ L6 C6 ~
#include <NXOpen/Builder.hxx>7 c3 a( L* e1 n0 \$ M: A
#include <NXOpen/Direction.hxx>$ L1 ^( h' O. u' s
#include <NXOpen/Expression.hxx>, O5 ]: G1 H, c& _/ Y I" i. W
#include <NXOpen/ExpressionCollection.hxx>
' @2 S1 @* H, e. U" A, u0 \#include <NXOpen/Features_BaseFeatureCollection.hxx>6 B! ^0 W! Y* [' U# l+ q8 C4 q. e
#include <NXOpen/Features_DivideCurveBuilder.hxx>
9 J8 C. |& A' a, `, L/ O; [#include <NXOpen/Features_FeatureCollection.hxx>
$ N2 Y" u+ r9 J1 I#include <NXOpen/Features_PointFeature.hxx>. r7 O/ v& w) @9 G: a
#include <NXOpen/ModelingView.hxx>2 L' ?9 @* T6 L4 ^$ {* _5 p, S1 Y
#include <NXOpen/ModelingViewCollection.hxx>
: D% ^9 T0 F, A2 w1 u h#include <NXOpen/NXObject.hxx>& R* d/ ?' |6 j2 K1 u
#include <NXOpen/Part.hxx>7 B% l; u: @4 |. l% q
#include <NXOpen/PartCollection.hxx>" @5 D/ f5 m5 Q/ t
#include <NXOpen/Plane.hxx>
0 F8 K! i# F1 E# ^, {. t#include <NXOpen/PlaneCollection.hxx>' U$ U) U2 x @
#include <NXOpen/Point.hxx>
, l( S1 r9 I( H- ^$ L: B#include <NXOpen/PointCollection.hxx>
! Q, A3 Y: n# y: P$ G#include <NXOpen/Preferences_PartModeling.hxx>
1 O( {5 p! \6 m: {- ~4 O! D#include <NXOpen/Preferences_PartPreferences.hxx>
; C5 P( p3 w2 L, b3 c( ]$ W/ @% {) U#include <NXOpen/Section.hxx>0 W+ ]' _4 r6 L* k- o8 k3 G$ Y
#include <NXOpen/SectionCollection.hxx>
\* C( j. |8 D3 n3 ^# w# x#include <NXOpen/SelectCurve.hxx>
. j4 b6 d5 v3 a" b" [#include <NXOpen/SelectObject.hxx>4 T& u# `3 o/ y/ U& ^. t$ |
#include <NXOpen/SelectPointList.hxx>
, v0 b# ~5 k/ M4 @#include <NXOpen/Session.hxx>$ v6 Y0 O }1 `7 u. k+ G
#include <NXOpen/Spline.hxx>
, W# A, Z4 l7 W4 U#include <NXOpen/SplineCollection.hxx>
2 f- {. h2 T7 f! q# |0 ~9 u' O#include <NXOpen/TaggedObject.hxx>
; I' G) j( M$ U! w$ v8 I#include <NXOpen/Unit.hxx>
Q/ H2 s! o2 E! N) c9 ^! A' p: J#include <NXOpen/UnitCollection.hxx>
: y% U: ]. p$ s# w& w- T#include <NXOpen/Update.hxx>; q- d `9 m' e8 ?7 D5 u) O
using namespace NXOpen;5 t( \- j5 z, W7 ?$ w6 W
8 K' {- @. b: textern "C" DllExport int ufusr_ask_unload()
0 T1 C% O( F! p0 A8 c{( H$ S1 `3 ^. X3 {0 C& ]" p& i
return (int)Session::LibraryUnloadOptionImmediately;% o' P+ F, c( A0 z, v
}! W' k) ~6 T3 [4 Q1 f" W9 z4 B
J% }" I: d8 f
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)- r k! Y/ u2 \2 n7 h) }5 r/ l
{
5 r4 R+ C, J; O% O) k# I6 h Session *theSession = Session::GetSession();3 K) ^5 m; R, t d
Part *workPart(theSession->Parts()->Work());3 v. @+ [4 N2 X
Part *displayPart(theSession->Parts()->Display());- U& S; t& P! l( f
// ----------------------------------------------1 j+ K" R! E( `" [; G
// Menu: Edit->Curve->Divide...2 N- p" K/ w/ h
// ----------------------------------------------
. L6 n. |7 u3 @) x Session::UndoMarkId markId1;) C+ Y7 v" Z7 c! I
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");1 k& G4 @4 L, P3 t
3 h& y. X# a0 L# H& W$ m9 P
Features::Feature *nullFeatures_Feature(NULL);
+ ]' @8 I6 s* c7 S- _9 _' `) D9 ~ p% h- Q
if ( !workPart->Preferences()->Modeling()->GetHistoryMode() ); L$ G a" x+ w0 Z7 \/ B% X
{3 \2 e. R' X8 u1 R3 r/ o( z
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
: ~/ S, M$ u4 C% R }
# H1 q: p( d: B
; v: T- R$ l6 z& J Features::DivideCurveBuilder *divideCurveBuilder1;7 N) u4 I2 Q& O, x* r1 o0 W
divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);: U( E; d8 q& B$ [* K0 ?% \
7 w4 ]* N+ V. o& S
Point3d origin1(0.0, 0.0, 0.0);
8 h# m; g/ T) U Vector3d normal1(0.0, 0.0, 1.0);- I7 O8 H6 A6 V: c$ Y* r' [
Plane *plane1;3 X) J% }( j! {! k0 n8 f! \
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
+ G! Y1 a. ]' @( V$ y: R' g; z# G2 d6 F+ H
divideCurveBuilder1->SetBoundingPlane(plane1);2 ]1 v. ?# ~6 W' k J
# [) Z9 ]5 o3 E% l
Section *section1;
7 N! D, T) j1 S% o9 {% I) o section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);9 D& R* x" F' E# q
1 {* y. j$ u9 d- N2 ]- }' k0 |
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
. d8 S l, p5 Z b! i- P/ E" A Expression *expression1;
% Z" u/ I8 x) S' K! @0 B0 H6 e expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);, v1 Y3 B# W; ^+ Y+ P0 f3 H
* c# n; q: l8 h3 Z$ }" M3 H% m6 J Section *section2;" K+ R, Y5 n4 G. [/ `
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);. }7 N7 T6 I/ o* G- a4 i
% w p' h; _9 r- \" E+ z Expression *expression2;
# T* v8 R7 b+ ^: n, Y7 b6 _% C& l( Q expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
, Q% ?8 n" M( V( ^( v8 w! c! P4 `" H9 ^) F/ |' Z8 P
divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
3 B; d) w- F1 o4 k8 k# `! o7 P2 i" M. j' y" k, X+ O! C( ~
divideCurveBuilder1->SetEqualParameterSegments(5);( k P7 N; K5 `6 j3 p: A7 Y+ ^; \
% A2 _0 X' X' ~; [* C divideCurveBuilder1->SetEqualArcLengthSegments(5);0 C+ D) P* V* H: `
$ Q* p, d1 [+ x. b$ ?1 {
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
" h) Q5 w1 q! F5 ~
$ r/ u& _/ |7 L0 t( e5 h divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
0 x/ k4 i5 @! b! i. C+ R3 G) B; ]4 d8 w$ Z l/ N) O( }! D6 L
Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
" F9 `9 A6 A$ b d; W$ \. d Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
' L6 Y$ i2 a4 f3 j, p2 C' S divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);6 l) z( H0 o2 c% M; T% Z
# A$ j" r3 `9 e* B
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);! B2 r2 Y* r! F
- w: Q; T( R: R2 } Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
3 U/ ]& k- ^! w6 n2 N Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));* g, C; F2 F) R$ m3 G' N1 _
Xform *nullXform(NULL);
9 P w9 }- L' t Point *point3;' I5 d3 t7 U6 [
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
, R* `) b+ _. Z/ N2 Y% V3 a+ E3 g V I% b! G: o1 s9 X
divideCurveBuilder1->SetBoundingProjectPoint(point3);
5 z& s! G2 l4 Z, J0 r+ q) m
d5 _) g9 a% K& Y; b3 g2 u3 S Session::UndoMarkId markId2;
0 i4 ?$ O( [6 O- c$ o/ G markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
. R3 D. X1 @1 j T
' k& H8 W/ C; o# p3 p NXObject *nXObject1;
# v& y# j1 a9 i) \ nXObject1 = divideCurveBuilder1->Commit();2 u1 _7 F9 M" c, w
& M1 o' I- J' K
std::vector<NXObject *> objects1;. w! g) J' f: n( j4 |1 v
objects1 = divideCurveBuilder1->GetCommittedObjects();
" Z0 i" U" U" P; }8 w5 W; B9 f" ]( t. j' ]' c' S
theSession->DeleteUndoMark(markId2, NULL);. x+ B3 S8 Z% l& u
, |, d& q& z- u- }. U theSession->SetUndoMarkName(markId1, "Divide Curve");
; g# c. M' s4 a5 ]8 V; Y) I5 C V6 M& i" ~% _# c2 Z& J- b, g
divideCurveBuilder1->Destroy();
6 G2 |6 x( ]2 F- N- j
- p6 u! H# p& c# d {# p5 i try
' G( P$ m9 n& ^" x: u {
; v, u7 x) o2 Y1 I // 表达式仍然在使用中。
% \# c) i( ?4 B0 p workPart->Expressions()->Delete(expression2);
) {* [% `% @' ^+ Y }3 f1 p5 {6 G8 j D
catch (const NXException &ex)
5 [; k" z# I. r" b1 \ {
$ R+ n) A3 F1 b; Y ex.AssertErrorCode(1050029);" A1 v* M! I+ G( N8 s8 F
}3 [/ T9 {' U" T% j& O
# p# B+ s1 x6 L! H1 x section2->Destroy();
! I6 R# u3 {/ r5 q) |
4 |6 t' H7 N8 p. ~+ _% K! A try
6 Q5 _. C2 {) a, J* @ {
8 Q/ h* A$ Q$ ~% |: H; J5 F( l) D i // 表达式仍然在使用中。
7 ^5 B5 V) f7 T8 W, m8 | workPart->Expressions()->Delete(expression1); [7 j' ]: ]3 N- @6 p
}
- T g5 D5 d1 G6 w4 e catch (const NXException &ex)9 e f, C$ ~4 e1 T0 {
{0 f5 k8 v. d- s8 c- d5 U! f8 u7 c
ex.AssertErrorCode(1050029);. h& z n f4 y* z8 ?! C# c, ?% |
}
- [) C+ f' M9 l, t7 @* m1 \0 r; n* b" O+ I+ J5 P0 ^/ G" }# Q" i
section1->Destroy();9 L! e l; p! r: R7 n7 H# R
. R8 [1 z J; [- `" A2 f! B3 l
plane1->DestroyPlane();* |" K. c; X/ B' G3 G
F( K; C) `8 J0 R. T int nErrs1;
7 }6 w) s, {" K# _/ u4 f nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
$ q/ R7 Z1 |4 N0 c3 l# E% O
6 S) N, M; U9 E: T' c+ z // ----------------------------------------------; O9 W i! e, d- s/ @
// Menu: Tools->Journal->Stop Recording
9 K$ g' N1 Q1 }$ f5 P1 c7 h // ----------------------------------------------
4 q2 _6 P1 @* V0 t}8 X2 L0 O( P9 `- x; c: F8 [4 Z! s
9 s! H- o/ }& j* f% Y
7 `) q+ z7 f6 J- f$ F8 ]
# o8 V8 B' Y }希望大神指点$ F. ~. E& R# l+ E
|
|