PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2017-5-6 13:17:52

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

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

x
CATIA二次开发入门教程---15 通过点击屏幕创建点
( z  S/ O8 P5 b- t8 u. g通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。. V# n, C9 [8 [9 y- W3 Y
createPoint.PNG
5 }& ?/ Z, N/ Z+ A; f. ]5 m) V/ F9 Q) x3 b- Y" \) O
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)4 H- v' ^6 H3 O6 R% e
{
/ I& `1 c! T; G) G  g* G  // Add your code here
! M) i4 }; n0 M: t- i      CreatePointCmd *createPoint = new CreatePointCmd();
5 a( E" r7 E5 l$ ?0 e}3 r5 |- v& f, e( J
9 E; L# t6 r& H, h
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:6 @; r) z7 N3 o/ z* I4 Q0 b

1 S; L8 l- d# O- ~2 O+ ZCATBoolean CreatePointCmd::ActionOne( void *data ): K/ e; ~, w1 N8 M
{
- w0 b! S4 c( O7 S( J1 o, N  // TODO: Define the action associated with the transition
5 ~" k" m) e! g" U  // ------------------------------------------------------% \5 Y* N! j$ R# f4 e* s/ X& k
CATMathPoint2D point2D =  _Indication->GetValue();; l/ g! U, ^! x
CATMathPlane plane = _Indication->GetMathPlane();
+ k) X! T+ z2 H) k+ J- e. \ CATMathPoint point3D;
% k* F5 M3 y5 x plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);
  r" ^& Y7 K/ B5 W2 u! Z0 t9 E) D8 J$ I& M
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
2 `$ {3 U$ N4 j    7 b" o; N' s! C
  //设置Container(非根节点)
6 @. f+ a: ~/ |. \0 u% n( ~  //获得Editor
  S* ?* j9 N( @( [( G7 L( l% l  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();+ X$ n1 \5 z- q
  //得到当前对象的文档
( ~$ T' }! I8 Z4 }' J  CATDocument * pDocument = NULL ;8 x5 O0 @7 g9 }8 `1 n* n7 V# B; X
  //取得当前活动对象
# K$ ?- q2 ^$ R* B9 S& P; ]" u( L  CATPathElement activePath = pEditor->GetUIActiveObject();
1 U5 @8 i+ S$ T  //取得当前活动的product
6 Y1 \" l8 u6 O8 M: C+ `  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());  H& z# O& ?  \
  //当前活动对象不存在9 m& q7 i8 h/ f$ ^& o
  if (pActiveProduct == NULL)* ]) T! L3 f) {, R
  {
7 P5 t$ N2 [7 d$ L8 y6 R! T& c2 `' k    pDocument = pEditor->GetDocument();
6 q3 h0 J1 W3 k# V. _& ^" v, j% p  }1 i' x+ y- m4 i
  else" A+ c' q* `/ E( }: L% ?
  {
7 z. n) C& Y: K* ]7 Z/ Y    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();" J0 R7 S% F% S0 o; d! Z
    //当前对象的引用对象是否存在
' L7 w& f0 ?! M) t: }    if ( NULL_var == spRef )* q' Z* D' z3 G8 ?; S7 S4 H
    {, F9 C( r# P4 {+ @
      return FALSE;
& u9 o* u8 _1 U* Z* K    }- f: N% b; \- c" G" b; k* [
    //当前对象的链接对象
6 i$ q& a9 L1 J6 R2 ~- N0 a9 w    CATILinkableObject * piLinkableObject = NULL;6 _( _, L+ o" d/ }0 Z; b! [
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                           
5 @" P& S* T; V3 l    if ( FAILED(rc) )
2 g. {0 Y( W, J1 {$ [( u( E7 d    {
# L' j# j' `% s. u      piLinkableObject->Release();
9 B9 l, o+ u4 Q3 b- `/ d% d      piLinkableObject = NULL ;
+ T- S$ X5 v# O8 e0 L8 z0 N9 C      return FALSE;
! l6 D$ Q, e. o" o    }
8 g% L2 a. d" a8 |- A5 w/ k    //得到当前对象的文档
0 f; W+ A" [/ w    pDocument = piLinkableObject->GetDocument();
7 z' A5 M' O" p8 e: Z4 V) R    piLinkableObject->Release();
# B. K' ]" |% |4 N6 J    piLinkableObject = NULL ;
9 n8 t( M8 v! d* s! D3 w# f* G) E    if ( NULL == pDocument)
# N  g' r# L9 U( ^; e    {
- b9 A3 u  V+ h' [# e; M, ?* e      return FALSE;5 o2 D$ q8 Y) m6 `
    }
6 ?# T/ m; I0 T# S. g3 z  }
" h8 w9 M3 ~5 F# m2 t  //得到文档容器集
$ J- ~9 D- v; ^" \+ u$ |  CATIContainerOfDocument * pIContainerOfDocument = NULL;* r3 L  I. y% p( Q2 ~6 e/ x
  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
  _! a* `9 B2 b  if (FAILED(rc))
4 r0 ~* V& s" e8 C/ `9 \  {
' y/ K- F3 `% u% d: b    //pIContainerOfDocument->Release();
/ ?, a! Z5 Y/ w- l' F2 f+ ]8 x  ]) P    pIContainerOfDocument = NULL ;- I' k$ c- V3 L! z3 q; v
    return FALSE;
4 {6 G7 }+ Z( F9 F/ b  }
* C, g$ x0 o6 Y* @  5 D4 k2 {; g9 ?0 K7 ^6 m" X
  //获得Document" r& Y* y  U0 w- Z4 z
  CATIContainer* _pContainer = NULL; 3 G$ e9 J7 d2 `# l* y+ x8 ]+ e9 Q
  //获得SpecContainer6 `* k1 ?$ Z$ `2 D5 M
  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);3 B6 G% ~3 i8 Q7 G
# h7 n2 n7 W/ G3 e+ ?
  //GSM工厂$ F9 ]' k. B% X* F9 _+ {# _
  CATIGSMFactory_var spGSMFactory = NULL_var;
) T7 N1 i9 D8 {9 \  //设置工厂  
8 h# p, w, b( h; P: a* m: t  spGSMFactory = _pContainer;         ( c& }) p, \9 e+ E4 @: \5 w
  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);
) K* G- f1 n, B/ C" I' F4 o- f( Z& O  CATISpecObject_var spSpecPoint= spPoint;     
$ A' }* M5 d4 @5 `: P3 B5 g3 d  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;6 ^& u( h/ @5 U8 G% r7 `

5 |4 e% c7 W2 |6 s) @" |  //*将点显示在屏幕上
& n, }7 c7 |  O7 h- g  spSndPntObj->InsertInProceduralView();  \( u. _. X9 Y- l7 @/ N, _  W  q
  //更新点对象; E  t8 x; `) j/ {/ A" Y( U
  spSpecPoint->Update();
  q3 v  c, g: q. |/ n+ y& t ( W! @+ A; b( g: }
  return TRUE;
, y4 ?) J  v8 m. c1 P: i}
: g, L& h, o! D* ]0 n& D0 @; j
) m$ Z* s2 |, J; o+ d8 u7 t
. f* ]/ V( E" U1 c5 S8 u4 m/ z效果如下:
; x; }( T$ |9 x" S: B% q( V8 k

/ _( M' n( K7 v0 ^: p) C( c2 w- a! B' f
上海点团信息科技有限公司,承接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指的是什么呀
, g- W6 \: a/ |: |' T) c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了