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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x
CATIA二次开发入门教程---15 通过点击屏幕创建点
& b8 C  u3 J( _8 m% Z9 v通过点击屏幕,自动创建点, 这里直接建立了一个简单的对话框,通过pushbutton来添加一个回掉函数,函数里面去执行创建点的类。
* I+ Y6 ]( f8 B createPoint.PNG + C" `7 n/ Q; a/ o; J

9 S# r: T8 E% ]& ?2 U2 N6 Gvoid DialogTesTCmdDialog::OnPushButtonCreatePointPushBActivateNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
1 x5 C! J! M2 E2 ]" l9 ]; `{% q9 S( |/ b- q/ O5 I0 v* M
  // Add your code here
& E9 w7 k. p7 P/ j' b3 ^/ J% ^      CreatePointCmd *createPoint = new CreatePointCmd();3 W  H3 Y; Z! `
}9 S: X) i# a, c) l6 z2 c2 _

$ |3 z( M7 ]" n6 Q' o3 A: t# j) C新建一个catia 的命令,名称为 CreatePointCmd ,接下来要做的就是在 action one 里面进行点的创建,代码如下:
5 t% g  S, k9 V& V9 B8 H; b
& C2 `( x" D+ a: x  lCATBoolean CreatePointCmd::ActionOne( void *data )
1 |/ H# e/ S& e+ d4 R* Z{- U* Y: p+ }& O, A
  // TODO: Define the action associated with the transition
$ d3 t9 V+ V5 Z4 a! [  // ------------------------------------------------------
' }' I& e0 Z$ P3 k4 u- q0 U( `: N CATMathPoint2D point2D =  _Indication->GetValue();
% M3 p' t1 u5 n/ p1 R- l& Q CATMathPlane plane = _Indication->GetMathPlane();
, f- u  J; ^) U+ P CATMathPoint point3D;5 l! r7 ^6 o2 y1 P- ]' B
plane.EvalPoint(point2D.GetX(),point2D.GetY(),point3D);  N  g: Y, K) N" ^. s
- P4 t2 s8 i2 E  w  K
cout<<"Point coordinates:" << point3D.GetX() << "," << point3D.GetY() << "," << point3D.GetZ()<<endl;: P, {" I; i$ N, f
   
; V' ~: a& N! V$ N- K+ Q  //设置Container(非根节点)
/ Q8 I7 `6 s' s: T! a% q  //获得Editor/ l( c: t. [1 F9 F' p! r" D+ W, }; Y- Z
  CATFrmEditor* pEditor = CATFrmEditor::GetCurrentEditor();
" T; ~# m  j4 i1 l4 @3 h  //得到当前对象的文档
% n7 G- R9 R' F; {/ C  CATDocument * pDocument = NULL ;
; O/ G. |$ @# W) N. C" V  //取得当前活动对象
# c3 ~6 |, S1 c  G; w% _  CATPathElement activePath = pEditor->GetUIActiveObject();" y' O/ \" U  p% g2 r* w
  //取得当前活动的product+ Y+ @1 ?- q2 z- W. w8 G7 }$ t
  CATIProduct *pActiveProduct = (CATIProduct *)activePath.SearchObject(CATIProduct::ClassName());
2 k( g7 A. Y) a$ R' T& S/ j  //当前活动对象不存在
9 T3 @2 M" ]9 ]' N7 b# y  if (pActiveProduct == NULL)9 V& C  [" N  W3 G
  {1 ~" r( i4 Y% z
    pDocument = pEditor->GetDocument();) z" H8 Z# C1 X' C
  }
+ {; z* n: t) `4 d5 w, g  else
6 u* l# \) c8 S; V: l  {
! X9 x0 P; x# m& x    CATIProduct_var spRef = pActiveProduct->GetReferenceProduct();/ u# w* A. s/ ]- N' t
    //当前对象的引用对象是否存在$ A- G# r3 a6 ~& `6 F' T3 {
    if ( NULL_var == spRef )' S3 b' X' ?1 B- C7 k+ O4 ^5 k
    {
8 R& v9 o6 T8 ]8 f5 _& J      return FALSE;
( `" ^; x& t" v* i# D! ]    }
) \" I3 r8 s- z) o    //当前对象的链接对象4 |$ ?" N- n0 h3 N( }' b
    CATILinkableObject * piLinkableObject = NULL;9 i* y, O  Y# U  ~5 o$ W
    HRESULT rc = spRef->QueryInterface( IID_CATILinkableObject, (void**)& piLinkableObject );                            * f/ w! T7 M" \. x( V* j2 Q# V
    if ( FAILED(rc) )( a/ _! @( X9 |+ k4 A0 W
    {
/ V+ d) @( p- l$ ^1 C. S1 f      piLinkableObject->Release();$ g; O1 \" a. l2 [, G
      piLinkableObject = NULL ;$ L7 B* U) V) m- _8 q) J) ^
      return FALSE;. D  v* S- |8 E3 O1 b; l7 t+ n
    }
: D# h& I# I7 X2 F  g7 n    //得到当前对象的文档
0 C# F  e4 P7 s" q    pDocument = piLinkableObject->GetDocument();
& w% q' A2 o* t. a6 g: R    piLinkableObject->Release();
6 M* c0 m* @. p0 s# v: D    piLinkableObject = NULL ;# y  ]5 h0 s, a- e- h+ X
    if ( NULL == pDocument)& P8 L7 ?- a) d1 z
    {
! \/ q9 P  ^, \+ m4 B, E' x      return FALSE;: j8 T! }4 q: ~1 Z8 \6 x
    }' o/ F- z# V! Q; v( L- ^8 N
  }* x2 ^$ r1 b* Z; D
  //得到文档容器集
2 |% Y  _9 }9 V, C/ k- f) y# h7 o  CATIContainerOfDocument * pIContainerOfDocument = NULL;# {' Q6 q% V1 Z; V/ \! _9 |8 [: E
  HRESULT rc = pDocument->QueryInterface(IID_CATIContainerOfDocument, (void**)&pIContainerOfDocument);
7 b% @7 O  @8 D- t  if (FAILED(rc))
" U8 ^9 z" V# i  {
; V6 m7 H+ N; _% z7 {4 \. S! P8 x    //pIContainerOfDocument->Release();
1 C3 L, k8 `  d1 N# D( c    pIContainerOfDocument = NULL ;! O6 f- I" N9 k# |0 {
    return FALSE;3 M1 p, m$ u7 p* F
  }7 O6 t0 G. Q$ L# d- i
  8 t8 I' e( N6 Y$ i
  //获得Document3 M3 _; I  Z" d. Q7 h& g# W+ t
  CATIContainer* _pContainer = NULL;
& g# z# ~# F2 D0 S  //获得SpecContainer
  d* V' _( E- x7 I1 G& H! K  HRESULT hr = pIContainerOfDocument->GetSpecContainer(_pContainer);
$ s* U4 t# W1 R# F& G9 F/ `) N / c# e: n1 l1 t: ?
  //GSM工厂7 y& m9 A$ p. J2 M
  CATIGSMFactory_var spGSMFactory = NULL_var;, G3 ?+ R2 l, p' }. U) P
  //设置工厂  # W& k- Y  \6 @  \
  spGSMFactory = _pContainer;         
& B6 y+ P" m, Z, L  j  CATIGSMPoint_var spPoint = spGSMFactory->CreatePoint(point3D);! g3 }6 S4 a# ?7 Z; q  M
  CATISpecObject_var spSpecPoint= spPoint;     
/ i. T9 L3 c, Q, F" f# F  CATIGSMProceduralView_var spSndPntObj = spSpecPoint;
- y+ k1 ]8 }. U# p5 v& W) w: o9 G+ t# b) j) r8 B# Z# w
  //*将点显示在屏幕上3 q0 @  m, h& R
  spSndPntObj->InsertInProceduralView();
- w$ I1 d' `; W1 r' H  //更新点对象
) P. a( C& X0 t/ q  spSpecPoint->Update();
( ~) D4 n- w" Z, E7 E% E
/ E1 r. [. t6 Z! w  return TRUE;
% c* Z! @  Y' t$ U7 R}
8 h; \  }9 ~2 l( v
1 [! ~8 P  K% W- C! Z7 `' k  g9 Y& i4 j4 J
效果如下:
/ n% C! k0 G" q% @: }+ X) K; q0 \# |+ ~/ F! _
) |) H4 m) z4 j0 ]- V
) Q( m* H" T! i
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复1

0

主题

1

回帖

12

积分

新手上路

积分
12
发表于 2024-6-12 17:01:01 | 显示全部楼层
  _Indication指的是什么呀- o/ z3 S% e9 {- t7 }
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了