查看: 5192|回复: 1

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

[复制链接]

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

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

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

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

×
CATIA二次开发入门教程---15 通过点击屏幕创建点
% @# @. u* M- G. U& h通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
* d  i. {' i0 v createPoint.PNG , c+ g7 p1 k9 D$ A! G

, Z' c5 H# S: ^6 q" p, E$ \" m- {7 q$ jvoid DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
. q2 U5 m" m0 |0 U7 S6 r" Z{
% w+ y$ a. l4 w+ L; h1 n3 z  // Add your code here
% ], i4 k$ b% s: Q+ e( j) x0 t6 U' O      CreatePointCmd *createPoint = new CreatePointCmd();5 }# }( w; u2 D- d% p7 @, c
}
6 }' B+ f4 b& J  |$ Y: W! A- [- W4 u: C
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
. ?# @* ~( ~& Y" l& i' ~9 b( T6 R+ J6 K7 W
CATBoolean CreatePointCmd::ActionOne( void *data )
+ P0 ]. Y; X' K0 U, X% O{( a6 {& D# K/ g4 H3 k
  // TODO: Define the action associated with the transition - F! L* |8 S6 [3 K
  // ------------------------------------------------------: R& e& B5 p6 ?2 p! ?# l  I+ h
CATMathPoint2D point2D =  _Indication->GetValue();- t& U& h9 i# `- s/ B2 T' e/ l& I( p
CATMathPlane plane = _Indication->GetMathPlane();
7 _8 z2 h; z7 q# |7 {* t CATMathPoint point3D;5 C4 B+ N+ V, E+ S! K- I5 s6 N* b
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);
1 m" W2 w, c- L, ]  F5 _8 O! Y3 ]
2 t; K( M) w3 x( {/ O; c+ G cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
% Y% G, _! b5 q( v   
* X( e6 |$ d7 C$ C  y: x2 O6 _  //设置Container(非根节点)# @4 h0 A: j5 L7 w! \8 ]6 L
  //获得Editor
2 b: e5 F5 _/ b1 e- S  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
5 g( j8 h# u( `! h) P* Q; S  //得到当前对象的文档
. D* }' s7 Z9 G% r/ `+ j  CATDocument * pDocument = NULL ;
- q- X$ I9 H6 Z6 D% ^9 w  //取得当前活动对象$ S% _$ u8 M9 J* ]/ y+ T
  CATPathElement activePath = pEditor->GetUIActiveObject();9 g3 o; i/ ?) i; W
  //取得当前活动的product
7 Y% f* P2 A( L: L, W. v  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
* z* e! C1 C  i  //当前活动对象不存在
# @% l/ ~5 r8 _7 s' Y  if (pActiveProduct == NULL)3 A5 v0 V) R8 J! O& y5 Q' ]
  {* s( O+ X9 y  {
    pDocument = pEditor->GetDocument();& |% S( {5 d4 U. c) j5 X" N( q) m8 W
  }
5 |  a% d( [3 U7 C' b) I: r( M  else/ ^1 t' k) g- U& Q1 R. c
  {
1 g; D- F4 U, {! S# ~3 l- K    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
# b" M5 `1 |: v6 U    //当前对象的引用对象是否存在
( `+ ?+ u4 e4 n/ U" J% o: j& t2 I    if ( NULL_var == spRef )
+ p4 r' e  g5 }3 Y    {1 l& k  B- Q4 u0 V4 y
      return FALSE;, y; n, C& k: j# t8 H; s4 \
    }4 P+ l0 N; W) P& l8 t
    //当前对象的链接对象1 ]7 o6 C. w, p
    CATILinkableObject * piLinkableObject = NULL;# V5 x6 {( m; ?# k% B- b
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                            + }) U3 }9 [# p) L/ ^: ?
    if ( FAILED(rc) )
& x7 ~( W  o$ R8 j) [* Y    {
9 o% _& N$ n% ?/ j      piLinkableObject->Release();
1 l* L* U% e9 `. b) C      piLinkableObject = NULL ;& G7 z0 C/ c, q/ N/ m0 n
      return FALSE;
! M9 L5 F% Q" a) q0 [7 ?# b' A! f    }
6 ], Z* m3 t( C; Y    //得到当前对象的文档2 \+ Y  W5 A# o
    pDocument = piLinkableObject->GetDocument();
1 v" t, b  L* y    piLinkableObject->Release();6 \4 {# r, `6 j8 u8 _7 }2 H, B
    piLinkableObject = NULL ;
' V9 C3 |! s, x& L7 c    if ( NULL == pDocument)3 K; W4 J4 T; H2 n
    {2 d1 M; S- @4 [0 _% V5 c5 G
      return FALSE;
+ q( G" T- G/ d' [6 p. r1 ^, D% Z    }  m4 g; R* H& [- n+ P* N
  }$ W+ z7 L1 Y- O8 p
  //得到文档容器集
2 p& g# O. M8 V% M+ @9 e# t' u  CATIContainerOfDocument * pIContainerOfDocument = NULL;% O8 I* _1 G1 m; q& R. n$ P! r
  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
2 e  b8 j; o5 D1 E- |, p, u% J  if (FAILED(rc))
; t# I& @) p$ R4 F6 W. }  {. X: R3 g) Q2 V5 ]- ]& C
    //pIContainerOfDocument->Release();! ~2 P5 F% [3 ?; r: a
    pIContainerOfDocument = NULL ;
: i* Y8 Q: U: o& l/ x" ^. W3 g    return FALSE;$ D: o  s. r! _8 d/ y; _$ Y& V
  }) b  G8 C$ P: \9 G5 _
  . n. @% _4 J8 Q1 O" P. T6 N
  //获得Document/ @+ ?$ e/ t8 z4 f9 G
  CATIContainer* _pContainer = NULL; , H8 \. f3 H+ z" L* ]& J
  //获得SpecContainer/ y0 i/ g/ X5 g) k5 Q0 V; ?
  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);/ @' T5 w( P5 S6 f2 |# K

8 q: ^; B) s: }$ k% m% x  //GSM工厂
0 }7 ~5 ^; ^  I7 X# d  CATIGSMFactory_var spGSMFactory = NULL_var;9 k, {5 U' O8 r2 J1 Y. Y  B
  //设置工厂  
" b  v4 U4 y. _  spGSMFactory = _pContainer;         
4 g6 d% B3 ?3 m4 z, B$ p# A  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);* {3 k  I% h; U- r8 x, [* v
  CATISpecObject_var spSpecPoint= spPoint;     % j6 x5 f7 O8 c) J5 R2 T2 ?
  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;' A) G8 @. U; o6 f
# I( R, R" J4 Y8 B( ]
  //*将点显示在屏幕上
: i8 R1 m% E; j- Q- Y+ G% O  spSndPntObj->InsertInProceduralView();
3 ^2 c+ v" x# u8 m# E  //更新点对象
# w" j9 x  f# F4 s  spSpecPoint->Update();% e+ V; U  B3 x

) b7 D! C+ J9 H# v  return TRUE;" V* W6 V# P! W2 |) U, g
}
  P; D) P% H" h* V9 \# H( b# e: D' \0 w2 l
, n$ G* o% v% X5 h9 d4 R
效果如下:
0 T& X% w# f+ j7 a$ T- V; D
; J$ Q4 h4 `& i1 ?/ U8 r1 v" j; l# I6 K; R( t

- W# ?8 L4 E& ^1 |) B) F
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

0

主题

1

回帖

12

积分

新手上路

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

使用道具 举报

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

本版积分规则

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