查看: 5088|回复: 1

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

[复制链接]

6

主题

4

回帖

60

积分

管理员

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

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

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

×
CATIA二次开发入门教程---15 通过点击屏幕创建点
6 f  v/ ~& z. @# o通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。4 I3 Q. F6 ~! w
createPoint.PNG
2 D# S  p; V1 u1 C1 |1 }6 e0 r5 U) f& F7 Z
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
+ M# J1 B! k9 ~5 O% X{
2 T% T6 a1 C1 t7 p/ u5 y- Y  // Add your code here
+ p; R; F! R# C      CreatePointCmd *createPoint = new CreatePointCmd();: i% V% B: m2 R2 T( v
}
- @: H7 I0 U3 ^; T8 Y$ r# N4 c' D; t# d) g1 q
新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:% ?9 P+ P8 D* N

4 m- U7 G" O) Y1 v7 eCATBoolean CreatePointCmd::ActionOne( void *data )1 F  A! ~, x" {" D( G6 Z
{9 @; }) V$ T  U
  // TODO: Define the action associated with the transition
$ r% g) H0 B0 E- l: [+ S3 I  // ------------------------------------------------------  Z, @6 z' f) m4 y
CATMathPoint2D point2D =  _Indication->GetValue();- V3 i8 |. z& l# G5 b1 J
CATMathPlane plane = _Indication->GetMathPlane();
2 E% O# a* B- X CATMathPoint point3D;
/ T$ X  c, v# k) D% | plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);3 q) i9 E3 W1 K( c) h% T6 R

1 Z8 U  Z+ ?, Z8 f4 @$ H% B5 K cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
' |. C! `, \$ G$ Z3 C    - J: P& I0 x0 R
  //设置Container(非根节点)
9 }3 {1 B/ i# {  //获得Editor/ \9 L3 O" F6 {; r( r+ b8 z
  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
/ w6 @1 w8 `/ G  //得到当前对象的文档- X/ Q" e$ P( e% z! l
  CATDocument * pDocument = NULL ;9 Y! H0 \, Q+ M6 r
  //取得当前活动对象* ~* |% _8 Z5 c. b9 @
  CATPathElement activePath = pEditor->GetUIActiveObject();
5 s0 T8 w4 \% ]) u  //取得当前活动的product
) L2 A& R/ H; @6 U4 t5 Q  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
; b! Y& L- f* c& W6 j. f5 R  //当前活动对象不存在" |$ n% g) l- f' S- H9 L. ^  H
  if (pActiveProduct == NULL)! a9 ]' G# k  C. S
  {* A% z" z* B* ~. O+ h3 I  p) q
    pDocument = pEditor->GetDocument();
7 |2 i, P+ O: N1 f; g% x6 L* Z  }
7 u1 P/ A9 ?6 r, ?; Q  else
$ I! ]! A# \  v4 _& A' S% K1 U: K  {$ l1 w' @( @& {& t' @
    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
+ P, h% c3 w6 r  @2 c, X    //当前对象的引用对象是否存在
% f' U% J/ |. B  W0 m    if ( NULL_var == spRef )
% G5 u+ I( t4 ~6 g, U, Z* W    {& f0 v6 P( R0 a  y2 z/ g
      return FALSE;4 u! s' f8 ?( R# v/ B1 Z2 B
    }4 ~' ]* W+ i: k
    //当前对象的链接对象, E( L! J9 b6 o9 {
    CATILinkableObject * piLinkableObject = NULL;; e  f# m( K) s& L  \/ Z
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                            & h6 |6 }, b1 G, y) z
    if ( FAILED(rc) )
! ?! d* |" W; V0 F6 u' \3 \* t    {5 X+ P/ m! s& o" F
      piLinkableObject->Release();% r8 L0 }7 k! F+ u" C; Q& D! |
      piLinkableObject = NULL ;* P. {8 x6 I; Z
      return FALSE;% L# N+ ]; D! @) q7 |$ i
    }3 H5 X3 q) n& B$ a% n. u* u- e
    //得到当前对象的文档' F$ H* S: f6 Y! a$ d, W4 }
    pDocument = piLinkableObject->GetDocument();# ~4 g9 u, v" `9 {8 u
    piLinkableObject->Release();
2 }4 B5 I5 ?$ _; q: N1 \. a    piLinkableObject = NULL ;
1 Y/ d7 D+ A# G    if ( NULL == pDocument)
+ t; U, _$ g# l" j  O$ k    {7 r2 A/ A& H2 H8 I% i4 S! Q
      return FALSE;. a5 u2 H: F& T. T$ P- a- X
    }* Y+ Q0 E  ]5 }$ t% b9 f; Z
  }2 H5 l! |8 W1 F/ V
  //得到文档容器集
) S& ~, E' ]6 _0 k  CATIContainerOfDocument * pIContainerOfDocument = NULL;  R6 [2 X/ `+ H1 B( Z/ ~- V
  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);% c. Y3 }7 g7 D7 {% s% m  O# f* N
  if (FAILED(rc))6 F. h3 j+ o1 J) E
  {6 n  r; ?% g& F# d; M( S4 S: ^
    //pIContainerOfDocument->Release();* s0 b, g% d5 U
    pIContainerOfDocument = NULL ;
1 k) Z& ]; ]& ^! W; u, B& [2 w    return FALSE;$ j$ L6 B% a$ M! [* J  G6 G. T
  }1 f$ t6 `& f5 d% w1 n
  4 N2 h8 f/ _. [8 T" |' F
  //获得Document) S. p! ?# ~) L5 L
  CATIContainer* _pContainer = NULL;
) e) g9 v, b6 ?1 C% T1 r, |1 L  //获得SpecContainer& |4 |/ d- b# T3 i$ T
  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
9 K( L, K+ b1 J8 @& Z/ R- C/ H $ R6 \6 E1 R/ ^$ s3 _( H
  //GSM工厂
2 P% N+ o3 e2 q. m8 H" z. n  CATIGSMFactory_var spGSMFactory = NULL_var;0 `/ I( Q+ P; I2 {$ N7 _- U: {5 d
  //设置工厂  
) D# T6 |$ {- Q! l  spGSMFactory = _pContainer;         / C7 d! U3 d2 [6 c: Z) n* W
  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);
1 [' ?5 H/ x; u  CATISpecObject_var spSpecPoint= spPoint;     
8 f  N' p& g: f! l# @. A  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
5 h. ?7 q- ]! h8 e' [2 [1 d. u! b" N( a
  //*将点显示在屏幕上
4 T3 I& M  J/ b% Y$ i  spSndPntObj->InsertInProceduralView();
* q2 P, Z* G  M" N% `+ p  //更新点对象
5 V. [% x3 o+ _  spSpecPoint->Update();4 D" }8 x% H- _+ s' j
- q6 S8 v# y3 q5 x
  return TRUE;+ o$ k& H  Q) z
}
3 M0 w* c3 v' R. t
/ _+ @1 s3 ~; [0 a: V& V$ Z
$ V  P. D6 m% k; p& w  M效果如下:
) E8 o$ f) y6 |$ M/ @6 I
' E  f: f$ B- ^- z9 J( M9 x+ d3 F/ _& x

3 w% n+ t1 q  p- @; }
上海点团信息科技有限公司,承接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指的是什么呀
$ J7 O! Q1 E0 a" o
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

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

本版积分规则

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