|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了! k8 g" \( z( w G9 k0 S
! R; K& X$ p$ L, b8 h1 W std::vector<NXObject *> objects1;
# Q( R5 g0 Y: j3 E4 z0 Y6 B4 l7 @ objects1 = divideCurveBuilder1->GeTCommittedObjects();
h5 O: J, R/ z5 r- m# |
' H0 [0 `$ ?* U6 s
) k- v0 H, ]% Q! `0 J {, |( \1 u3 I5 w0 e0 F
完整代码如下:
7 A9 K T4 }) l, m9 q& A* g
" S0 R& H0 |6 p, q// NX 7.5.0.32+ [; X' d: r/ {$ U
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
2 K/ y- x9 w$ q//
/ V% `1 E W4 p: B* b0 G#include <uf_defs.h>
3 w7 k+ r9 e; Z* D0 h5 I#include <NXOpen/NXException.hxx>. C/ j" y6 I/ j
#include <NXOpen/Session.hxx>
5 h. s' X* b- f Y) u#include <NXOpen/Builder.hxx>
3 f2 \' M4 M. k1 o#include <NXOpen/Direction.hxx>
$ c( V- R4 Y# {" x- Q#include <NXOpen/Expression.hxx>
' B z7 ]3 R6 o4 F; ~#include <NXOpen/ExpressionCollection.hxx>
" K6 N' Z9 ?- W @#include <NXOpen/Features_BaseFeatureCollection.hxx>
; V3 J! ?% S4 M3 V4 M#include <NXOpen/Features_DivideCurveBuilder.hxx>3 r6 C5 X* |9 Q' K. D. i
#include <NXOpen/Features_FeatureCollection.hxx>
6 ?0 P+ W+ @! D; Z+ M#include <NXOpen/Features_PointFeature.hxx>
4 ~; G) B9 [; S' ]" x4 z5 ?: P T#include <NXOpen/ModelingView.hxx>, h0 Y; m$ W+ T6 c$ U w' b
#include <NXOpen/ModelingViewCollection.hxx>+ k( e# L9 u& l _# [. C2 ?( E0 a
#include <NXOpen/NXObject.hxx>8 J1 c7 X8 u8 |% I
#include <NXOpen/Part.hxx>
- @ v+ C$ `( d; d. k- H: x#include <NXOpen/PartCollection.hxx>
^) k/ J/ P4 W# A. A( S#include <NXOpen/Plane.hxx>( j" Z) v/ R" Z$ f! m% f, Y7 f
#include <NXOpen/PlaneCollection.hxx>5 k+ ^# F& E' U: ^/ \3 u' X8 p0 p
#include <NXOpen/Point.hxx>9 X& u4 E2 O% Y b$ l1 U
#include <NXOpen/PointCollection.hxx>
' B! x5 e8 k n* Q) d/ j#include <NXOpen/Preferences_PartModeling.hxx>
3 U( B2 X; O( S, f. C% B#include <NXOpen/Preferences_PartPreferences.hxx>
: D6 H2 {8 Q4 z5 K# K#include <NXOpen/Section.hxx>
8 W, W! `8 W9 C8 E& b) ?& p#include <NXOpen/SectionCollection.hxx>( R0 Z2 X$ M Y4 H0 H3 X; r& B7 X1 j) C
#include <NXOpen/SelectCurve.hxx>( n- v/ w& A% o( c
#include <NXOpen/SelectObject.hxx>
$ c$ b+ m3 N/ s$ s( Z8 J#include <NXOpen/SelectPointList.hxx>8 M7 K& }' F! I, F n* ~7 H" h
#include <NXOpen/Session.hxx>
* U1 f8 k x; s5 R4 O& H#include <NXOpen/Spline.hxx>
1 v2 I/ Z1 p% n, H#include <NXOpen/SplineCollection.hxx>
! t5 M+ {3 w0 \ z! _* P1 N#include <NXOpen/TaggedObject.hxx>
( k8 [4 \: A; D/ l#include <NXOpen/Unit.hxx>1 _* d) T+ v$ X" e
#include <NXOpen/UnitCollection.hxx>
# o1 [2 P l+ H, k#include <NXOpen/Update.hxx>
4 d6 V0 |% n9 ]9 ]1 w; S C% U- Pusing namespace NXOpen;
' p. I7 a2 n! K2 \' E: d' W9 u6 C. }/ H9 d! v
extern "C" DllExport int ufusr_ask_unload()
0 r/ q) e6 W0 {0 R( Q2 A) k{
& C! e* E1 q. z" I$ x return (int)Session::LibraryUnloadOptionImmediately;9 q* P* l. ]# T0 M
}) z+ O+ _; j, Z$ V Y2 u
5 Z! _/ g0 C+ O: a Sextern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)3 w0 [ a, ?# t, ^" a; v9 e
{0 N' c6 z* k1 H. z+ v
Session *theSession = Session::GetSession();
7 A/ b* G: k2 t- P Part *workPart(theSession->Parts()->Work());( u$ ]0 M4 Z8 o% J
Part *displayPart(theSession->Parts()->Display());- f* V0 k0 M* Q" `# S
// ----------------------------------------------
3 B8 j! _# m/ }1 R // Menu: Edit->Curve->Divide...
; n. j5 f8 ~/ C% o: ? // ----------------------------------------------, l5 E- V; S* ?2 _3 J. j' M, v! P
Session::UndoMarkId markId1;
- B; b8 P; }( W6 e9 w markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");: R! R# E! E( G% x& q! x' S
4 }" {) K* [8 I8 x Features::Feature *nullFeatures_Feature(NULL);( i) \+ v6 Z. w2 l6 H& X$ g: G
9 f& q& M5 _% b$ H if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
* @6 o. n& `; q6 U x0 C {
( |2 n2 ]3 A2 b) B% H' ~ throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");4 G! }3 \& W. h: Q" M
}
1 M2 }' I/ N6 a$ C# U. u% V/ O7 ~- W% i7 j
Features::DivideCurveBuilder *divideCurveBuilder1;
; q4 @4 b1 I7 o7 U. l; u! [ divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
& I- Z( `4 p/ C$ a3 ]; K
- {4 |2 r# K6 V& |3 ^ Point3d origin1(0.0, 0.0, 0.0);
3 n2 R" {6 N* q5 m6 t1 f5 [ Vector3d normal1(0.0, 0.0, 1.0);3 t9 R' {& h" [" L: g l ^0 N
Plane *plane1;$ G( `' u0 r9 k* c z! u
plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);+ i& c& m9 W- Q4 g6 I0 z
" a" ]8 w9 A8 O$ v; h, d5 y- k: h6 _ divideCurveBuilder1->SetBoundingPlane(plane1);
* D/ [1 T1 P( k! S2 g L, f/ n- A+ O: W1 K! f' H
Section *section1;
. S/ g# c+ }' a4 Y section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
5 C0 D |2 O% C- f+ i7 B( ]6 d( ] \: z+ h0 p! V; h8 F* U2 v3 i4 D! J
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
2 s# A( z0 h# M Expression *expression1;
" z+ q! ?6 S9 a. w expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
! n5 E! h: {/ z* v! L1 m2 @+ `% k" `
Section *section2;; {. @- [- l6 J8 q! S7 \5 j+ }
section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);& H, j8 e. \( A1 A5 B
/ @7 `8 k1 u, @$ _0 Q
Expression *expression2;6 D" y1 }/ C) c& o
expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);
( B, H1 I! l, U3 H$ B- ]7 z# C% A T N% Q3 |- C
divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);6 i+ E( e# [; c
7 ^ h" p0 o) F* K6 l divideCurveBuilder1->SetEqualParameterSegments(5);/ A+ x& }5 T" y( u0 `# W5 m" e
" j6 y& z! |. V
divideCurveBuilder1->SetEqualArcLengthSegments(5);% y' l$ ^! ]+ d; i9 u% T$ O
/ T. [ o6 X6 U- ?3 q5 Z
theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
! y) P9 @& r1 D1 b! f# `6 g& ^% f3 P9 P! W
divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
2 v3 S1 o8 X8 O+ Y" a0 ~7 j& \% a
* W" d) r) N5 }1 h% i/ Q Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));+ g- S6 u x5 N0 d( Q" u
Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);, t/ j! Q8 T6 u1 }* i' N! S8 t
divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);# u% X* I) r; u: I1 p
: p7 `& w! m+ O' U( s6 }
divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);& H1 x9 L, X' A$ t
4 r& q% b4 H. u; b Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));7 |- ~2 G) q$ T0 H1 {6 Q
Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
0 y2 [. K3 V, `% u' v9 } Xform *nullXform(NULL);
# f7 i7 q! i- a8 D9 Y; D, o6 T3 l( m2 }2 f, v Point *point3;8 r: C9 K2 ]7 c: R5 c; S0 H
point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
# V6 H9 W1 C1 ~% ~
, w8 e( L. q! C) }4 X$ T' {7 X divideCurveBuilder1->SetBoundingProjectPoint(point3);6 d+ s3 R8 _0 v& D, Z
; B: C1 ]: T# t' z9 a5 F% m2 i
Session::UndoMarkId markId2;
8 ]9 `8 d1 a7 \3 m8 J markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve"); {3 `8 r+ q4 ]$ @! l3 }2 a2 v3 w: F
# r7 J$ r$ y# s) D6 \
NXObject *nXObject1;
, j4 I" _8 N: P* | nXObject1 = divideCurveBuilder1->Commit();6 Z4 m9 s. N/ r; N4 n5 q
% [4 y1 {- Z# J/ f' E
std::vector<NXObject *> objects1;
; F6 ~- d4 t$ Y# p2 }- C objects1 = divideCurveBuilder1->GetCommittedObjects();
4 S" @! O l' Z u3 F
5 r. D" \' L; u: J, w* f theSession->DeleteUndoMark(markId2, NULL);( t7 `6 y/ M5 g/ h
4 y; n' ~- w5 J2 x, `4 E
theSession->SetUndoMarkName(markId1, "Divide Curve");
$ z3 o# e1 N2 d$ |' L$ R! m3 Y! V; T5 X2 d: X
divideCurveBuilder1->Destroy();
3 g9 F' A+ n( G4 g: |' ?
* A$ }8 J. J" L& U try/ M2 f8 a5 D, ?
{/ i: H& w! Y2 q2 ^; ]
// 表达式仍然在使用中。; _: N4 w3 D( N% f9 F0 _% Y
workPart->Expressions()->Delete(expression2);
z; v4 R* |/ s1 |& r }
+ W" t6 q* R: r& W& r3 u catch (const NXException &ex)
+ g0 Q" y0 z; F& v {
, i' b. X( U% b- L/ @1 J/ c6 q ex.AssertErrorCode(1050029);2 q/ ?9 O: [, M" L$ e# _% J
}, V7 O$ |" M5 ?7 \- x5 F
, y4 i: g4 s5 \' t2 l5 p section2->Destroy();9 i+ S2 h; P5 B
" O; T) @; G1 }6 ~0 W: R2 F% S try
$ ]+ X# d) U# O/ c {
" y/ B+ @* [7 Z6 V // 表达式仍然在使用中。9 j8 c) R+ X7 u! ?+ L, W
workPart->Expressions()->Delete(expression1);; I9 ^( G& U# P. F# J8 N
}
; Q8 a0 ]; b3 k5 y5 U, D4 L; }3 o catch (const NXException &ex)
7 E+ g5 h1 c( V( K {' O! a) A+ ]# m7 c
ex.AssertErrorCode(1050029);
2 g2 k0 K% N5 o! q }
- e6 H4 U" `3 n" N: j- D: C) J9 q8 a3 W! x/ r1 M, m- V
section1->Destroy();. Z# R7 E7 B3 r. `- B
) W. {7 a6 |5 J# C/ Q3 p plane1->DestroyPlane();
/ e3 U- A( o4 Z' G( O3 q% C; s: | @- w6 k4 n# @& {
int nErrs1;
: `8 S5 @# p7 Y9 R. i6 |& g! @1 W nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);0 F/ U' S, \; k; E
& J7 B, f7 w0 Y/ n% C // ----------------------------------------------
2 y, ]. {3 j4 X% Z1 T4 ?$ t // Menu: Tools->Journal->Stop Recording0 \7 n& o N2 E& s- q0 m
// ----------------------------------------------
9 w9 @) n: J2 c}# _! r! W! v" w7 `, E5 ~0 v
8 @! F, `" E% N0 a9 c T# O
& ?3 f" P! D, N3 P N' I, O* L0 j% I5 @! ?9 o8 Z8 l
希望大神指点# l: q- @/ I; l" Y: O' q
|
|