PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

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

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

  [复制链接]

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

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

SimonLv 楼主

2020-4-4 23:57:29

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

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

x
我想请教一下大神:为什么我用分割曲线命令,将一条线分割成两段,我怎么得到两条线段的tag,这是录制代码,每到这里程序就蹦了
' Q% d; Z( X  _9 z6 w/ ^$ y: S9 b" P- V( h9 Z* }
    std::vector<NXObject *> objects1;
* D/ X! Z- a. C' _7 q    objects1 = divideCurveBuilder1->GeTCommittedObjects();
5 k0 V* e* @% z* p
# c: G, c( l# `; v$ D% e3 p# O8 s0 C
, B0 G) l. T' e' N0 C8 ~. B( ^" v  T
完整代码如下:4 w3 ~" _) ~) v+ C$ v

, Q, T/ g8 r( L6 Z! K6 a// NX 7.5.0.32
, k; j8 t- P6 O1 s& l( H$ K// Journal created by 99112 on Sat Apr 04 23:13:53 2020 中国标准时间2 a# @" l  b4 u; H' H$ ^5 z, e* w! i
//
- g: E9 i& w; J, E#include <uf_defs.h>
4 e3 E% k6 |7 h5 g8 X#include <NXOpen/NXException.hxx>
3 y2 @% L' K7 `- o; ]4 y#include <NXOpen/Session.hxx>
. M- Q- W9 w. ^/ T% _#include <NXOpen/Builder.hxx>
0 i% W# P5 M" Q, {( v& @: [. n#include <NXOpen/Direction.hxx>2 i! [% ^2 S' K0 U+ t
#include <NXOpen/Expression.hxx>  S. o* J* P, ]; i, y) B) f8 o" I0 q
#include <NXOpen/ExpressionCollection.hxx>
2 z1 {; b4 c; `  z' g  Y" C#include <NXOpen/Features_BaseFeatureCollection.hxx>
( k2 \5 ]: {! W#include <NXOpen/Features_DivideCurveBuilder.hxx>; f# y' f* f7 g5 a" u8 ^
#include <NXOpen/Features_FeatureCollection.hxx>
( b5 a3 n4 V$ a#include <NXOpen/Features_PointFeature.hxx>  c# {/ }$ v- g7 y; `% J9 V) Q0 k
#include <NXOpen/ModelingView.hxx>
0 F0 ^3 G* o0 X#include <NXOpen/ModelingViewCollection.hxx>
6 [$ s# v7 l0 X3 @  v, C#include <NXOpen/NXObject.hxx>5 X7 ?2 H% o# B  T
#include <NXOpen/Part.hxx>& G# y* i% S2 _5 i/ P! {" \
#include <NXOpen/PartCollection.hxx>
; y$ G2 N  \* y: e, Y' u3 j! R#include <NXOpen/Plane.hxx>
2 {# P7 {8 y* }) N( c- G#include <NXOpen/PlaneCollection.hxx>3 k7 M$ ?+ ]6 H! J
#include <NXOpen/Point.hxx>
3 v7 C/ `3 F$ z9 W4 E#include <NXOpen/PointCollection.hxx>" J( e) Y* j2 v
#include <NXOpen/Preferences_PartModeling.hxx>' V- a2 ]8 t, q7 A# k4 D9 X" _
#include <NXOpen/Preferences_PartPreferences.hxx>" ?# F5 i, _! A1 [
#include <NXOpen/Section.hxx>
0 w3 E" i' w6 u8 I& l+ G$ l- m, `#include <NXOpen/SectionCollection.hxx>( d3 p, ]2 Q  G) h; h% }& O0 `
#include <NXOpen/SelectCurve.hxx>
$ w4 B# Q- L, u3 g#include <NXOpen/SelectObject.hxx>5 T$ u6 T, M! S5 y9 g1 Q
#include <NXOpen/SelectPointList.hxx>
& w  D: ~) r+ c; c8 G/ X) C#include <NXOpen/Session.hxx>4 Q( b1 Z: A$ o5 T1 p# u- t1 I) m
#include <NXOpen/Spline.hxx>% w4 |+ o- F, ~) i
#include <NXOpen/SplineCollection.hxx>
6 B7 t% _) v; J. i$ S" g#include <NXOpen/TaggedObject.hxx># n+ T4 m0 t# z( h
#include <NXOpen/Unit.hxx>
* k$ ~8 q' _" A( e2 j7 Y#include <NXOpen/UnitCollection.hxx>
  g  D$ f+ \- g" }, P, P4 e; \#include <NXOpen/Update.hxx>9 u8 d- D, B: j
using namespace NXOpen;
, V& L/ R4 x3 r* w% K: C8 n7 ?- S) B) \5 B- `6 K; B- ~
extern "C" DllExport int ufusr_ask_unload()0 H# t  P" ?8 X8 H. V# p
{" U: o2 I$ C6 H" K
    return (int)Session::LibraryUnloadOptionImmediately;1 {" U' Y* x7 F) r4 p
}# o2 K; T$ x! C
2 q/ x" j6 Y) z/ x3 F  K
extern "C" DllExport void ufusr(char *param, int *retCode, int paramLen)6 d# J" J* H+ d
{  R3 R; X/ [4 s  w
    Session *theSession = Session::GetSession();
' b% c/ F4 o4 G; f* `) k    Part *workPart(theSession->Parts()->Work());
* x. e6 C8 d* M5 p    Part *displayPart(theSession->Parts()->Display());8 g3 r: q$ K2 \4 j% I
    // ----------------------------------------------
+ r0 L- h) m7 h" {. d( Z, I    //   Menu: Edit->Curve->Divide...
4 q+ |2 Z% d6 O. g  H0 A! J1 {    // ----------------------------------------------
% r" _+ u) `4 z+ S! q+ v9 ~8 q4 E    Session::UndoMarkId markId1;9 e7 L7 N2 L0 Q/ {0 _- t7 p
    markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");
/ k. p5 T8 t' `& B8 N0 z2 |, f) J0 ?7 _/ t9 m- y% P6 }) {" I/ s- C
    Features::Feature *nullFeatures_Feature(NULL);+ N5 F/ @6 t9 ?( r: Q0 V

9 ?, o# z4 g8 _- W/ [    if ( !workPart->Preferences()->Modeling()->GetHistoryMode() )
& ?: m2 u8 p4 h$ B/ S) @    {
6 U8 `! @7 k% I" B8 R1 t6 J        throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
9 j+ W! M; R5 o6 |+ h( U    }
; L& {2 P0 P4 M1 @7 ~. f* M0 a
# ]4 l- r( s6 f' _( W' Y$ C* `    Features::DivideCurveBuilder *divideCurveBuilder1;1 R% \2 @" P/ \
    divideCurveBuilder1 = workPart->BaseFeatures()->CreateDivideCurveBuilder(nullFeatures_Feature);
. A9 k3 G4 r$ _; ^
: i+ F5 t, r7 O" }) _    Point3d origin1(0.0, 0.0, 0.0);
  B$ O3 S" `3 e, L  `( x! G    Vector3d normal1(0.0, 0.0, 1.0);- l) d: Y. O& h8 w7 w, Z
    Plane *plane1;0 x% h: n+ X; G7 t) ^6 a
    plane1 = workPart->Planes()->CreatePlane(origin1, normal1, SmartObject::UpdateOptionWithinModeling);
$ U3 E3 b& P) k! p0 F6 ~- S" ^/ r8 ]) o
    divideCurveBuilder1->SetBoundingPlane(plane1);
3 ]( G  Z* _4 s: u0 ^* \4 r  d5 ^. }" K0 U
    Section *section1;
' l/ y, r8 \4 k+ ~6 W, a/ q2 Q* v    section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);# ~8 p- d6 X" R$ G- N

0 N9 {, C  S2 |# [1 ?    Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));$ n* _  K1 E0 k9 O
    Expression *expression1;
) C6 w& t7 z9 v& Z/ e1 V( U2 u" }    expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);; [5 t+ a8 a1 e; x$ C9 r
, t/ N* O4 n3 C
    Section *section2;% j, @/ s+ x; G8 e7 \! j
    section2 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.005);
& }5 ]7 Z! m( B' M3 M- l! F8 Q& i' ~) W
    Expression *expression2;5 m5 J( _; h/ U& N# U8 P, j/ c6 t
    expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);2 X+ O; l/ ~/ L) j
( G/ i2 {  H# d( s
    divideCurveBuilder1->SetEqualSegmentMethod(Features::DivideCurveBuilder::EqualSegmentOptionEqualArcLength);
  q" {. Q7 N( q4 K' S% Y
* D, H* a1 r5 G/ o+ `& x    divideCurveBuilder1->SetEqualParameterSegments(5);
3 Z. L+ J! n* I0 D
" i# l6 u1 E+ ?% t    divideCurveBuilder1->SetEqualArcLengthSegments(5);
5 O! P5 |, B; n$ f4 Y
- n1 e  H0 z$ z% B    theSession->SetUndoMarkName(markId1, NXString("Divide Curve \345\257\271\350\257\235\346\241\206", NXString::UTF8));
: H9 y2 q7 w% x% m4 f
' H7 [# X. U- _! R' X- @$ W  Z- M8 u; A    divideCurveBuilder1->SetType(Features::DivideCurveBuilder::TypesByBoundingObjects);
" n0 ~  S1 Y2 j4 O  n! b% C8 H7 a9 q+ G& U
    Spline *spline1(dynamic_cast<Spline *>(workPart->Splines()->FindObject("HANDLE R-13222")));$ e9 e8 S  i$ Y  m( \) }/ f
    Point3d point1(687.588524265161, -38.7585251796817, 92.0013591828029);
' B6 y% O4 k/ g4 |    divideCurveBuilder1->DividingCurve()->SetValue(spline1, workPart->ModelingViews()->WorkView(), point1);
) n  r. v/ a* a
7 n4 i; k% \9 ~2 i. |% P( s    divideCurveBuilder1->SetBoundingObjectMethod(Features::DivideCurveBuilder::BoundingObjectOptionProjectPoint);
! Z  `! N6 m% R- H- F
# b' z, ~0 i  }, N    Features::PointFeature *pointFeature1(dynamic_cast<Features::PointFeature *>(workPart->Features()->FindObject("POINT(33)")));# L% h: t! \, A$ U: N! e3 m
    Point *point2(dynamic_cast<Point *>(pointFeature1->FindObject("POINT 1")));
+ g0 k( g. r# `# q* N( k4 P4 S/ U    Xform *nullXform(NULL);. a1 {/ a( r" U
    Point *point3;8 [2 X/ O! d6 u, J% w8 u, l# m
    point3 = workPart->Points()->CreatePoint(point2, nullXform, SmartObject::UpdateOptionWithinModeling);
  l6 I: K5 \# s" B$ O9 X# Q# e: H- M* U
    divideCurveBuilder1->SetBoundingProjectPoint(point3);$ y# V- C/ v" C: L8 }0 c
1 c- U5 k9 R' a6 }6 E
    Session::UndoMarkId markId2;# B0 A. H- X0 c! D( b, F6 \7 }
    markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Divide Curve");# c. o0 ?0 J: E; [

# K, p' j% ~: N* P3 [4 @    NXObject *nXObject1;
8 ~3 e% V# X" p( }! t    nXObject1 = divideCurveBuilder1->Commit();
% r+ K+ n' u: k# R3 S0 \- Q1 P
! B% R; |' ^$ F7 ~/ L    std::vector<NXObject *> objects1;  y, g) j! ~( K2 J$ U
    objects1 = divideCurveBuilder1->GetCommittedObjects();" M& I$ O6 g5 D9 V! P

' J8 d+ I' G! k" d% R7 y( v    theSession->DeleteUndoMark(markId2, NULL);" O$ D" E- j3 ^9 U1 ~

9 H; J- m; ^" w6 i% s    theSession->SetUndoMarkName(markId1, "Divide Curve");
+ ^" F; N, w3 ]$ s$ p9 S
( I2 ?! Z* H  Q1 u5 H    divideCurveBuilder1->Destroy();* m, q* y/ a/ }0 t: y$ o! Q

6 Z, w# N; a$ e3 D3 ]    try
. v9 E6 b* R. a+ ], z. j    {
! z) Z# I* f5 ^9 Z        // 表达式仍然在使用中。
( j, M: p' T$ C" T+ o, S5 d        workPart->Expressions()->Delete(expression2);1 ~; M7 a( x1 Z
    }
3 m5 |2 L  t  S' E4 J    catch (const NXException &ex)
6 t- f7 I0 U7 Z$ P' |/ \    {
5 A0 Z( m) O, R) i3 k! i+ q      ex.AssertErrorCode(1050029);
* \  b" T3 V$ v    }  B, T* Z# _4 C" g/ i' B* ?5 q

. N* Q2 g( j- f" P* [+ |% B    section2->Destroy();$ k$ i0 j2 B, W1 P" ]

5 F# g4 _/ R5 z8 T1 L$ V- j( B+ U    try
  r$ S( e' q1 F4 t/ P8 w8 A% X    {
( d$ A2 G$ Y5 `4 k        // 表达式仍然在使用中。( R2 I4 g* Y7 t: Q9 Y/ k/ a
        workPart->Expressions()->Delete(expression1);  O9 ]8 E2 J4 [" f- U3 j8 ~) r/ K
    }
) }1 p. P, Z. F) v( V& w    catch (const NXException &ex)
6 b7 M# I; G. N2 K    {$ h4 n8 G+ d  P) y5 C3 U4 g
      ex.AssertErrorCode(1050029);  A- B) D$ e# k0 T
    }
" J- A" M* @: A8 r
; J- {. J" x9 `! g- _) y    section1->Destroy();8 R( ^( P$ `; N. m7 E* F

# \" {- w! C2 G* a3 ]2 `) |    plane1->DestroyPlane();
9 Z. q8 B. y% y! O; m& b7 _5 E
8 ]$ c( V1 `/ U6 [0 {( u) `& B    int nErrs1;" a( W4 {2 O* P5 {
    nErrs1 = theSession->UpdateManager()->DoUpdate(markId1);2 ]/ T, O% d& d) F! C9 Q( x
+ \' |  D; Z# M) z. ]
    // ----------------------------------------------
: A( q" O- Z$ B0 X9 V: G+ Y. s) _    //   Menu: Tools->Journal->Stop Recording* P2 o3 E' a# A: V6 Z* D3 r% M
    // ----------------------------------------------  p3 @% F+ g. R7 n7 e% N
}
) i5 w; S5 L/ m% @! \- y8 B' o% O/ t( z- C) G6 @( w% ?8 C% z
' V2 [, C' V" n9 o  u% m

# ?$ A$ K7 m; W" m0 v* T希望大神指点5 g, p) R, b0 E* n1 n
上海点团信息科技有限公司,承接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()  这个是空吗? 如果不是通常情况下,就是在这里,你可以打印看下。
" a  T5 m: J5 h+ X# G
+ g% n. }5 O. r5 O另外一种方式就是生成的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\Desktop
  B* P# H4 F: h* ?  J* Y 捕获.PNG 5 {. k! I6 \7 C! U; E* u
[mw_shl_code=cpp,true]objects1 = divideCurveBuilder1->GetCommittedObjects() [/mw_shl_code]的值一直是两个0,这段是录制jounal生成的,源代码就是这么获取的
( ]' ?6 `2 s1 ~2 z2 k+ _- m+ R
6 T% F: I0 L$ {9 b% h我用
. }! u/ S; C" t6 A; b/ U: S; u1 W+ M! K1 H0 q( ]

0 _9 M) j7 k/ r: n1 h' R$ M, d9 q$ I[mw_shl_code=cpp,true]        Features::Feature *feat1;
. s  Y- c( H0 l        feat1 = divideCurveBuilder1->CommitFeature();[/mw_shl_code]
# M  S; }. E5 G& [9 A& \  \9 {9 W  K代替
  S2 E0 ]  E9 A* v[mw_shl_code=cpp,true]    NXObject *nXObject1;2 \5 ?+ o% Z& S( R; R
    nXObject1 = cylinderBuilder1->Commit();[/mw_shl_code]
9 t& i6 @+ q0 e: i) H. q  t* B也可以分割一条曲线成两条   但是我想用这两条线怎么获取他们的tag??+ E  v" `' @3 W$ P8 D5 Q
希望指点一下?
4 Q. d* a6 n: K( `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了