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

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

  [复制链接]

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

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

SimonLv 楼主

2020-4-4 23:57:29

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

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

x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了* z: P% o% S2 {& e8 L

' L, s8 b4 e* t8 u+ g    std::vector<NXObject *> objects1;
+ c$ K" q8 g) z5 k1 {6 a& j    objects1 = divideCurveBuilder1->GeTCommittedObjects();1 E- U$ k: k* _) G

- P$ j5 ]7 X, w2 K0 U; f) W. V+ j* |4 F

, q& i; q1 m3 ?4 y' `+ x4 T完整代码如下:
& @- x$ U9 |1 R6 R& t" |: Z
6 ~; D4 F" c, `. b- U! x  n' F// NX 7.5.0.32
0 U5 A+ y7 h9 g' W# i// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间
6 @  C/ i( o/ Y' _, G//7 s2 T; D' O! E5 D' Z! m
#include <uf_defs.h>
. |; j) Q) h2 E( y/ d2 w#include <NXOpen/NXException.hxx>0 i3 C8 I  ?# c/ X' X7 D9 b
#include <NXOpen/Session.hxx>
; ?+ `5 X% X9 ?#include <NXOpen/Builder.hxx>
, n7 A6 E& u$ E. Q#include <NXOpen/Direction.hxx>
; |: G' {: k. B#include <NXOpen/Expression.hxx>
7 d9 Y1 y6 P& m: i9 F$ U#include <NXOpen/ExpressionCollection.hxx>
& X: u5 e3 \9 f6 b9 l! y- X, V2 C: B#include <NXOpen/Features_BaseFeatureCollection.hxx>
( [. F' \$ i& o' x#include <NXOpen/Features_DivideCurveBuilder.hxx>
2 V2 L: S$ C2 B- O' K. m) s#include <NXOpen/Features_FeatureCollection.hxx>
' A+ I. t, g6 |#include <NXOpen/Features_PointFeature.hxx>0 N3 s+ |$ n: a* Q) x+ J6 e" D5 ]
#include <NXOpen/ModelingView.hxx>
) P0 @4 T0 d3 h* L3 M#include <NXOpen/ModelingViewCollection.hxx>
4 s, ^% j  K. U+ p#include <NXOpen/NXObject.hxx>, n% w3 n0 i: q. [. N' f
#include <NXOpen/Part.hxx>/ W! E6 Q- R2 }6 g$ Q& ?) j$ ]0 H' o
#include <NXOpen/PartCollection.hxx>) X# n$ t0 W3 p
#include <NXOpen/Plane.hxx>  @$ y! B! D% Y# O) q
#include <NXOpen/PlaneCollection.hxx>/ d4 v" e" t6 U4 l( `3 K
#include <NXOpen/Point.hxx>
1 Z, ~; g, l$ n( ]& W- S' B#include <NXOpen/PointCollection.hxx>
) j  X, f5 M0 S, ^- r  V#include <NXOpen/Preferences_PartModeling.hxx>
" B! G1 ]: F5 f& Y#include <NXOpen/Preferences_PartPreferences.hxx>+ d7 d/ J  e/ Y& k; i! q# ~! o
#include <NXOpen/Section.hxx>
# F- a8 r- o( B8 N' T% y- j2 K#include <NXOpen/SectionCollection.hxx>
" ]3 ?) m# C( e* e( n  ]' Z+ Z#include <NXOpen/SelectCurve.hxx>) l! t$ d3 ~: F' F
#include <NXOpen/SelectObject.hxx>
1 R( e9 u0 d( t; s8 r' M3 m#include <NXOpen/SelectPointList.hxx>
9 p6 s; a% E, `. ~5 ]# {#include <NXOpen/Session.hxx>0 J  ]+ a( j! {
#include <NXOpen/Spline.hxx>
, G3 y0 [. Q! C- P1 d$ S. n#include <NXOpen/SplineCollection.hxx>  [; n) Y. ~. y5 I
#include <NXOpen/TaggedObject.hxx>
  I4 }# O& F: Z0 [7 u, L! {4 [: A#include <NXOpen/Unit.hxx>( t; Y6 [3 u" x; F5 V. m+ J
#include <NXOpen/UnitCollection.hxx>" e8 }: |1 `6 S# m- s: O+ _7 _  j
#include <NXOpen/Update.hxx>1 a* D9 V% E, o. m* J
using namespace NXOpen;
9 ?4 D( m' h# X; p! e4 E: D
2 d7 f' o4 Z, @extern "C" DllExport int ufusr_ask_unload()
5 a/ O+ G$ A$ z; Q. j{' W/ {& s9 q$ ]7 \
    return (int)Session::LibraryUnloadOptionImmediately;
; {+ w& r. e2 |+ `; r+ i+ n( z9 l}7 E" s( Y. U) h/ W! v" P" ]% ]

0 H0 c: |  `6 P. ^: S# \! `1 nextern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)
+ F% m; e! E: v. @{( A( Z3 h! i$ @
    Session *theSession = Session::GetSession();
$ a$ j$ R: b, {, t! s1 F) W    Part *workPart(theSession->Parts()->Work());
, C6 `  a( K" A3 K5 e; ?    Part *displayPart(theSession->Parts()->Display());6 W* K- Q2 k  B7 G" `. f! _
    // ----------------------------------------------
2 t  U: k/ \2 d: y6 ]' j    //   Menu: Edit->Curve->Divide...
5 ]( X& A! n( P# }' \5 A0 |# I    // ----------------------------------------------& Z# V8 T& m% K
    Session::UndoMarkId markId1;& o8 W2 Q4 U/ Z$ K
    markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");  t) e, J( S7 V+ F, ]- C
4 X% r0 G( o; _8 i6 H
    Features::Feature *nullFeatures_Feature(NULL);
" r  v7 q. C# f
6 J& B; F$ I% A6 [    if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
, c$ k$ U  C. |    {, u3 g2 u( ]4 F8 J/ J
        throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");3 ^! e0 o% e6 x; _$ l. Q
    }6 x0 W- _2 K$ i$ {+ t2 P% ?0 T

0 i; ~& V* p: B* ]9 Z2 V    Features::DivideCurveBuilder *divideCurveBuilder1;/ b% F2 j# M. B2 y, p0 z- ?4 @$ P
    divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
1 y: G2 y% ]! z9 J$ C
9 V8 `& j- w& o+ ~    Point3d origin1(0.0, 0.0, 0.0);
/ r4 I9 v% n& x6 `5 B- u* P9 g    Vector3d normal1(0.0, 0.0, 1.0);1 j" H; M+ c0 p% c4 g* Y
    Plane *plane1;) H( [) @+ p4 N: _" A' W2 F
    plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
! o9 i6 A; d: Y+ u) J! K
  Q2 l0 u2 o+ L    divideCurveBuilder1->SetBoundingPlane(plane1);
0 b& t5 r+ u+ o8 U' w0 @; F3 J
9 C& m# T1 H8 Y    Section *section1;$ y. g( c2 i7 a2 y( y
    section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
) j/ _6 b5 L3 N% D) a  n
3 G) t  h, y3 p& g/ s    Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));0 ?  m1 p" V$ o" y+ y
    Expression *expression1;
% n1 ]9 G8 K0 Q. b9 J, v    expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);8 y3 z$ s9 y" M4 d( }
8 W; P( h! l, D1 B0 c% z( x: I( j
    Section *section2;
9 ~1 i5 t' }: n( [- |    section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);" Z4 x: d1 }& P7 i* Y/ c

( Y$ X7 o- S. i, D8 _; V: P3 i    Expression *expression2;1 O( A1 d' G. A# y6 [
    expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);& R1 @) G% U% N7 s' H4 z
. M# P" P0 N* D% O
    divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);9 x, ?2 e% W9 h, D, M

- Y1 E0 E2 ^6 e+ W6 @4 @9 R    divideCurveBuilder1->SetEqualParameterSegments(5);
3 T0 ~5 g# D& n% V$ R: ]
- g. e* I7 E: a. F    divideCurveBuilder1->SetEqualArcLengthSegments(5);& Q1 C9 N$ e$ ?) e4 H

) y. y/ E/ v/ L0 _    theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
' O( R6 f2 \" O# X- f: J0 |
6 E4 W9 A4 \: K# I, f+ Z    divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
! N; l( c4 ?, h; i
6 U6 m& X4 n5 e/ D! G) e1 l) d    Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));! P/ O6 O% T" c0 ^  r9 @6 I4 B& ^
    Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
/ T$ L$ y7 I8 d4 W  y    divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);4 L  a2 |/ N) `

2 i( J8 }- U) C+ W8 P. Q    divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);
# r6 i7 r, P$ f) f) v3 \
% x1 W: p- L4 v+ B: y& i1 @8 n4 G    Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));+ ^; i, k! P) ?
    Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));, p9 ?. k/ X" O' w& B2 `5 A' d
    Xform *nullXform(NULL);2 O" F. x+ c6 I, a8 m9 n
    Point *point3;9 n  b; e# Q& t: S9 T# u
    point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
' Q4 ^' z5 o2 ^( S% ]- M0 @$ @, y  D" k( V! @
    divideCurveBuilder1->SetBoundingProjectPoint(point3);
: J6 ^2 \) i' Q2 r5 y% }& {( Y2 w
$ ?7 z% Q; z# j, y) A) I    Session::UndoMarkId markId2;
& ?) o* d  h! B; U9 |7 G# Q    markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");
$ \% x& S6 Q( S$ Q* A: [* P8 E6 F2 X  p: M  W
    NXObject *nXObject1;
+ l, F$ G" F7 s  `  c. v    nXObject1 = divideCurveBuilder1->Commit();$ {$ D" Q. X) |- T

9 j5 Q8 q. M: T/ i    std::vector<NXObject *> objects1;6 B$ y/ z: T. f* [
    objects1 = divideCurveBuilder1->GetCommittedObjects();$ y+ M" D% ^" i2 R
1 L3 j5 N8 `- F& X
    theSession->DeleteUndoMark(markId2, NULL);5 o1 B, B' |* i; Z- a1 }
) L" Q  q$ v* d( @
    theSession->SetUndoMarkName(markId1, "Divide Curve");6 ?7 T# _+ {# O) E( D
, F+ g! F9 ?+ g$ z( h& Y
    divideCurveBuilder1->Destroy();
5 k4 k9 a$ v! A) ^& O. W( P' q) A% W3 b, h& V# d. U6 C  a
    try
& o' H9 t" Y9 u2 W$ D8 z    {
) {' y* }, g8 i/ G/ S        // 表达式仍然在使用中。2 Y3 j5 G: e7 \  w
        workPart->Expressions()->Delete(expression2);
% @: j+ U$ B7 g$ w    }
1 Z, X' ]- e/ e0 W0 O0 ]3 Q    catch (const NXException &ex)3 a8 ~! M  F$ B
    {) N# b# q$ P' w- ?% X
      ex.AssertErrorCode(1050029);, X5 K2 h7 \8 ^: v1 k
    }
. ^8 G% @" w7 @" O2 P* X
& Q: S" ~' c/ T    section2->Destroy();, j) Q8 n! ?& E* Y; c
  M/ U. J* s2 C+ T
    try# C$ Y/ ^' Y! y1 F4 o' t
    {' ?! y; Y) _. I
        // 表达式仍然在使用中。
7 q/ x9 l  R5 }# _5 T4 r# O5 v        workPart->Expressions()->Delete(expression1);
, w9 h% Y6 a$ J. c    }
9 p! W* R  J# o% ]! ^2 [- @- T, k    catch (const NXException &ex)
% c  V) p2 P+ I9 F% x2 a9 H    {
% t# _; M3 Z. M8 @      ex.AssertErrorCode(1050029);
: ~) u1 f0 k- n; S( p. e% ]6 r    }
  s) Y3 s0 x$ B) x' L! A4 M- i( a! N" r2 e; P( r
    section1->Destroy();
0 `+ ]2 R/ v: y1 D
6 n$ o* h3 ~: f5 w    plane1->DestroyPlane();
. O8 O5 B( X9 c& x
4 |7 ~% l; K' y- ~    int nErrs1;6 E6 K1 [9 I  M0 T7 e
    nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);8 _5 w6 g# T, f0 a9 q

& `7 U1 H. b0 q; N( {    // ----------------------------------------------7 @8 C& F! j4 _* j, Q% E
    //   Menu: Tools->Journal->Stop Recording3 i5 W/ Q! B6 y% M
    // ----------------------------------------------) N2 t: _7 R1 \. m" G5 u
}
. S; W3 L. e$ G0 N7 ^# H
# }  D, p3 t, P- ~  A
- s. \" p0 ~6 c  W) A  B, t$ T2 x  h/ c1 I1 [
希望大神指点% \5 X% c  i9 W9 H
上海点团信息科技有限公司,承接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()  这个是空吗? 如果不是通常情况下,就是在这里,你可以打印看下。9 ^% ^2 {4 O5 e4 D* A

! S* v; j8 Y6 x' |: [另外一种方式就是生成的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\Desktop8 i+ v( E2 X' W0 I+ B6 p
捕获.PNG # @: l' y- a# J* T
[mw_shl_code=cpp,true]objects1 = divideCurveBuilder1->GetCommittedObjects() [/mw_shl_code]的值一直是两个0,这段是录制jounal生成的,源代码就是这么获取的6 r# q3 Z: s1 r, J
) e6 F; J$ H4 o6 y$ L
我用
$ g$ ?/ D7 n3 V2 A0 K) d$ b# L
4 ~' \/ b" c; M; Q- b! R4 G
[mw_shl_code=cpp,true]        Features::Feature *feat1;0 r, H( n, S* G$ w
        feat1 = divideCurveBuilder1->CommitFeature();[/mw_shl_code]2 ~# y1 K5 ^! ]5 I- ?: C
代替3 |% W/ @+ h9 j* F0 Y+ p
[mw_shl_code=cpp,true]    NXObject *nXObject1;
: Q& Y# S* G' L6 m" d    nXObject1 = cylinderBuilder1->Commit();[/mw_shl_code]
6 S) Y9 R/ t  F也可以分割一条曲线成两条   但是我想用这两条线怎么获取他们的tag??
, X% V7 ~4 K. `) J3 X希望指点一下?0 K0 w: y$ y, D& ^
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了