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

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

  [复制链接]

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

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

SimonLv 楼主

2020-4-4 23:57:29

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

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

x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了* @3 h) L# g0 X+ [
4 F5 u" a" |2 y, |2 j$ C
    std::vector<NXObject *> objects1;
4 |/ I; ?% \4 g* f% L    objects1 = divideCurveBuilder1->GeTCommittedObjects();
. h% Q  @/ [: }) |0 ]! z5 l) b# v- {2 g" B* o

3 \8 C; I2 M8 B) Z" b
! x6 G9 d1 F- [- m0 q完整代码如下:
8 J; K2 Z" E- R; n9 o
5 P. W, u/ t3 I4 z) {// NX 7.5.0.32  A% `' |4 s$ U1 k: g* p8 p
// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间0 d$ p4 G8 R* Z* \; Z# D+ a( l
//5 z9 K( y0 h" n/ c
#include <uf_defs.h>
' ^7 h6 ?7 C: F+ V4 z7 C/ X, N#include <NXOpen/NXException.hxx>6 k3 l' V' o2 `; N
#include <NXOpen/Session.hxx>! u  P" e4 \% K% j
#include <NXOpen/Builder.hxx>
; a; T: y5 ^% h#include <NXOpen/Direction.hxx>/ T4 q# H$ {4 d- B2 v/ R+ _
#include <NXOpen/Expression.hxx>
, n: X+ h% ~0 ^, }#include <NXOpen/ExpressionCollection.hxx>7 ^% z# r3 e2 z
#include <NXOpen/Features_BaseFeatureCollection.hxx>, P# U8 K7 m$ {' \: s  v
#include <NXOpen/Features_DivideCurveBuilder.hxx>
" P: @) t) s1 K2 R4 D" Q- F#include <NXOpen/Features_FeatureCollection.hxx>1 l4 ~: e- Z( \' e% Q8 R
#include <NXOpen/Features_PointFeature.hxx>* n3 Z9 V( \7 q( h
#include <NXOpen/ModelingView.hxx>
+ V- U8 Q, G4 U: m4 c#include <NXOpen/ModelingViewCollection.hxx>
, N& C$ i% M7 i8 H2 g, u#include <NXOpen/NXObject.hxx>! @# _% w# B! _. g6 ~+ d9 \
#include <NXOpen/Part.hxx>
- Q7 a" P1 ]! \0 v#include <NXOpen/PartCollection.hxx>1 c  |( J2 l6 ?! {& A2 u% [1 A  f
#include <NXOpen/Plane.hxx>
2 m' R. V2 e7 u7 Z#include <NXOpen/PlaneCollection.hxx>& f! V7 {* Q7 `6 v% N
#include <NXOpen/Point.hxx>, N, x0 Y: C2 Q8 _4 l( c
#include <NXOpen/PointCollection.hxx>8 w6 r$ j$ w) A; _; j3 B* ^
#include <NXOpen/Preferences_PartModeling.hxx>
. a0 T' r5 y+ O! b: g. v; @#include <NXOpen/Preferences_PartPreferences.hxx>4 W" D! U& [& }, I
#include <NXOpen/Section.hxx>' R9 U4 R) m* X. E& k
#include <NXOpen/SectionCollection.hxx>6 N0 q8 i0 X/ h; s$ o5 g+ \8 D
#include <NXOpen/SelectCurve.hxx>
  r6 B- Z& w% T9 z2 Z#include <NXOpen/SelectObject.hxx>
% ?) x: e1 k' _#include <NXOpen/SelectPointList.hxx>! d% l! h: X+ Q: i- ^
#include <NXOpen/Session.hxx>
. X% ^0 L! ?7 A6 r#include <NXOpen/Spline.hxx>9 R* O7 C; d) p$ i+ T* p4 \, x7 q3 M
#include <NXOpen/SplineCollection.hxx>8 i# s( K( w! v0 A! p
#include <NXOpen/TaggedObject.hxx>% z3 Z) R+ l& l: d1 m& e8 t( d5 E
#include <NXOpen/Unit.hxx>' N; [, U4 q$ M& {! [
#include <NXOpen/UnitCollection.hxx>
- k) W# `! e1 y4 b4 [9 H#include <NXOpen/Update.hxx>1 m! y+ u( G3 {) Y- \
using namespace NXOpen;) m: G% S! r, T8 ~( @% a; F& j

& k* m0 J7 Y" k( Q9 U! Eextern "C" DllExport int ufusr_ask_unload()
, f8 [1 x4 W. t" x% Y1 }{
( l, n: t& U% k9 w    return (int)Session::LibraryUnloadOptionImmediately;7 {/ E, N6 s( t: [3 b% X7 x' f
}
) L. ], z& A4 d1 B. O. \
) h1 \# C6 P5 u; u( E" U3 textern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)' L$ l) ?* ?+ m3 c
{: N7 O& P( W0 q
    Session *theSession = Session::GetSession();; m2 C6 r* o" P! p6 z/ c  @
    Part *workPart(theSession->Parts()->Work());/ L8 W6 `5 K  M9 n, x' i4 g: v
    Part *displayPart(theSession->Parts()->Display());$ F. W+ C" R! f
    // ----------------------------------------------9 w! b5 G- u8 o% @, p3 w
    //   Menu: Edit->Curve->Divide...4 ?( H# N9 n1 @2 e; ~. t  I& ~
    // ----------------------------------------------* G# K& `# s9 |/ q; ~) L! f: F
    Session::UndoMarkId markId1;5 a# {3 b" C# E: C  a4 @  s. A
    markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
. h: r4 K( k3 c7 s+ X2 p+ I: w3 U1 y$ [7 M8 I5 o& {
    Features::Feature *nullFeatures_Feature(NULL);
& _$ b* I% f& o$ k3 b2 I3 u/ K" h/ \" d0 S  z
    if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )4 A* v$ u! Y2 {3 B* }& W" `0 C. R
    {9 U7 G! c, e" P' X; C7 r
        throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");3 m  a" J! e* J6 |# ?1 r
    }. E! x. _0 f2 \4 c! h' ]
8 ~) B# x8 P  r' z
    Features::DivideCurveBuilder *divideCurveBuilder1;% @% Y7 G) @% N7 r
    divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
$ `) W7 ^4 y1 N, f- i3 B) G* K5 x) x! F- `9 D
    Point3d origin1(0.0, 0.0, 0.0);( y) b( j: N& x5 ?/ s
    Vector3d normal1(0.0, 0.0, 1.0);
: H" [/ @: P. E    Plane *plane1;: _  y. p+ N8 m8 l* A( o9 v, n
    plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);1 z/ e5 D: B& a$ s; O$ d5 W; ~- s

. h) `2 a# ?) B    divideCurveBuilder1->SetBoundingPlane(plane1);8 Q0 {2 J; k; X  U; \+ S* m2 q

; p" F7 v* f+ @) C    Section *section1;: ~. m3 ]  b5 C3 L
    section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
8 ?; ]5 R  [& Y/ o
4 r4 u: B7 b% G/ @4 s' l8 w    Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
; t) _" Z6 c* l    Expression *expression1;; {6 b: K8 A5 k4 [. ?3 Q% ~
    expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);( I) c( Q% P3 T# Q# C% L
6 P" p, T/ m1 ]4 ^3 k
    Section *section2;
* H: o' @7 x* ^8 O2 E: X- S. _    section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
  A7 `% I/ i1 y3 n  q6 E- W% x
( s6 d  i& v* k" p    Expression *expression2;* a7 ]1 l6 c& L' P, \
    expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);( d# L5 l- K+ Z- c0 [4 R
! v& Y6 U2 M& }9 R7 f
    divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
+ |7 ^+ M2 y, t5 `. \) P3 h$ s& Y, E5 }2 I. _! _
    divideCurveBuilder1->SetEqualParameterSegments(5);; U5 z, s5 {2 [: v3 |* Q

( Z9 v3 X* C3 U& _, r    divideCurveBuilder1->SetEqualArcLengthSegments(5);0 l$ V0 W/ r- e, Y! F  F+ w
* q: q" j1 d/ k; r9 {% o; T
    theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));/ C7 f2 T3 N3 z) `1 ?# Q

1 r: Z9 z2 U$ D/ b  D8 H    divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);# b4 D9 F9 X$ M) A( b5 P2 c' h
8 r/ S6 o! S  Z6 j% D/ S
    Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));
4 Q) ~" [# l$ x7 u    Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
7 G: i. s) @4 h  z, e    divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);( v, H; u$ s( m1 u. K7 M0 q* R/ \& T

' C, L9 G" l( t; ]    divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);
; m7 W. I# K# z: u! \8 L+ f7 X" T2 `+ @: j9 H
    Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));
( c1 p9 {) v7 e    Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));: s0 I4 d2 h9 b1 _6 F
    Xform *nullXform(NULL);
/ {1 d: g& O; p8 r( h" S0 Q    Point *point3;
& z- e, l) D% r' N- v, J4 E    point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
* n1 t' `8 v* O9 R/ x; s* g3 v+ J; ?6 I! h' C' {  {7 m; _
    divideCurveBuilder1->SetBoundingProjectPoint(point3);
* Y$ G5 p6 ^, H3 R, a5 X* Y+ @4 K2 l5 z2 C
    Session::UndoMarkId markId2;7 _" P2 J9 m  _
    markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");$ f4 B8 @5 `( t# |- m5 _

8 k% F3 \+ S, U# U+ z    NXObject *nXObject1;
- \! R; J$ D  u  o& [    nXObject1 = divideCurveBuilder1->Commit();) J5 w; h% l6 L% r' f' U* V
4 D2 c" F! L& i4 N# L0 ?( |
    std::vector<NXObject *> objects1;% [5 g5 m2 n$ p( U" z6 W
    objects1 = divideCurveBuilder1->GetCommittedObjects();
$ z* B* a, H/ }+ s0 y/ M9 V$ ]6 O
: T1 c- X# m& Q& @+ ?! {4 P1 S    theSession->DeleteUndoMark(markId2, NULL);
8 O3 u/ u- `" x: S+ K
7 O$ U; j$ J: s, i/ Y    theSession->SetUndoMarkName(markId1, "Divide Curve");" Q' Z" O' b+ a  i  \% ~/ [  h
# d; R1 P! o) p7 P" l
    divideCurveBuilder1->Destroy();% R  y) E* K  n$ e" v% h
# p) @  K3 ]! c9 r$ c, ]. }8 ~6 k3 M
    try7 j4 O  n' K/ s% \7 Q& |  v6 c
    {
" g" ^' ^5 i) j' J  @        // 表达式仍然在使用中。$ N7 f- Z, }8 t8 E6 C0 Z* a/ {
        workPart->Expressions()->Delete(expression2);+ R* R* n7 G3 }/ t1 g* \( b; ]
    }! \4 c4 d* }1 s
    catch (const NXException &ex)
# o/ N& s1 Q3 A7 h$ X" l0 h    {
% A& ~. Q, ~0 w8 U8 k* Z) f      ex.AssertErrorCode(1050029);, ]. X0 k3 ]# C& J5 W
    }8 H3 n" n# C1 \
! {& [, ^' E6 w8 N+ E. ^
    section2->Destroy();1 c  s" Y2 z! i0 O& a( ~
- N7 W& ^7 N7 S- j
    try
8 R/ Y8 p( s) s& O5 R    {+ @% t1 _% D. P+ W% p7 d
        // 表达式仍然在使用中。. T$ A& c3 W6 J0 ]: ^1 G) ^
        workPart->Expressions()->Delete(expression1);) ~/ J# j' `& W8 T" b% G
    }
% l$ B1 y# k! X3 i    catch (const NXException &ex)# e7 H9 z8 W7 H+ `5 l" U6 |. o
    {1 f. C9 S1 u& i8 ^0 t3 R
      ex.AssertErrorCode(1050029);
2 ^5 I. z( q# N! Y    }" j1 ^" p. ?7 K" W# ~
: p6 i/ X5 b9 W) B) d) s
    section1->Destroy();
* g, C* _% q: g' h9 C9 Y! j; a# \6 |/ p2 e/ I: c
    plane1->DestroyPlane();
' v" Y5 e$ h3 K5 p0 l+ j
% t* [6 d7 y0 x1 q- s( x    int nErrs1;- E: L0 v* J7 z
    nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);
# l* c# o9 j2 Z' a# I  ^
; q, |" r, ]/ O! H/ r    // ----------------------------------------------
8 s5 b2 i3 m) {6 Y    //   Menu: Tools->Journal->Stop Recording
" _4 Y6 _: }+ i" W- _0 \2 M! t    // ----------------------------------------------
- h/ H" U0 v# m1 @% j9 R}1 Z* C' U+ a* n; n' M
1 ?* Z# G- T! s1 k/ ?& o! _

. z; b* I6 Q3 Q1 N) |& Z. R8 a7 k' E1 T
希望大神指点
" e& X) ]* N, P) E) G6 X" I8 X
上海点团信息科技有限公司,承接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()  这个是空吗? 如果不是通常情况下,就是在这里,你可以打印看下。4 A# Q& H4 r! V' n0 F1 M
8 Y5 q. S" w4 m* [" T
另外一种方式就是生成的feature,通过feature去找对应的子对象
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

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

SimonLv 板凳

2020-4-5 10:47:20

C:\Users\99112\Desktop5 n. u2 u+ ]- f' u2 t
捕获.PNG , }3 g* M7 @/ w% D) [$ W, ~. `
[mw_shl_code=cpp,true]objects1 = divideCurveBuilder1->GetCommittedObjects() [/mw_shl_code]的值一直是两个0,这段是录制jounal生成的,源代码就是这么获取的! r' i9 f, Y( w) g( B- X! w5 J
+ S* P5 z6 h9 R( w8 _+ B
我用8 c" e+ {3 r1 e/ R3 I# u  A+ N
: I' r8 M& F+ c2 o$ G. V% d  M
- @" T' y) D9 R( }' f
[mw_shl_code=cpp,true]        Features::Feature *feat1;! b5 m- j% T3 \1 X
        feat1 = divideCurveBuilder1->CommitFeature();[/mw_shl_code]3 }% E$ ?0 }# A0 h! X$ C1 z( G& |
代替
$ t. F9 L7 _* A2 F3 @* y[mw_shl_code=cpp,true]    NXObject *nXObject1;) }8 b5 h. C, n# s" K4 B
    nXObject1 = cylinderBuilder1->Commit();[/mw_shl_code]
3 a5 P3 E# e* l: P; d5 }$ n- ?也可以分割一条曲线成两条   但是我想用这两条线怎么获取他们的tag??
& W5 w: B% q8 n2 h* t' m希望指点一下?: x# v- q5 \! i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了