PLM之家精品课程培训

PLM之家精品课程培训

联系电话:18301858168   |   QQ咨询:939801026
NX二次开发培训

NX二次开发培训

UFUN/NXOpen C++和实战案例

适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术。
公众号二维码

关注公众号

点击扫描二维码免费在线高清教程

课程详情
Catia二次开发培训

Catia二次开发培训

市场需求大,掌握核心技术前景广阔

Catia二次开发的市场需求大,人才稀缺。掌握开发技能潜力巨大,随着经验积累将在汽车、航空等领域有所作为。
B站二维码

在线原创B站视频

点击关注工业软件传道士主页

课程详情
Teamcenter培训

Teamcenter培训

全方位培训,从基础应用到高级开发全覆盖

涵盖用户应用基础培训、管理员基础培训、管理员高级培训及二次开发培训等全方位内容,由多年经验讲师打造。
QQ群二维码

加入同行交流

点击扫描二维码加入QQ群

课程详情
×

PLM之家plmhome公众号

课程涵盖: PLM之家所有原创视频

×

关注B站视频

所有高清视频一览无余,全部在线播放学习

×

加入PLM之家QQ群

同行交流,疑问解答,更多互助

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

[原创] CATIA二次开发入门教程---16 通过点击屏幕创建线

[复制链接]

2017-5-6 14:18:38 4036 0

admin 发表于 2017-5-6 14:18:38 |阅读模式

admin 楼主

2017-5-6 14:18:38

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

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

x
CATIA二次开发入门教程---16 通过点击屏幕创建线
4 s7 w1 O+ g$ K# X
! D( W7 M) M9 w* O1 ?和上面例子类似,这里需要手动添加一些action事件,在头文件里面新增加一个 indication,效果如下3 y; Z. i: ?- q/ O1 n
create line.PNG & W0 p& V% I) w. n- }! p' X

. c" }+ Q1 d4 P: c% |/ b1 m$ X代码如下:+ d$ t5 I3 x5 X' t0 ]; \

: f& Z- _. [. k3 ~2 ~6 N2 t' ^5 s4 u" d9 ]: _7 `
//-------------------------------------------------------------------------
# u# v, w7 _, E+ R4 d// Constructor
! M! V/ p/ _" j7 i//-------------------------------------------------------------------------
5 l9 u' `3 P" B0 y& P$ J. xCreateLineCmd::CreateLineCmd() :
6 a. [! ^0 ]# M- M2 a  t( n  CATStateCommand ("CreateLineCmd", CATDlgEngOneShot, CATCommandModeExclusive)
$ U1 C" ?8 m/ |7 |1 _//  Valid states are CATDlgEngOneShot and CATDlgEngRepeat; z3 \  E. R; i* ^  q3 V
  ,_IndicationPoint1(NULL) ,_IndicationPoint2(NULL)7 z( q: ^3 A) b
{
) p7 F" B; k9 o% h5 t2 R}
- [( W; V& f  B( B2 f6 m  O//-------------------------------------------------------------------------
1 u! r8 @5 g3 B9 X// Destructor
/ n# j) H. S6 p6 d//-------------------------------------------------------------------------' [3 G4 `8 x! J% d, R" n
CreateLineCmd::~CreateLineCmd()
3 S/ ?9 ~. F4 {5 d4 p' Z{
; R8 ?" e1 Z- d% `" @, i8 |9 t$ L   if (_IndicationPoint1!= NULL)
/ @( h' ~. `* M6 f( E3 S      _IndicationPoint1->RequestDelayedDestruction();9 {6 p4 e0 J; W6 t2 v
   if (_IndicationPoint2!= NULL) / X, K% m; s+ U
    _IndicationPoint2->RequestDelayedDestruction();
% |; C9 T1 F) ~7 i/ v7 r" R9 [& s8 R* q( d; s% A
}
% R) L2 D8 b2 @
$ ]5 M, E/ F% y9 |# u9 O0 S//-------------------------------------------------------------------------
1 u* Z- z& k2 Q1 n0 e1 }7 |// BuildGraph()
' D# [$ `- x7 u; u) J: f) V//-------------------------------------------------------------------------
; U7 Y% b2 K0 y; ^  [+ o6 f- Avoid CreateLineCmd::BuildGraph()' U5 w3 R3 ?8 G2 `- p* k
{
7 \$ N; c8 g6 n5 i) A. d$ a0 t6 Z2 [. Q* Y, Z
  // TODO: Define the StateChart
  L! i3 k# e  V% Z9 G. f9 E  // ---------------------------
8 _8 }- }6 z2 f9 q  _IndicationPoint1 = new CATIndicationAgent ("IndicationOne");' I# r0 r  N* r# B
  AddCSOClient(_IndicationPoint1);* K- l, q7 |. v$ Y7 A
  _IndicationPoint2 = new CATIndicationAgent ("IndicationTwo");
3 g& `9 x( ?8 w8 W1 Y  CATMathPlane PlaneXY;/ b) V0 \$ d+ @% f( S1 Z5 }. @
  _IndicationPoint1 -> SetMathPlane (PlaneXY);
7 @" Q# L6 o" L( ^" b( e  _IndicationPoint2 -> SetMathPlane (PlaneXY);
7 ?, k5 D9 F) F  CATDialogState * initialState1 = GetInitialState("select first point");, ?) L; I7 ]. u8 u
  initialState1 -> AddDialogAgent (_IndicationPoint1);7 n0 {- {5 Z$ J" ]  I! V

0 d: n7 G: S) O' }! Q' E  CATDialogState * initialState2 = AddDialogState("select second point"); // add important. t( ?0 w. I( z9 z
  initialState2 -> AddDialogAgent (_IndicationPoint2);
7 T' {8 b4 d$ H5 M+ F% t" p  O4 v& s0 I: t( l% l2 V/ a" o
  . g3 I& n$ U  f" a
  AddTransition( initialState1, initialState2,
5 k" m( u5 W, n/ b7 u3 \                 IsOutputSetCondition (_IndicationPoint1),
5 m! k8 O5 D3 L5 t1 y' n                 Action ((ActionMethod) &CreateLineCmd::ActionOne));6 S/ A& z7 g1 O5 |* m) {* J! S

3 Y2 ~% i( u. X3 {8 c/ l3 [  AddTransition( initialState2, NULL,   p+ Q9 C; U# L% {/ R
   IsOutputSetCondition (_IndicationPoint2),
7 D4 g- z* U, s   Action ((ActionMethod) &CreateLineCmd::ActionTwo));  a; N  H6 q6 L9 m- Q
}" }; B3 D. f/ e

* H# ~+ s3 v8 j, o( U8 M0 {//-------------------------------------------------------------------------
5 E6 c. c  @5 ]// ActionOne ()1 ?5 d( D6 J' t7 R! m6 k! e9 U: {4 i
//-------------------------------------------------------------------------
! b- i' f1 v  C5 \, }( dCATBoolean CreateLineCmd::ActionOne( void *data )
0 v( u' R& _% g+ E{/ F' H" @1 o# y' l1 X$ `1 k
  // TODO: Define the action associated with the transition
$ g9 T, U/ ^4 j# Z* k8 P, w  // ------------------------------------------------------
- t; N/ o) ~0 H& y6 F0 C7 u  CATMathPoint2D point2D = _IndicationPoint1->GetValue();//获得一个2D的点; i3 L1 u  j' f/ c
  CATMathPoint Point3D;" t. M. G% y1 Q5 a7 |4 V
  CATMathPlane Plane = _IndicationPoint1->GetMathPlane();! r0 L) d+ n9 C
  Plane.EvalPoint(point2D.GetX(),point2D.GetY(),Point3D);  //将2D点转换为3D点  {. \  G. v4 Y5 |# u
  //设置Container(非根节点)# R$ U: ]2 Y, Z4 l; d$ g2 y
  //获得Editor
- d- V$ ]& c1 T3 x. X! p  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
5 [5 n  m; |! q7 ]9 f8 v. C  //得到当前对象的文档
: A8 F! p) L. n1 D; f* d  CATDocument * pDocument = NULL ;
! g+ W! Y# E# L+ y  a2 o' D  //取得当前活动对象% A% W# W6 t8 W! J2 r( o/ N7 ]
  CATPathElement activePath = pEditor->GetUIActiveObject();9 Y+ M# @/ a- I
  //取得当前活动的product
' ]: o$ l' x' C% P/ i  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
" R0 u5 h$ q5 ~; O5 Y3 G  //当前活动对象不存在3 ~) {8 w: H/ a5 P
  if (pActiveProduct == NULL)
! b4 f2 g0 U; D4 c, W  {3 m2 K9 d0 [& l* v5 J, i
    pDocument = pEditor->GetDocument();
  D$ s8 p$ B7 E4 B( `  }
7 V6 A' n" Q2 Q  else
, U( K& l  q6 S9 \  {! I; U8 S5 d: l0 v8 x/ X
    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
/ h- i: x& l7 ^    //当前对象的引用对象是否存在9 |9 K) a4 z6 a
    if ( NULL_var == spRef )
7 ?0 X6 L2 r! {! F. i/ g5 D    {
6 o8 ^& W8 C! ~* [2 {( N% T: q      return FALSE;1 W1 `  q5 c$ l/ M: B( f
    }/ ]7 n& r7 n' u$ V
    //当前对象的链接对象
4 q8 h2 g; q8 n0 n. g    CATILinkableObject * piLinkableObject = NULL;
5 c- \- J+ k( [0 Q, ^2 j    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                           
. y* z& t& m4 u    if ( FAILED(rc) )& r/ @6 Z5 A3 q! b) u! h
    {
+ J4 [# x: F/ R' t      piLinkableObject->Release();+ c1 S, i  ^" t4 h0 P" S; p( A
      piLinkableObject = NULL ;
% \7 \  m8 y) W      return FALSE;- Z$ S4 p6 v2 h
    }
; ~; j4 f- T% X    //得到当前对象的文档% T- ^) @- e) [# b# I: |$ ~- k
    pDocument = piLinkableObject->GetDocument();
+ G- N2 E* _% I6 e    piLinkableObject->Release();
! I, ?0 K$ N" _3 z& {: m& B. ^    piLinkableObject = NULL ;
) W  n' o% p0 y5 d5 V% c% j    if ( NULL == pDocument)
* j$ N. F" c3 F# T6 p5 ]+ }    {6 E/ r1 ^8 t' X- D
      return FALSE;
; d( \2 R0 x( ~6 t    }4 p( z. F8 |; q& B% c9 r
  }
" S. q+ T7 |1 F5 A  //得到文档容器集' o& E0 ~% B) [4 D. X5 \, O& n
  CATIContainerOfDocument * pIContainerOfDocument = NULL;
2 D; x, ~- d( P2 N* q  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
) \, k; U9 r) X  _( W  if (FAILED(rc))1 t! a' I/ \" C' |( `' e
  {
8 \. j5 G  y2 H    //pIContainerOfDocument->Release();
% H3 J# |$ N# a" M6 L! \7 S' \    pIContainerOfDocument = NULL ;4 L8 y9 c* @8 q7 o
    return FALSE;
# o! E& p( ~- f' g  }
3 \% I1 Q! a% r) ?$ \/ G  //获得Document
* J3 V3 D- n2 n3 l. S$ `  CATIContainer* _pContainer = NULL; 6 O4 S7 `, Q9 N- y( w( a4 q
  //获得SpecContainer
1 x% `% i. C1 [7 T! D% \! F  v  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);: R) o& H- L% r& t) l8 [) q
  cout << "container ok" <<endl;2 {  d' o0 L/ k! S/ h" O

3 _: t( T% S/ {8 C7 p' a. ~  //GSM工厂
5 x4 w; O7 A+ ^  I/ |9 T2 L. y  CATIGSMFactory_var spGSMFactory = NULL_var;& v5 m5 X; a: h
  //设置工厂  : r$ _) Z& V/ L; h
  spGSMFactory = _pContainer;         , M1 b$ B3 q4 ]( u- N  P* C% E
  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(Point3D);
" w2 v1 b# Q+ N; T9 a- T0 U& N, x  spSpecPoint1= spPoint;     , r, M8 d: u8 m
  CATIGSMProceduralView_var spSndPntObj = spSpecPoint1;6 \/ i* Y0 j5 g3 p9 i( s* Q
  //*将点显示在屏幕上; \( T' X5 Z" G
  spSndPntObj->InsertInProceduralView();
& M  V  s* W) {- L4 F7 O cout << "create point ok" <<endl;
9 \% _/ \; K! f1 W  spSpecPoint1->Update();
# F* g8 L  ]. P! U7 Acout << "update point ok" <<endl;
$ j1 Z+ ?" P( W& c; p4 j# y& s  return TRUE;4 g1 d( i0 [. p  m* x2 m
}
2 {% u) Z, k; c: B6 G+ ^1 u2 o! U( N# _. s4 \! O

# r. W5 x& h  {$ |/ \  V% Z* v& v
( f, r2 o! A2 UCATBoolean CreateLineCmd::ActionTwo( void *data )
+ x6 A; o" N) ?/ P{: z# L# }( L' g( ^
// TODO: Define the action associated with the transition
3 ?' L, S* q: ~) P" h/ p2 r7 p // ------------------------------------------------------/ C! u( K) d; A$ I3 _" {5 {
    CATMathPoint2D point2D = _IndicationPoint2->GetValue();//获得一个2D的点( Z/ P9 a2 l! Y0 @8 `+ i
  CATMathPoint Point3D;
- `' O  v' m" [% P! P& ^: p  CATMathPlane Plane = _IndicationPoint2->GetMathPlane();: N, \  d" {5 C
  Plane.EvalPoint(point2D.GetX(),point2D.GetY(),Point3D);  //将2D点转换为3D点
# J1 K) f+ A4 X  //设置Container(非根节点)
( @, ]8 s$ A6 K* o+ {1 E, ?  //获得Editor
* r+ L. ]9 S* ?# b# K  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();: v0 i( w8 Z4 N5 _  l& w3 f2 ]
  //得到当前对象的文档
% ], d4 v3 [8 A2 N6 y* z  CATDocument * pDocument = NULL ;
- Q" O/ b( R' [" N( J7 c3 f& Y; h2 l  //取得当前活动对象' L1 T- Q" m$ X5 d) F) d
  CATPathElement activePath = pEditor->GetUIActiveObject();; G$ ?% {, ~& }& C2 f" S* b
  //取得当前活动的product
3 X: R, v9 Y$ r4 {) m  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());" J, w: k% P  _0 _$ E
  //当前活动对象不存在
' a. b2 Z$ [4 Y  if (pActiveProduct == NULL)9 c$ C2 A! W% ^0 |
  {* u" k. R1 I- j
    pDocument = pEditor->GetDocument();
+ e( U1 K/ W- L  }
& h! i# q. ?8 S0 b1 m+ _5 i' o  Q  else
& j6 z& t: V3 [5 P0 \# Y0 a3 c1 `  {
( p1 k4 \8 |4 A( ^    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();( C0 l/ S$ k2 T* v9 \+ F' a' j
    //当前对象的引用对象是否存在  ~- ?% U3 \* h$ W5 K
    if ( NULL_var == spRef )  ^9 t7 R# n8 x2 i
    {
7 M% }" `3 n4 l' a/ o2 u: \$ g% G      return FALSE;( _  g7 e* o( n/ N5 x% l
    }9 e2 ]# ]3 o, y" M' j! @7 X) V
    //当前对象的链接对象
% @& n# K4 Q$ {+ h" M' u    CATILinkableObject * piLinkableObject = NULL;
0 j1 K0 Q' r: V' p" E2 K9 q. i    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                           
4 D6 v( {5 w# g7 t/ }5 U    if ( FAILED(rc) )  t7 {& Q+ t: b
    {
8 R0 B" ^  X+ l4 ~: y, |      piLinkableObject->Release();1 k0 _& H8 C# I
      piLinkableObject = NULL ;
: K7 r2 M4 |1 F3 [      return FALSE;) w6 T! j  x* V* v) F
    }  [1 v4 q$ S' V
    //得到当前对象的文档3 a+ Y! b' i' ]. \! s+ k/ F
    pDocument = piLinkableObject->GetDocument();# z& W0 U4 u# B' i$ S3 s$ S
    piLinkableObject->Release();
' `; m/ K  R9 c( O4 a    piLinkableObject = NULL ;. H6 V% Q! M! a
    if ( NULL == pDocument); ?. c3 n/ `! _2 `# x: I" x
    {% j9 R8 u0 c2 v$ m2 J* Q
      return FALSE;
4 l! J, m0 K2 g# g3 d$ T    }; n5 \  d" g. b
  }; ]- R* M: `" g2 k
  //得到文档容器集, k0 d0 _6 |5 M: o  d
  CATIContainerOfDocument * pIContainerOfDocument = NULL;
- s' i4 {# A* j3 X5 @% i& W" B  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);# I/ `" @( ~) z+ H
  if (FAILED(rc))% q6 q( A4 l  f/ i, O- P1 S# J  M1 f2 O
  {
! b$ L' o- ?2 a2 Y9 z# ?    //pIContainerOfDocument->Release();6 {+ C, o1 j' ?- B: Q3 e; P6 w
    pIContainerOfDocument = NULL ;' m8 N8 P; |& N2 v" B! W7 }- q4 j! b
    return FALSE;0 K- D8 b8 s) }% h% |: i7 o2 d! H
  }* P+ ?, l  l+ k: {  P' K3 C& z
  //获得Document# G! o, ]/ A7 ^: y+ n& a# r6 ?
  CATIContainer* _pContainer = NULL; & L, w; d  _8 m" N
  //获得SpecContainer
2 m6 n' u( w( n7 s  F7 t  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);1 i4 p' z6 ~) \3 y' S4 M/ X! T# T

) s7 {8 V; x1 B- u  N: v' j8 G* r* M  //GSM工厂
- [% v4 A% E1 Y7 G$ g; z  CATIGSMFactory_var spGSMFactory = NULL_var;
+ T9 T$ p' _- M  //设置工厂  # V) K; X# O- N  o$ j
  spGSMFactory = _pContainer;         
( b6 a5 d. k: y& @/ j1 S5 I/ p. h  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(Point3D);
$ Q) B1 h6 u' t9 J% z6 t  CATISpecObject_var spSpecPoint2= spPoint;     ) N- i' ^* r" f# d
  CATIGSMProceduralView_var spSndPntObj = spSpecPoint2;/ X) [& ]; R$ g/ O$ y0 k/ C
  //*将点显示在屏幕上
" L& M; u# ?: `, H. P6 U  spSndPntObj->InsertInProceduralView();
1 ]; \, ~3 z# p8 Q  spSpecPoint2->Update();
( G$ b$ Y& W! C5 u% G  //生成线7 w: r3 g7 v' k9 l% D5 ^
  CATIGSMLinePtPt_var spLine = spGSMFactory->CreateLine(spSpecPoint1, spSpecPoint2, NULL_var);
9 k' I% I  a! ~5 }  CATISpecObject_var spSpecLine= spLine;     
: ~0 b4 R% O8 m9 v( s) c, a2 x, X  CATIGSMProceduralView_var spSndPntObjLine = spSpecLine;
( M" z8 Z/ `9 b  //*将线显示在屏幕上
: P6 Q/ z( E! ]  spSndPntObjLine->InsertInProceduralView();
/ j" r! F% [5 t- j! r  spSpecLine->Update();
9 d; f9 C" E) A2 Q( U3 _
5 t6 U/ g3 S; q* Z9 }% ^ return TRUE;
; G# M1 g2 X" A) Q}% @0 O  f" g0 l1 S

, J6 s( n& _6 A# S( ^1 [8 b' V
$ n  ~, R! o+ h0 Z0 X  T
2 _4 H' `0 q9 `/ u! D2 O/ ?
( j& t2 P) G8 j+ z# [2 t' c' }" N! w. H1 E: D. V7 U
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了