PLM之家PLMHome-工业软件与AI结合践行者

[资料分享] 如何获取选择点映射到视图空间中?源码分享

[复制链接]

2023-7-15 12:08:47 1326 0

admin 发表于 2023-7-15 12:08:47 |阅读模式

admin 楼主

2023-7-15 12:08:47

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

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

x

" C+ y) m, N. B3 J
$ Y! V: @2 O* X! n$ n4 X+ K0 H& t$ ]如何获取选择点映射到视图空间中?源码分享9 b9 G# \* t( r' G6 ^
5 q) z' `0 j2 f% a& I
  1. //------------------------------------------------------------------------------+ ^& M+ F. u  V& u
  2. // Select Screen Position and map to Modeling View Plane7 F) v% P4 h! p9 A5 S5 x5 t
  3. //------------------------------------------------------------------------------
    1 a+ W  |8 m+ b3 q8 l7 n* }
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    6 L5 |7 q- @" s0 t5 ^
  5. {
    3 i" m6 Q1 X0 O7 g* y* r
  6.     NXOpen::View* myView = NULL;- d, Z; \: C5 t0 e7 E. x
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    $ k6 B- U  Y5 n) W( e% Q  q

  8. 2 k+ n* B8 x+ N  C2 H8 n7 ?7 a' n
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);' S5 Q$ E( @' p/ W/ m0 m/ G
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    3 S8 |( h% @$ [
  11.     {
    # n( R/ K4 Z+ `% z
  12.         // obtain the current default annotation plane where PMIs are placed on
    % n2 `7 f- R7 u, s; w: W* ]; D
  13.         NXOpen::Xform *xform1;6 Q: A) G  Q  g+ M. P
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    # C/ K  D$ P9 T; T5 ]& l
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();4 |4 {' \, y; P# ?2 N# T
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    * D( _2 |+ o; ?# i
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);( t! I+ \9 N2 }* |# q! m' @
  18. : H- n7 u/ z9 O6 s" s
  19.         // create the ray 'into the screen' at the selected cursor position
    " B$ X! O" R" y* v* e; c! S
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();8 D( z8 j, l/ a" Y
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    ( f7 }( o2 J2 k: |/ w
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);1 v0 q+ h; P  g. S$ Z& _/ @
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);7 W% d: n& T& ]/ s/ c
  24.         lineRay->SetName("Ray");
    # ~+ F2 r9 `% C+ G" ]0 i4 c
  25. 1 G; o2 x$ M$ j6 u# T6 n7 u
  26.         // create the plane from the view to intersect with the ray
    $ I2 L, W  e4 N1 P& b
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);# @5 Z7 y3 U) C  H. T4 O' ^
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);5 k. {' ?0 ~9 T$ X* B
  29.         planeView->SetName("ViewPlane");0 f& K% X1 X/ o& y6 h& B) n

  30. , T2 ~8 b. m& p  _' A: L
  31.         // now create the intersection point7 t5 ~# h  X1 H7 W! t
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    : R) G2 R0 |  u
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);( l2 |# F7 X4 ]. ?; N3 h0 X
  34.         pntInterSect->SeTColor(10);7 R$ _5 p" C0 F
  35.         pntInterSect->SetName("Intersection");( r, {- E9 B5 U9 ^6 i) f

  36. - ~7 A2 X; u7 s. T1 m
  37.         pos = pntInterSect->Coordinates();
    ; {( G0 b# f6 c: n6 }- x( v! S
  38.         print("\nPMI Position:", pos);
    1 C( U& B# c) e/ E/ g9 ^

  39. 4 Y1 n+ M. w& x$ Z* H; _/ B
  40.         // clean up - comment to see intermediate objects
    % X( Y& I1 e. g, t7 @. z
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");" y. J( v& }: _) ?1 k7 A7 m
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    , t+ q0 s3 L' O1 [0 @
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);0 {! Y2 t2 s5 w: g! ]+ r; T
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);" D/ G9 @" r& c9 t$ Y( t
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);  v8 T& u: X. ^2 N& u; S, w0 }
  46.         m_session->DeleteUndoMark(markDel, NULL);! `3 o$ j5 I8 K5 B

  47.   c/ d2 Q% p# A% Y; U
  48.         return true;
    6 U8 Q% [# `% i( v- e0 K! C4 j
  49.     }0 a) U0 N3 s4 M: W

  50. ; s2 ~' `# G$ f* k
  51.     return false;
    - j- H  d- U9 Y/ ]1 f
  52. }
复制代码

% U" H' R, ^; [
2 I4 T( D! c' S8 f( m; ?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了