查看: 4962|回复: 1

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

[复制链接]

4

主题

3

回帖

44

积分

管理员

积分
44
发表于 2017-5-6 13:17:52 | 显示全部楼层 |阅读模式

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

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

×
CATIA二次开发入门教程---15 通过点击屏幕创建点5 X+ s2 G! d, X3 Z
通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
1 M5 C% U( u" F: a8 P& _1 C createPoint.PNG
8 e0 O" M8 D. e$ n( ]& [: p
- R8 T% \' A. z& hvoid DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)' M! f* I( T% q  ~
{& J/ {7 h9 u& z
  // Add your code here& u* I( R6 j% h6 k
      CreatePointCmd *createPoint = new CreatePointCmd();
7 I+ N, G! ]) c5 W}/ V: e4 s1 h2 ^) y3 N0 g. D

, \+ V" B1 D$ u) x, V1 B' x/ [新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
) N4 [8 B. [# h5 q7 P, {" t
* z* v9 Q# j9 J! {+ U. KCATBoolean CreatePointCmd::ActionOne( void *data )
; z- W6 K; ~+ U, S{1 s, S( o# p* _0 x
  // TODO: Define the action associated with the transition % x% a3 v( i1 [4 h% ]( F
  // ------------------------------------------------------
: W" P5 O* A) k CATMathPoint2D point2D =  _Indication->GetValue();
' V/ s/ @5 D1 G, U# R5 ~ CATMathPlane plane = _Indication->GetMathPlane();% |: _  J) G9 K4 q
CATMathPoint point3D;1 K6 j: a4 w4 u- y* h
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);
/ E' P/ O0 u* Y9 g+ ]5 e# X# O/ V3 Z5 x) t- R/ v
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;( v1 t1 ]( y& R4 A8 f  [
    # T- P. d2 ?2 Q- |9 ?' F
  //设置Container(非根节点)
% x% J9 v6 e' f) t3 `  //获得Editor3 u- n" w& m: }; N
  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();" E' E: b) E' P4 ]' B
  //得到当前对象的文档
' D9 Q. y8 b% Q  CATDocument * pDocument = NULL ;- y( C* G9 o! k% c
  //取得当前活动对象
1 l9 i- j5 {+ n5 B% D  L  CATPathElement activePath = pEditor->GetUIActiveObject();, p( k: `! _" F  M% x4 v( B7 Y; i
  //取得当前活动的product9 l- d; C( C5 S
  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
& {1 u+ U$ T& m- \) l5 ^% d8 o  //当前活动对象不存在
! `0 m8 h- u4 v* `4 A  if (pActiveProduct == NULL)
; {, I- m2 d6 J. j3 W# X  {
, T6 |3 V+ }9 T8 P$ ~0 l    pDocument = pEditor->GetDocument();
1 e& @$ D7 ^, M% P( h# ~2 S  X+ Q  }
$ f$ b9 D6 M' y& T  else& o: y# }) u* A, a+ J: S: g9 |9 P& }
  {( s# Q/ y, |$ L: K
    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
( ]4 _; ~3 v6 o    //当前对象的引用对象是否存在
/ s% _# ^  Y" C8 z! d4 Q* E5 Q    if ( NULL_var == spRef )
# O8 H% K  O. N. v$ X$ a    {( l" ?' }% s; J6 D
      return FALSE;# b% X* c9 s; U1 G2 i0 F
    }% w7 M* m- j7 n7 [7 ]1 ^% l
    //当前对象的链接对象! t1 f+ X9 E1 {! L' s/ Q
    CATILinkableObject * piLinkableObject = NULL;( n) `* b# s' _! T; z% s
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                            8 G9 K; @; p8 v
    if ( FAILED(rc) )) j5 e/ x' Z5 Z1 Q8 X
    {
" N- f" o7 D6 W2 d, q- g2 i8 ]      piLinkableObject->Release();
% m5 w+ l* L- q8 |* _( r$ [      piLinkableObject = NULL ;
7 I4 a. k$ h6 W! @5 Y8 ^      return FALSE;1 I  n4 e6 m5 s$ f. ?" x9 D
    }
2 a3 A9 P3 P1 D, ?5 E8 f: |3 u    //得到当前对象的文档
5 A, q6 @4 X/ S% C/ t7 x" x% |6 _    pDocument = piLinkableObject->GetDocument();5 `$ O0 }0 L6 b$ X7 g  N
    piLinkableObject->Release();
8 y, F2 R. {" Q5 t, I) p9 b8 k    piLinkableObject = NULL ;' ~0 I$ B% a0 \$ m7 ~5 M# m
    if ( NULL == pDocument)3 ]% a2 \! a3 A2 Y( U) m
    {4 T+ c! r+ [5 i! Y9 d  C
      return FALSE;
% Y: F  ~! X# F+ N8 r4 Q    }- w5 n1 P; s) m# A, g. _5 ]) w
  }2 j  t% j# P4 K$ m( Q8 h6 T' M* u5 `
  //得到文档容器集) G$ v/ _+ _; b6 T  i! K
  CATIContainerOfDocument * pIContainerOfDocument = NULL;
* V: x) W2 d1 @0 s9 {7 K  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
, K9 Q. O. I, ~+ ?* Y  if (FAILED(rc))
! Z6 |# M2 {1 c- g$ B  {
9 X9 M1 v1 B/ x% {  V; T    //pIContainerOfDocument->Release();
3 X) C; N+ u6 W/ P+ Z' P) L    pIContainerOfDocument = NULL ;
. m2 H; t2 a0 r" x% o* F    return FALSE;
; t6 B' `% r  q; {+ s4 K1 x1 |  }
  z6 r3 X9 t; X9 R, X  
+ F% G- x" ?/ z( a/ t- |2 R8 K2 L* N  //获得Document7 k: v# V: P- f( C  z
  CATIContainer* _pContainer = NULL;
; x, p1 G) Q/ U' i$ p  //获得SpecContainer( Q. A& H# P) s; U4 |/ s
  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
+ d1 s# m9 C8 c: ]2 p# M
, q" P' I% I: K9 {# |  //GSM工厂& T8 V. V2 O. i1 _5 a7 @& ^/ N
  CATIGSMFactory_var spGSMFactory = NULL_var;
# M! ]" h. g/ y. p: I) d  //设置工厂  2 D8 p" C) _6 q9 ?9 t6 A. }8 g
  spGSMFactory = _pContainer;         
/ H. r  Y0 h4 B5 Y  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);
3 G) T6 M6 l! Y, v( J$ g  CATISpecObject_var spSpecPoint= spPoint;     ; a4 _' V0 a0 a
  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;9 U& X% t) v+ U8 F

7 l7 @, l" f+ b; @$ |; V  //*将点显示在屏幕上
: f; J2 R+ l7 r* W. |* j  spSndPntObj->InsertInProceduralView();
$ a" [% A9 a; k% E; Z1 `$ `7 s  //更新点对象
) \0 t/ t1 S% c  spSpecPoint->Update();
. d, w% L: U* S9 G: j1 m   w4 s  H( A3 e! ]
  return TRUE;4 E; q' c$ b5 C1 e) j8 Y* d
}
+ c1 K9 Q9 f! z  ^
6 t) w4 Z) I& q6 \: M/ v
& P  E9 J2 N' j, F8 i效果如下:5 d; v, t5 D9 K" V; I/ J% S5 s

$ y) e# g8 b, W4 N6 n1 ]# Y6 m
/ I" z* t( R5 i& L( U$ m/ Y; e' C/ Z
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

0

主题

1

回帖

12

积分

新手上路

积分
12
发表于 2024-6-12 17:01:01 | 显示全部楼层
  _Indication指的是什么呀
5 O$ w  t( l: m% D* m2 Q# \
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部