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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
7 g9 m+ Y9 I( W; k. T7 y7 w  I9 c

, S! u8 O0 J/ `- J* L/ U如何获取选择点映射到视图空间中?源码分享
9 u# u$ ~5 K3 |3 ]8 Z1 b% D% O0 }7 V* x; y% Z3 C1 D% u- o; c5 z
  1. //------------------------------------------------------------------------------
    : i# k4 u% `3 X: M
  2. // Select Screen Position and map to Modeling View Plane* u" Y% ]5 Z4 \- _
  3. //------------------------------------------------------------------------------
    " y3 @# Q. u3 l" }/ C
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)% R# z1 v3 u% U9 U0 y  e
  5. {
    " G! c- m8 A6 {
  6.     NXOpen::View* myView = NULL;9 z% B. g* M2 P
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    4 O- `  `) q" }6 y& J* r/ ?3 {

  8. + W: D2 x! C5 h$ w8 N) l
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    ! \' V" j& N9 v, c/ S
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)+ n% @7 ?) t! T
  11.     {; r8 ^; g; L* O& N# j# G/ R3 |; Z
  12.         // obtain the current default annotation plane where PMIs are placed on1 }1 w+ R" N7 I; A4 }3 W0 T
  13.         NXOpen::Xform *xform1;
    7 ~3 |$ ]  j2 B: k* W3 a9 D  G
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);- n9 X8 K! \8 X" G# B# U9 ]
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    3 Y# X  @" ~3 l  w
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
      u  ?$ H/ c2 _' }6 _9 l5 X  L, C
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 \. y/ n9 \/ ]# \7 `& U. D8 [4 G
  18. . @  X$ c4 [7 n5 a, G+ f; @
  19.         // create the ray 'into the screen' at the selected cursor position  `  V: ?' G  Q9 F* l
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    % s4 Z, y3 h1 j' Y/ `
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);2 g6 d& j) {8 x; T* j' \! a& D
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    2 q1 b7 J  s+ W5 e
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);# Y) m; [$ A# e# N( j1 Q+ U
  24.         lineRay->SetName("Ray");
    ! A+ u  L% c5 d7 i" E" q
  25. 5 r9 E( m' n5 H( }0 M
  26.         // create the plane from the view to intersect with the ray
    0 ~' a& O# m! L/ [% P' X2 o8 W
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);! I( Y& y' s8 h) R
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    & @3 B4 c9 h  y
  29.         planeView->SetName("ViewPlane");
    . @' E, A" d) ]6 t& h5 W& I

  30. ! H" `0 U8 k/ L
  31.         // now create the intersection point
    ( i( e- m4 o& Q: A& F
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);" ?/ t0 p( ]! H6 m4 t
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, Q' @6 T# Y+ O. ^5 O2 ~% f
  34.         pntInterSect->SeTColor(10);
    5 r1 G. Q) h. I0 Z6 k- {" b
  35.         pntInterSect->SetName("Intersection");
    6 T  z" r  N" @( r; T! j
  36. 1 d0 ]8 o- t. s) F' u* S; N
  37.         pos = pntInterSect->Coordinates();
    ' v' w" ~% T/ v+ \2 P8 z
  38.         print("\nPMI Position:", pos);
    , `6 `# R! s6 |  ^) Q' `0 ~! I# M
  39. 0 m* j5 J" s/ Z, v
  40.         // clean up - comment to see intermediate objects
    , Y/ P, O. K& _8 t. p
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");# W, E! @7 x1 b3 G8 \# O
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    ; [% d  q3 `# v5 r( O
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);* L6 w- H* @, n' U7 M
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);% a/ `2 Z9 b; o# K1 n
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);5 J9 U, x3 ~5 `& {" r: Y; L$ C+ m
  46.         m_session->DeleteUndoMark(markDel, NULL);' j2 U, {( p1 D0 p2 V
  47. 7 q$ E, q% q7 ]) K9 d) U
  48.         return true;/ K; R% ]; X2 V7 Y/ P; C  v' k- p
  49.     }
    # m- y$ A9 U, ?' G% d
  50. ) s" f" F; ]- r3 \9 _1 G
  51.     return false;
    2 ], Y7 M. F' D' U5 F) U1 A
  52. }
复制代码
% ~: Z% q* A: G" V7 J

. \) v) L; g. c3 Q7 c
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了