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

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

[复制链接]

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

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

admin 楼主

2017-5-6 13:17:52

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

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

x
CATIA二次开发入门教程---15 通过点击屏幕创建点5 S9 l6 j1 I. E4 O
通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
. u/ C  L/ |8 l3 P createPoint.PNG
+ j: Z4 t1 b# u6 e) E% o) o6 T, y' Z7 T- e% X* W
void DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)' @3 A  @% S9 M: A% T8 T1 r
{5 x1 q% T+ c9 F! w* p& S2 ~; r7 u: S9 W0 V
  // Add your code here
$ e$ r( {1 R& A- p      CreatePointCmd *createPoint = new CreatePointCmd();! g$ m* m! [& N  Y* N) Y
}
, ?+ q, R, Y2 L/ O6 n$ X" x
0 R3 x2 C1 n+ I4 u* D7 D新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:: d& ^) r6 V" r$ n$ Z+ ~* r

% @% C% \9 C, Z( L1 T* UCATBoolean CreatePointCmd::ActionOne( void *data )
. l1 \% n: \+ h3 j( Z5 p" f{
* V9 |  ?8 G2 Z* c) Z  // TODO: Define the action associated with the transition
$ u5 E0 y8 @9 R: \8 P  // ------------------------------------------------------9 t* s' i0 d( {9 a3 ~' D
CATMathPoint2D point2D =  _Indication->GetValue();/ U+ {6 F; Y! h2 y
CATMathPlane plane = _Indication->GetMathPlane();/ `+ E; G' w. J& V
CATMathPoint point3D;2 e4 @, Q5 S5 x* F
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);# k( b# _) m* V% ]2 x2 P0 ?3 G
7 D1 U0 R# T6 H+ f4 |
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;
$ w3 e$ u- l: p    6 Z" Q, R6 s& w; b% a2 o/ Z4 m* Z
  //设置Container(非根节点)7 h6 R4 d$ P/ ]8 z7 Z: _
  //获得Editor
. u& Z# }/ h+ M6 ]  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();9 w7 C& A! |5 k/ T1 {
  //得到当前对象的文档$ m1 W! P  T- B  o/ |/ X
  CATDocument * pDocument = NULL ;
7 ]1 x, R' d) P; B  //取得当前活动对象
6 s0 H# |( b7 M2 J7 g/ y  CATPathElement activePath = pEditor->GetUIActiveObject();
  B( q% ~- s, V: L  //取得当前活动的product2 d: [8 m+ P3 t1 B9 A
  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());+ C9 }7 p- ~% \3 W
  //当前活动对象不存在  E0 B6 I  I4 @
  if (pActiveProduct == NULL)
' [- K; g- `) j$ w8 E6 G% q  {* i! j7 Y2 _, [9 E( \
    pDocument = pEditor->GetDocument();, ~9 d' m; T) _& ?
  }  _" D4 g+ ~4 a
  else
: P6 v4 X: j. T! ~! @* N  {# F0 r% M8 M: y5 A; q
    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();
7 B( N" ~0 X% I7 n- _' P0 S) T! z# n0 ?    //当前对象的引用对象是否存在7 G2 x) P, n, q0 }3 Y
    if ( NULL_var == spRef )& r0 F7 M" O1 i" b3 |# H
    {  q3 b- [6 ?6 x3 o
      return FALSE;
/ D7 v4 M: s- J" q    }" M3 e4 A( R, L: j9 K2 ^; W4 S
    //当前对象的链接对象
: i( {6 D! W  s  f: M7 j5 m, H    CATILinkableObject * piLinkableObject = NULL;, x0 J. e2 s2 S( O
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                           
: B, c2 a; D& u: `4 j9 `- z7 q6 Z    if ( FAILED(rc) ): k7 ^3 h/ y+ m3 C4 v; A+ D2 i
    {
0 V( A6 d( c5 }      piLinkableObject->Release();
% v0 F- [  [1 T9 u      piLinkableObject = NULL ;
6 e- `1 h0 g# Q  f6 `      return FALSE;9 V- c! E  w6 S2 X6 {, ^
    }
: T; K/ t) c& `2 X) z& T    //得到当前对象的文档% r8 W, N0 k+ b. u! }
    pDocument = piLinkableObject->GetDocument();" D. \% U1 W1 g& d; U$ [" U, p& A2 O
    piLinkableObject->Release();5 J5 y# |% A. k. w2 w
    piLinkableObject = NULL ;
, e2 x$ y& o# L+ u% {% C    if ( NULL == pDocument)" w; z/ D0 g6 u2 K
    {
% c% M: i0 H% x      return FALSE;
4 N0 k( ~$ H# ?( w2 A3 a% y2 p2 I    }
4 _  v6 A, i6 e. ]  n% Q8 a2 _6 Q  }: M; `! C9 w& U" c3 k7 M3 Y/ O
  //得到文档容器集
/ g. T6 h, X6 Y- x) u! V: Z  CATIContainerOfDocument * pIContainerOfDocument = NULL;
3 O( y5 x- R7 Y) d7 ^5 K  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);4 s3 K+ W% h9 L+ c; \: ?5 l
  if (FAILED(rc))
" t/ p9 Z) [' H, T; C4 R+ ^% D3 F  {
$ z2 M0 h$ d" v' t  r    //pIContainerOfDocument->Release();1 L- k5 i0 ^% Y# {
    pIContainerOfDocument = NULL ;
1 Q, e/ u+ s& u3 [/ [! T1 F    return FALSE;
2 m4 M7 ?5 H  i  V% u4 W4 n  }# Y9 b) @  [4 n3 e, }* B. m* }
  
: {  R; P+ u' q7 r  //获得Document, X; ~2 Y2 @6 k# f% {
  CATIContainer* _pContainer = NULL; ' ~8 m0 {' ^( q" q6 l. p+ ~
  //获得SpecContainer0 E! J8 M  S0 F1 F" u
  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
& z! R' |* o% n0 q7 D
# o" C' X- z( e% N5 D  //GSM工厂; j) Q2 m% j# w* x) C. [$ u" g
  CATIGSMFactory_var spGSMFactory = NULL_var;3 P( ^! C! D0 F
  //设置工厂  ! A- t$ \' Q) ?/ ]5 g9 j
  spGSMFactory = _pContainer;         
) G4 g# ~2 }: O  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);9 X1 l5 [5 D/ R" _+ D7 y
  CATISpecObject_var spSpecPoint= spPoint;     
0 {' h: @4 n! W! I4 A5 w  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;$ N2 @3 Q7 S  p% X9 L6 B5 P0 t. z) J

! F  F  ?1 |; }. Q  //*将点显示在屏幕上& _* s: e" e+ ?' X; O4 J
  spSndPntObj->InsertInProceduralView();
9 k; i8 h/ A) I( X+ |  //更新点对象
9 K1 R% [: d) y, N  spSpecPoint->Update();1 u8 B+ P0 C1 b

% |) E9 A$ C& A5 T% T9 J: k  return TRUE;
+ M+ M2 r3 P; ~. t, i) y; ]  Q! W}
7 P4 ?' a) A9 F" Z; N
  c& O7 s% m3 D! J6 H7 U. @3 x1 C$ h! O& m/ d2 C) U! @6 M; h( f
效果如下:
2 V2 \' W+ s1 y& k" i1 Z- q/ B
) g; [2 r2 a. b/ w2 d. u( h$ b! r3 l" g

3 G( Y7 m+ I2 e" p2 j  f/ B& ?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复1

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

onerice 沙发

2024-6-12 17:01:01

  _Indication指的是什么呀
- a2 g& J; }' U& ~8 n
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了