查看: 5072|回复: 1

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

[复制链接]

6

主题

4

回帖

60

积分

管理员

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

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

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

×
CATIA二次开发入门教程---15 通过点击屏幕创建点
) y1 I7 G7 F- [; i# \0 j- ^) M通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。- [: X4 X  D8 f9 P5 Z- A. [
createPoint.PNG
% X$ Q& d) Z. c8 ^$ d( ^! ?; W6 l0 P% L0 Z6 K6 O/ C
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)# [5 [' c; H. b4 B  W9 _3 U
{
2 a; N4 M  r# N$ a* ?  // Add your code here
3 @8 r2 W- P. H; k6 u, {. i      CreatePointCmd *createPoint = new CreatePointCmd();
9 ~$ b) u6 L" P. y. @}
0 ^6 f, d( u9 b: ^1 G; j$ ]2 x% U) I- O4 q9 z; q4 K
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:) |& x  [  C4 I) j+ n1 q

+ B. M+ n( V) U, P8 B, b$ |* LCATBoolean CreatePointCmd::ActionOne( void *data )
) k. C2 \! e* F5 a2 \9 p{
. a! _, Q- ]* Q5 h  // TODO: Define the action associated with the transition . \( S9 n7 W' ]* G5 J$ P
  // ------------------------------------------------------$ y6 H' A- W% \) C, t/ k
CATMathPoint2D point2D =  _Indication->GetValue();
/ `4 F/ E6 m5 ~) d CATMathPlane plane = _Indication->GetMathPlane();
1 b! r' Y. s& Q; a CATMathPoint point3D;$ Q' R" g, `" j+ x9 `
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);) e0 s; H0 T& T
, N: I, a/ O* s, K) g- G0 p
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
( p4 I( w* q# ?5 v. p; E* M" F9 S   
( n6 g2 s5 v2 I" B. j7 n* W5 l  //设置Container(非根节点)
! G1 K( K6 U4 n$ K  //获得Editor
7 {5 v2 x/ y( @5 f4 p3 w, U  f5 ?  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
; v6 O$ m7 |) U1 P! `7 m: @2 t  //得到当前对象的文档
. i8 g# q- `, @6 ?( A  CATDocument * pDocument = NULL ;4 ]! z( x; |+ `  H- u. _" p! o  a
  //取得当前活动对象
, ~1 ?) y! m0 @; d  CATPathElement activePath = pEditor->GetUIActiveObject();
& s- ]+ O( ^) Q7 i+ Y  //取得当前活动的product& r' |+ b  D/ E. t- \
  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());5 @7 A  _# `/ a2 `5 S0 O, L- v& Y
  //当前活动对象不存在
& c- ]1 j4 W# @2 u3 F  if (pActiveProduct == NULL)  {- C: @0 V+ X- V9 t
  {( `# a7 Z- Z; h# b1 l
    pDocument = pEditor->GetDocument();
3 f, M2 ^( ]4 r8 |  f( M  }
. J+ j* P) V  M) b( D# h! x2 w: Q. Q  else
( C9 h8 A+ h& b6 ?- D( {  {
$ C) ]4 ]3 r; D$ C    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
  ~. }' D3 ^! {/ }3 c, \: e3 r    //当前对象的引用对象是否存在
/ g5 S5 K' V( d  @    if ( NULL_var == spRef )
2 I5 i9 O% a. H: ?) t' _    {
) R7 [6 G; c: O8 ]+ u      return FALSE;
$ V) n  B5 D9 ?" }; _    }
2 Z& O* C" C  [" K: u. }( x0 ?    //当前对象的链接对象' ^3 ?3 H8 |$ M. c! X
    CATILinkableObject * piLinkableObject = NULL;
' `/ w# R9 U$ e  B% C( u# {6 K9 N    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                            . O" Q+ X0 o% D
    if ( FAILED(rc) )
& o. P0 g4 M! y) i    {
" m7 i6 C; }' ~/ K  h5 q2 ]      piLinkableObject->Release();
1 t  |5 v% c+ H  \: R: x      piLinkableObject = NULL ;1 F$ _* ^+ F- f! ^/ w8 |* N: H
      return FALSE;
( W, T. @  O9 D( l' I7 H& z# e    }/ C" q5 y, N6 h6 |
    //得到当前对象的文档
$ z7 M$ a0 C" j7 e. C8 @) n    pDocument = piLinkableObject->GetDocument();
+ X" N2 j' E; h; u2 ~' O1 x    piLinkableObject->Release();, L9 c' N  c. {/ I2 m# u4 O% B7 v
    piLinkableObject = NULL ;7 L) t$ r( K, [+ m) R
    if ( NULL == pDocument)
1 F, G" @$ s% S6 ]- V: u    {0 r- e, ?& e0 {5 a. ]2 ]$ W1 s
      return FALSE;3 O0 N* z0 P5 X- B* `( W3 Z9 g
    }
" n6 Z- G, o% P% y4 u( A  }
3 I& \0 l9 u* i# J/ I/ q4 }  //得到文档容器集
6 y- s  q/ w9 t2 L  CATIContainerOfDocument * pIContainerOfDocument = NULL;+ m+ Y  a# Q( }2 M
  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);! I% {, ]! x/ `# {% c9 T8 c
  if (FAILED(rc))
- V; Q' t, F' N5 v+ f+ E  U  {, z5 I! A4 A0 K8 o# |$ W
    //pIContainerOfDocument->Release();
- Q; i: r- ^3 H' c* \+ B    pIContainerOfDocument = NULL ;
3 G2 N: a* X+ h' z$ B: m    return FALSE;5 H8 ]& }' F8 }% e
  }
3 L* y' @0 W9 K$ h0 V  
. L0 k" t$ M/ m4 g: z7 \  //获得Document
$ B3 F) {5 P9 g, ^6 H7 s, _/ L+ J3 o  CATIContainer* _pContainer = NULL; 5 ~8 T: B7 K+ _3 O- M" y8 Z
  //获得SpecContainer
% @1 t! D9 r7 M$ Q  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);) T  X5 i! `+ w1 D

' O0 W5 L  z# f  //GSM工厂1 `" \* {  \# K6 X$ C3 l
  CATIGSMFactory_var spGSMFactory = NULL_var;/ {0 t3 v2 ?' Z6 R
  //设置工厂  9 P3 ?3 Q5 D# y  M
  spGSMFactory = _pContainer;         
2 T& ?7 O* n" f8 i  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);1 U- F5 i2 R: m$ o' |/ S, ]/ h7 a: m: r
  CATISpecObject_var spSpecPoint= spPoint;     6 c" f! v6 F0 @
  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
7 M/ c, T( P+ `1 ?$ v, \. Z6 I+ F7 `( v# p
  //*将点显示在屏幕上
3 L: P+ n' ^# O  spSndPntObj->InsertInProceduralView();% r2 D- [! |" M2 r% I& U6 G! V
  //更新点对象! B8 X, V% ?& ~; z$ X, E! I- s
  spSpecPoint->Update();
- i! L6 J) J0 k9 h+ J2 E
$ {! i) i& N2 u8 {  return TRUE;
: ?) O& d' {  B, {7 J  N: E4 g- x}3 |8 V3 J+ ~& P1 I3 U5 s) F0 N2 V
2 H% m" U; [, y2 Y
& _% {  a3 R' N, ?1 ]8 _; ?6 c6 P
效果如下:' f5 O) _7 h& y% U% {
' m7 `; N% @0 X9 E3 z4 i, ^

0 x0 P* h5 W* \* t4 N; o. _2 Y" \& ~' x# |3 M! E  O/ `8 {
上海点团信息科技有限公司,承接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指的是什么呀) H, h1 m, a! f2 l; B
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

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

本版积分规则

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