PLM之家PLMHome-国产软件践行者

[求助] NXopen C++ 分割成两段,我怎么得到两条线段的tag

  [复制链接]

2020-4-5 10:47:20 1751 2

SimonLv 发表于 2020-4-4 23:57:29 |阅读模式

SimonLv 楼主

2020-4-4 23:57:29

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了
7 C5 s- i, f6 ?" T
; r5 I; w  F" C/ X6 o% p    std::vector<NXObject *> objects1;
, K5 l: h! b- `& s' w9 c    objects1 = divideCurveBuilder1->GeTCommittedObjects();0 E  ^# R$ n. N( `1 k  L7 H

4 O2 S0 W/ R% C+ {; A0 a  D) r; {! b  T( t5 T( }4 W
! k3 b7 ^7 {* V  L6 X: g$ F
完整代码如下:
6 ]6 r# y2 h5 N3 Y9 M1 U) E( [9 T. ^* b% O; h+ Q0 D
// NX 7.5.0.323 F3 f% |- J$ e; C7 t8 H. J
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间/ G3 g, w2 W- @
//
4 p. e7 R' E/ q/ H! [+ r' |#include <uf_defs.h>
3 v7 u: B: K0 A% X/ q: z! t0 v#include <NXOpen/NXException.hxx>- s. q' {2 C2 C. L- ]4 F* K
#include <NXOpen/Session.hxx>5 l9 [; A8 i- I, o6 k
#include <NXOpen/Builder.hxx>
+ {1 Z2 `0 F- @' j* o' P#include <NXOpen/Direction.hxx>
) K, M- v# k+ t6 [# j" K/ |0 W#include <NXOpen/Expression.hxx>
% N9 [0 S( B+ W2 c#include <NXOpen/ExpressionCollection.hxx>" O" |( i. }# }8 v1 o- X; j8 `
#include <NXOpen/Features_BaseFeatureCollection.hxx>. w$ K* U) c/ \% f! j
#include <NXOpen/Features_DivideCurveBuilder.hxx>
# [- z- Y, U6 t7 D: H5 L#include <NXOpen/Features_FeatureCollection.hxx>3 b: |8 n  |2 F8 v. U2 t) w: U
#include <NXOpen/Features_PointFeature.hxx>
3 \: t1 L2 I# ?: W/ A$ s! _9 W1 s8 }#include <NXOpen/ModelingView.hxx>8 I$ L( I0 X' n: K+ j
#include <NXOpen/ModelingViewCollection.hxx>9 B+ t6 ]0 T5 r
#include <NXOpen/NXObject.hxx>! W: ?8 t, q6 z9 l9 t7 r
#include <NXOpen/Part.hxx>
2 V6 i+ S; `- u& S#include <NXOpen/PartCollection.hxx>7 _+ [5 X! H0 R$ v+ g
#include <NXOpen/Plane.hxx>$ L' K6 ~8 J; Y9 H, G" J
#include <NXOpen/PlaneCollection.hxx>9 l0 }4 S3 i4 F& Y4 K1 |7 W& J4 j3 l
#include <NXOpen/Point.hxx>
7 p1 P* `) N  V" o#include <NXOpen/PointCollection.hxx># E2 @0 N& V, ?
#include <NXOpen/Preferences_PartModeling.hxx>
/ H% V! m) E9 H2 r4 p8 o+ p7 G9 z6 B7 V#include <NXOpen/Preferences_PartPreferences.hxx>7 \! r" L; T6 v4 u9 a( b
#include <NXOpen/Section.hxx>
. u2 z/ ^' D  ~#include <NXOpen/SectionCollection.hxx>
2 q% ]0 B. b& T0 q1 I  j0 ~#include <NXOpen/SelectCurve.hxx>
$ U4 s6 Z% T  y( N. f# H' ?#include <NXOpen/SelectObject.hxx>
6 p& O2 Z4 I4 u#include <NXOpen/SelectPointList.hxx>5 A0 _3 b) a6 f+ P
#include <NXOpen/Session.hxx>' r6 {5 I$ G5 i- }
#include <NXOpen/Spline.hxx>7 h6 z$ S$ b5 D8 W% S: d
#include <NXOpen/SplineCollection.hxx>: {2 Q5 ~2 O# _$ T0 j) {
#include <NXOpen/TaggedObject.hxx>( E( S! W( o  e0 V% \
#include <NXOpen/Unit.hxx>, @# s$ t! O- p
#include <NXOpen/UnitCollection.hxx>
* O. ^/ }. ?9 L$ J#include <NXOpen/Update.hxx>
% D1 U* Y# k& {% U. z- musing namespace NXOpen;! w( {) m7 W! P
5 X) g; s7 O5 u% G3 \" q4 e
extern "C" DllExport int ufusr_ask_unload()
) V; K; k5 W/ _{
" U8 c2 [  N) n2 Y6 J- \) I) U    return (int)Session::LibraryUnloadOptionImmediately;
: o# p' J: M" _}
$ d, N$ \  G& T4 ?# n  u6 R) m' f# P% w) n% I( Y  u9 z
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)3 r3 s5 J6 ], e9 k
{
4 M1 b, y, j) y' X    Session *theSession = Session::GetSession();
5 _' m  W" d) y$ ^3 n2 I. r    Part *workPart(theSession->Parts()->Work());
) m3 Z" ~- T7 Q& r7 l9 q2 }    Part *displayPart(theSession->Parts()->Display());
6 C/ n' d7 a7 \, s    // ----------------------------------------------
1 |9 z. P" b8 m0 w4 b2 U9 Q0 @    //   Menu: Edit->Curve->Divide...
1 X9 _" z3 t0 M/ U3 U    // ----------------------------------------------! r6 |5 U+ q$ D) P6 g& b3 r: b
    Session::UndoMarkId markId1;; M& |3 v$ o8 p4 \+ v0 g
    markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");- `9 t* Q( u6 p/ J/ V2 O

+ ~  \" e8 `0 n; F- w6 _9 I    Features::Feature *nullFeatures_Feature(NULL);9 D$ z* q5 m) l/ d
  q4 D* e" G  F4 t
    if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
4 x% s4 S9 R$ D- B8 P; N    {) m. H$ `/ G; Y1 R; e2 {% @
        throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
5 `' ~* t8 A; U    }
: T, J! W3 B+ M1 `* Y. x) U# q0 a' x8 Q- ?, A# h% B3 O, V
    Features::DivideCurveBuilder *divideCurveBuilder1;3 t, @* [: r; m$ p; [' n4 W
    divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
+ x7 q* D, c, b- U
0 `( o% T8 _5 r    Point3d origin1(0.0, 0.0, 0.0);% M- }7 j( ^$ ]( A% a/ A2 m
    Vector3d normal1(0.0, 0.0, 1.0);" `% r9 V6 _- m
    Plane *plane1;
) Q. V# q% J: c) n+ p    plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);( i8 o- D; i7 i. O; l! _) @/ o/ O

# g7 g' U% D1 ?4 z    divideCurveBuilder1->SetBoundingPlane(plane1);
7 X- v2 o$ W) ^( @
7 k- E- l9 E6 t    Section *section1;  U; ]: w" L! F) X" y7 D
    section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
3 r! _6 Z" Z$ i8 p, Q( W. d- x; D" b8 L/ c
    Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
( d; c9 ~# r* F, K- ~) d    Expression *expression1;
7 }& T5 g; o  _    expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);! e7 e6 M- S8 c! Y& O( K

( V$ L" y. q; q+ F+ `0 Y$ J0 {. ?    Section *section2;
8 [" A8 G7 G# b- e    section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);. A: e- D: v8 Q( E' b% u" H% m

4 J$ U, n, Z; ?    Expression *expression2;0 j7 @) |4 S# N% e1 {' ]0 O8 `
    expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);9 h) Q& n; ^2 S  @

- P) Y$ j. q: T+ P6 \    divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
% d+ Q9 L4 @! O; V. _( i- t3 s4 P: ]2 L$ f1 x
    divideCurveBuilder1->SetEqualParameterSegments(5);! i7 r4 j& G: H5 y; [0 a
7 J' D5 L! t( |4 T
    divideCurveBuilder1->SetEqualArcLengthSegments(5);
; Y& }) v: ^! ^1 f/ g. l4 B' w( V5 k, ?) K/ g. u: j1 ^3 o
    theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));( o5 F; x( Q7 {1 y* B

: R& S7 e5 y: Q4 D' a; k2 j/ A    divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
8 E, S$ t1 j" y# l$ _. S9 L4 x& y! E+ i; W
    Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
; [% D& n; j% @% y5 v) @& C    Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
. D: L( B( C) o$ J+ m/ d  x( [    divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);) u7 P! R1 O! A1 i

) g6 N# {4 |! W; x    divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);9 f9 A$ @% {' ?& m

- ~1 z7 E5 @" h' B8 g1 @& @4 X    Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
/ i. G1 f; X# a$ q- t# |    Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
- p3 w" @5 S0 E% u2 }* y' Q    Xform *nullXform(NULL);
+ h9 X" d2 h% A' H    Point *point3;
8 n0 v6 [& b! G6 J( w7 {- b    point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
# D2 ~+ A# H# {- ~! W3 O: |; @2 a5 R1 r" t
    divideCurveBuilder1->SetBoundingProjectPoint(point3);
# }$ Y+ \5 I* }
' {' ?( H% b5 K' \9 d2 f9 i; V    Session::UndoMarkId markId2;$ f" ?  ]! U  B* w% q4 X6 F
    markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");5 r* I6 U6 a' O, ]3 l2 K2 U3 j6 m) L

8 O8 }: [7 P  [1 s    NXObject *nXObject1;
( w! x5 U0 D7 i/ A    nXObject1 = divideCurveBuilder1->Commit();% a& L0 r2 h' S& p" o

: t& ?8 W2 i+ _; l( y) _& _4 r; E2 ]    std::vector<NXObject *> objects1;4 ~: I% s% v3 a2 h- n
    objects1 = divideCurveBuilder1->GetCommittedObjects();# d$ V. a0 ~# E
/ W% }0 ^9 @- O+ {# R
    theSession->DeleteUndoMark(markId2, NULL);
! |0 P9 z) v, T  ?2 G) E$ m5 f$ `( \0 d
    theSession->SetUndoMarkName(markId1, "Divide Curve");
+ w( K+ D/ Y+ ]6 k: J: J( j  T- y. O$ @: _8 u) D" ?
    divideCurveBuilder1->Destroy();
3 J5 n5 f& Y4 @
" c' \: P* b* U2 H* _$ Q% b( [    try- m; E- t, r$ O: `% ^
    {
$ R$ `! N: ?, E% b& ^! D; Z. f4 v        // 表达式仍然在使用中。
7 k! Z, P1 {# @) ]/ }        workPart->Expressions()->Delete(expression2);+ E4 j0 @% E* q# ^7 d" g
    }+ M# m; ]* c4 _. i) d. |  ~
    catch (const NXException &ex)% N9 O! |3 W. d# d) s
    {
( @9 k' s; Q5 B4 d6 [) B2 S2 u+ ^      ex.AssertErrorCode(1050029);
- L% q6 w4 r  B, ~) ]$ ^    }
3 K) h& x! H# E& ^0 G5 o' {2 G9 p
    section2->Destroy();
: D5 ~* B: e# J- s3 H8 f2 H# |6 ]: F0 b3 F& z
    try* R( j& d6 I8 m
    {
8 p# p9 p7 P6 ?. d! x1 N% A        // 表达式仍然在使用中。
7 x8 }, m. l9 h. }: e# S        workPart->Expressions()->Delete(expression1);
- g2 p) I& E1 I+ B+ C' h' L! n9 E% T    }
' B" u  v' L1 O* K5 u    catch (const NXException &ex)
! j* j- T. X, M6 f2 O, d    {& T' B" `7 `) B) Q( q" T& ~
      ex.AssertErrorCode(1050029);
+ {$ f1 A1 z1 I! p, Z# [    }* |4 k! @. q7 Y

; r" |. x; `( s1 p. y; ~, `. I    section1->Destroy();
0 d0 J) o3 w: y3 R1 j5 _4 h0 f9 n4 v2 c$ ^+ O, R
    plane1->DestroyPlane();
9 E9 n! o/ H, f; _. ^: R( B% o. n
    int nErrs1;
2 W- Z* x& u( u* b    nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
. Q) G: J5 O" z+ R" n
- K, X: V. U4 a/ h2 [  b/ k    // ----------------------------------------------( e& Y) L- {# Q: r& w
    //   Menu: Tools->Journal->Stop Recording: B0 L2 P- h- B: c! F
    // ----------------------------------------------
! ]  O: }8 B9 k4 g. H/ H; V# ?6 L: E}3 G- D- K. F# [. f2 \/ L% T
9 P9 l) I# Y7 B3 F' q5 o

  I- {0 v' E+ Q
  E. Z) Y0 `* [) O9 K2 L. P+ u+ d希望大神指点( n  c2 r$ z+ p. r7 o$ C5 Q. b
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复2

admin 发表于 2020-4-5 08:52:59

admin 沙发

2020-4-5 08:52:59

objects1 = divideCurveBuilder1->GetCommittedObjects()  这个是空吗? 如果不是通常情况下,就是在这里,你可以打印看下。8 q+ g5 v4 h! q. |/ j
. \& ]) s1 Z! U2 \8 k' U
另外一种方式就是生成的feature,通过feature去找对应的子对象
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复 支持 反对

使用道具 举报

SimonLv 发表于 2020-4-5 10:47:20

SimonLv 板凳

2020-4-5 10:47:20

C:\Users\99112\Desktop
- L7 s0 E1 l6 l8 J9 ~/ E 捕获.PNG
' E+ x* Z4 }- e; N( M- X[mw_shl_code=cpp,true]objects1 = divideCurveBuilder1->GetCommittedObjects() [/mw_shl_code]的值一直是两个0,这段是录制jounal生成的,源代码就是这么获取的
% ^1 y$ J# v. D/ y# F
+ q" D; k" {+ l0 B3 ^' `' ]( q我用' O; {) n5 m9 f3 l" l
8 B' v, i& l) ^+ `& G5 k

  [9 [5 N- Y$ M4 @4 a4 X* H: P[mw_shl_code=cpp,true]        Features::Feature *feat1;. ~+ }: ^. a6 G3 e
        feat1 = divideCurveBuilder1->CommitFeature();[/mw_shl_code]' d( A5 @# {; s0 r7 _
代替
% F' X/ w4 `) `/ p[mw_shl_code=cpp,true]    NXObject *nXObject1;
' N! r' u. z& K1 @5 D* d9 ?    nXObject1 = cylinderBuilder1->Commit();[/mw_shl_code]9 g" n5 n; B0 B5 U
也可以分割一条曲线成两条   但是我想用这两条线怎么获取他们的tag??* K  `9 c' _! X% u
希望指点一下?
( n, Y; W6 L6 C) s
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了