PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2017-5-6 13:17:52

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

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

x
CATIA二次开发入门教程---15 通过点击屏幕创建点, T! a' v+ }0 d# ~$ U
通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
0 h* ~5 ?! t: M2 ?6 q createPoint.PNG 1 ^/ |3 w  Y3 S$ b6 e. F
3 Q. v) Q% u4 E; c2 |
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data); l9 ]( k; i" F4 B
{
9 U% t# T7 T; S  // Add your code here- O1 h9 c1 J3 y' }+ ?# `! Y+ \
      CreatePointCmd *createPoint = new CreatePointCmd();
1 e8 V( |& n; G}8 t, }/ s1 _& b% h, m/ w) q! q! p, {; w
, h' p" D* k+ N8 F( S( \) N) m( W
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:# A; J& Z$ t) W
3 V# V7 M; H, }+ m' ~& p9 C
CATBoolean CreatePointCmd::ActionOne( void *data )
; G3 D. @- v3 G) D. e+ v{& U6 n+ C$ [8 Q1 x
  // TODO: Define the action associated with the transition
8 \& R+ X7 V8 q6 |  D  // ------------------------------------------------------
+ y8 u6 @6 z& _, L CATMathPoint2D point2D =  _Indication->GetValue();
# s4 I1 |4 z' V* N2 G2 |# H CATMathPlane plane = _Indication->GetMathPlane();# J3 @* s6 ~4 W  i1 F+ F3 w
CATMathPoint point3D;4 p5 X% r3 e' k- c, }
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);# r' h7 ?6 F* \0 v1 v( r
! {" @6 H- _# c* z0 X3 f
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;+ P& d) N7 U# m6 B8 ^
   
0 m/ f6 x4 y; f; e- v  //设置Container(非根节点)
! M+ ]1 D9 k2 k( b8 ?2 |  //获得Editor6 w. v2 R4 m: Z6 v
  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
7 L4 @' l" H6 M9 a4 S) {  //得到当前对象的文档
7 s2 x- A" {0 N2 O) }; e: E$ d0 W2 Q  CATDocument * pDocument = NULL ;
* x. Z: K6 r8 s& n  //取得当前活动对象. B* y1 n0 ]1 q& v, U
  CATPathElement activePath = pEditor->GetUIActiveObject();8 y: G( ^  g: Y5 C1 y  Q
  //取得当前活动的product
+ h+ m/ {& c6 c: k  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());; K9 D$ S/ @/ h7 g' f/ S% e& m
  //当前活动对象不存在: V( i3 N+ v7 ^% I# {8 W
  if (pActiveProduct == NULL)$ n9 p* W3 |1 o) T" S
  {+ P. Q, J. z* k. z
    pDocument = pEditor->GetDocument();6 \2 N6 j6 n' D3 y. X% A( F! k
  }2 }+ m: T7 q+ ^5 m* _# N
  else: d+ n5 A" c5 _! |7 x! h; s. ~
  {  }0 j7 v: c/ ]  E7 U
    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
  N  ]; h: X  k4 ]& F+ j9 B5 ~    //当前对象的引用对象是否存在9 X1 Z1 j6 u% i- K! K
    if ( NULL_var == spRef )
1 a3 h4 Z/ j; V$ n  R    {9 P2 h6 j' O% b" `/ |
      return FALSE;( P  \' y& g- I2 ?. p' o5 M8 ~
    }
. q& \! i# D5 x    //当前对象的链接对象; i4 X% V; p/ `& R& ]9 ?
    CATILinkableObject * piLinkableObject = NULL;0 N$ k2 j( B3 @, }9 z/ e% a( x3 N5 W
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                           
! z* i5 b2 [8 w9 \$ m1 s    if ( FAILED(rc) )7 ^# v$ W/ a6 j# b
    {1 f, J# w. Y, U$ p8 `4 B& L6 W0 p
      piLinkableObject->Release();
! N- k' s, ~, s6 R. K  n      piLinkableObject = NULL ;
, i. y  s) Y5 r( H7 z3 t      return FALSE;
! s, \; _) k/ |3 Z) R7 V    }! g1 y5 Y; Z% ^6 c0 U! P2 g
    //得到当前对象的文档  C# L. j+ L/ V  S
    pDocument = piLinkableObject->GetDocument();
: {! b1 i) A3 ^$ Y* `" T( j. V    piLinkableObject->Release();* A0 b( l+ u1 N' l; G1 f: u
    piLinkableObject = NULL ;$ B) N& [5 r/ z6 j
    if ( NULL == pDocument)7 q8 M' G$ ?1 j% I$ d
    {' X; r' s6 q8 }, p" H, u+ j
      return FALSE;, ^% \* K8 }- J  g8 ]& b
    }9 a- g8 n- Y- N8 h" U- J6 N
  }+ G5 Q# t) m# n" o2 f- _/ L" ?
  //得到文档容器集
" ]/ T$ |; {7 _2 H3 C# {: z1 l  CATIContainerOfDocument * pIContainerOfDocument = NULL;
/ e7 b4 I6 d8 t$ L0 a  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
( M3 ]( W- ?* h; ]$ @  if (FAILED(rc))
5 z; Z+ J3 h2 r, n8 j( A  {
1 Q& l7 O( t0 i9 S1 `! C$ Q    //pIContainerOfDocument->Release();+ ?/ X+ n0 @, z0 o% x& w- Z
    pIContainerOfDocument = NULL ;5 p- y" g9 ]* f  F4 i( O% q' f5 z
    return FALSE;( i1 J8 \" K" V- ?% f& }0 _; ^
  }
' u# V- r  e: Y) n3 U) b# X  8 i! I% v& l5 n: l7 v, P3 M" U
  //获得Document
. ?$ {: \" j0 e7 }1 s; d9 a  CATIContainer* _pContainer = NULL;
5 s5 L  R  C, n$ }- v  //获得SpecContainer
/ b& I& u- H) R  i4 n7 _7 ~  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
$ b& k( W( f( D, k# D 1 q% a9 V. m( Z  _& }, o, D. V9 f# h
  //GSM工厂- a- M0 H9 h. I) v
  CATIGSMFactory_var spGSMFactory = NULL_var;
2 l( f) C. w( W  //设置工厂  
5 u+ f* n" a7 ?: U. Q6 K( b8 H  spGSMFactory = _pContainer;         : R5 J/ u3 b% e& ?7 V
  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);: ^1 v) n3 t" {& d6 P2 d. ~; j# e. \+ ~
  CATISpecObject_var spSpecPoint= spPoint;     + r1 m0 N$ f9 x' W2 S6 U+ n/ n
  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;/ V" a7 d& x3 X7 l4 @7 x

; z8 X3 b, h) r0 j6 g  //*将点显示在屏幕上0 z! ~6 _+ n' y7 R* @  q# s" C
  spSndPntObj->InsertInProceduralView();
* U% {( X" b5 u- Z( }( W6 V+ t% f  //更新点对象
. P% `# q0 @7 C! h' W  spSpecPoint->Update();
4 m1 h: u$ p& S/ _7 e , e# Z$ {) k# m8 q- U/ P7 V
  return TRUE;
. }$ \7 R0 z% T" `5 z4 C0 I}
6 C' t3 s4 a% `' t; }: O9 [
& K4 W4 |, l1 K$ @( F- D) _# _9 u( W1 ]' L) t
效果如下:% s, W4 U5 g7 u( }0 p5 d2 p
% i" W" A2 l4 `, h" r" G6 ]2 u

; {0 ?! V. l' j2 t: T$ H2 A8 `3 f8 k7 d2 T5 H5 u$ D/ h6 l
上海点团信息科技有限公司,承接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指的是什么呀
% U8 [  W9 }9 h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了