PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

2024-6-12 17:01:01 4792 1

admin 发表于 2017-5-6 13:17:52 |阅读模式

admin 楼主

2017-5-6 13:17:52

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

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

x
CATIA二次开发入门教程---15 通过点击屏幕创建点
8 \2 [8 N6 C5 m: s通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
$ b, l# v- I1 C0 p- x createPoint.PNG 2 ~2 H& [8 U) v9 {1 {0 f

: y: x$ Q9 X' p) X- x# Lvoid DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
' B7 e7 X- @! v9 w{! ?- C% ^, U% G" n. m
  // Add your code here* L/ U2 z  n, o$ D! s0 ^, B" @6 B
      CreatePointCmd *createPoint = new CreatePointCmd();) b! ]6 h$ s* y/ Y) d
}
- t+ F3 `! J2 |9 O7 I3 y( I" N- S
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
9 Z! C0 V' u8 q8 D3 p1 c7 y8 O9 @: L" g3 U! W' b, J
CATBoolean CreatePointCmd::ActionOne( void *data )+ a6 a7 I; e9 C7 u$ s- n2 \0 j- x' O. w
{+ y' G5 U/ `+ x1 d) W
  // TODO: Define the action associated with the transition
. a! K% r2 m* e& l  // ------------------------------------------------------) r  d; U/ r1 D: J
CATMathPoint2D point2D =  _Indication->GetValue();
$ o. D7 C+ }* a1 r9 @ CATMathPlane plane = _Indication->GetMathPlane();! q' @) C( c+ b
CATMathPoint point3D;
- k. |2 c. g) ?! o plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);9 G/ P& g! B5 ]. B6 p. ?7 B
2 F$ w% j% u0 t( H1 X' L
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
0 J6 x7 ^, ?! n3 i   
5 k- s2 H, y- X/ k$ c& n  //设置Container(非根节点)  ]( m/ Q9 U' I. K& h" U
  //获得Editor
: i/ r- E0 q+ _! ^" B  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();7 H. `4 h" a3 o  i" O, J+ h4 W
  //得到当前对象的文档6 [( O. z8 C8 C3 @+ Y3 d5 w
  CATDocument * pDocument = NULL ;
; L5 f" E1 ~% R: O) N- q  //取得当前活动对象1 I: E% k9 Y: n9 O. q' v  F
  CATPathElement activePath = pEditor->GetUIActiveObject();" ^" i& x/ {7 c9 q% `$ _
  //取得当前活动的product
( H/ U6 _& e8 Q6 f+ [& b  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());. I4 I3 U% f0 o3 C( f
  //当前活动对象不存在1 f# y; ~; R2 A+ q+ S4 B
  if (pActiveProduct == NULL)
8 ]: K* ~2 p3 t0 `: H! J  {: S+ \1 n: N) |
    pDocument = pEditor->GetDocument();1 y9 \) g/ B: a% j( x; G' ~; O
  }
; Z5 e: a( i. k$ P  else0 T& O6 }& ~3 E2 Y
  {
& a1 n( W! n* K& P4 X& \5 o7 I    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
, o4 y2 W: D# f5 D% L4 m/ N    //当前对象的引用对象是否存在
% H7 `- A! N; x' q' {8 H8 b    if ( NULL_var == spRef )
( t( D6 T: `1 p& k    {
- V! c6 a8 J6 a, W      return FALSE;
& v$ c4 Y* r* j5 |    }
1 U( t( h; P8 }, q7 N, G    //当前对象的链接对象
' U8 d# ]$ k* w    CATILinkableObject * piLinkableObject = NULL;
' N4 `: I) W  f& L: E# {! ~    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                            # [% d' m' r' \: d! T; [9 l6 [
    if ( FAILED(rc) )
! o. y: q1 F3 @; S4 q    {
3 _* ?5 A, G3 f      piLinkableObject->Release();
9 r  K  ~( Z- r) P1 A2 u  D! [      piLinkableObject = NULL ;! ^" H; A3 y; n3 v: k
      return FALSE;
/ a" r8 v/ ]: b7 R. \% @" C    }
2 A! _- }: f: p8 r1 w    //得到当前对象的文档
/ W0 l: m$ `% ?, e4 Y" E# g$ v    pDocument = piLinkableObject->GetDocument();
0 P9 W" D1 {' H4 I' z  ]    piLinkableObject->Release();$ Y  O9 l2 B. R1 F3 Z
    piLinkableObject = NULL ;
' V2 j2 p% d5 a$ u7 O    if ( NULL == pDocument)
% F; c' J( {5 W5 p& c    {/ A9 f" E5 \1 W$ i" @0 l) O( P
      return FALSE;' c3 Q2 x5 p' y+ ], |+ T
    }3 x0 I6 x3 V$ r2 |2 k. {
  }/ L$ P  H3 w+ _- e  t
  //得到文档容器集' u8 b  k6 k& f: t0 w- ^2 }# w
  CATIContainerOfDocument * pIContainerOfDocument = NULL;
; t9 t% u! i  i- h4 }  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
" A, N$ p- C/ L- b2 `& {% g  if (FAILED(rc))
, S* U$ N6 q6 V$ ~$ F, h$ G  {
; z; K# T, a4 B$ J4 z/ I1 J7 S    //pIContainerOfDocument->Release();
& w6 z* k: O; o$ z( B+ U    pIContainerOfDocument = NULL ;
/ }5 u" Q+ D* r    return FALSE;
5 x5 O! [( b) c* `4 A  }
! W% m5 d: D. x  
/ y- h" `$ c) z% o/ W& z  //获得Document
" b2 [. ]/ r0 V) |- k. V) o0 S  CATIContainer* _pContainer = NULL;
& U/ n4 h0 i# {  g  //获得SpecContainer( S+ L! r7 E7 F9 w/ E8 F
  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
* d; `- X3 r- [- {4 I ( g  D  o  C7 L3 D
  //GSM工厂3 Z+ F5 k- {0 c" _2 U7 s
  CATIGSMFactory_var spGSMFactory = NULL_var;+ m, ^9 O6 x3 o
  //设置工厂  
/ Y3 y( `! L" u( d8 E* j7 R  spGSMFactory = _pContainer;         
+ ?2 j/ T9 ~! r  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);
; x/ ]0 e& f+ w" O: M$ p- }* d; b  CATISpecObject_var spSpecPoint= spPoint;     
' j4 V0 V7 o1 J  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;2 |, A( u- z4 O
/ \; |! j1 G( V% F
  //*将点显示在屏幕上
+ J, D# r) C6 P' I6 E1 x" ?  spSndPntObj->InsertInProceduralView();/ T; f* j. s5 M, N
  //更新点对象
) Q4 b7 f6 p/ u- T  spSpecPoint->Update();
- _9 C8 L% x# ]" {
7 @* r  R+ p1 a9 X, U/ W' r/ [. v, h  return TRUE;  T  L$ t7 P1 t' s  t' S4 n, c
}
4 @- W. J- K, `# ?& }/ X' {# {
  j  c1 a0 ?# p- B  \/ Q
  {/ v# J1 P8 X* r效果如下:( y& n4 W: M. E; y/ n! p3 W
3 k6 Q" V+ _" I5 |  t- f- E: m- J

2 t7 f4 M3 b$ ~2 a1 W6 x' l5 ~2 C3 [
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复1

onerice 发表于 2024-6-12 17:01:01

onerice 沙发

2024-6-12 17:01:01

  _Indication指的是什么呀
) M3 n7 v2 \- T0 `7 T) b  p
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了