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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

4 U- M, Q' |: c3 d4 }' f" D7 w! m; L' g" j' K. e5 S2 Z
如何获取选择点映射到视图空间中?源码分享
) P& x9 `2 m3 U& Q9 T- Y! [' v! f- O+ U( I; H" h8 i  G
  1. //------------------------------------------------------------------------------5 N0 v; s. \, |4 _6 J
  2. // Select Screen Position and map to Modeling View Plane
    7 c+ R$ J+ F  y5 Z
  3. //------------------------------------------------------------------------------, u; C+ _+ J3 M+ {: Z/ B  A0 ^
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)4 E7 j0 ?6 R5 I
  5. {6 k: W" f6 ~1 Q0 P4 i; N
  6.     NXOpen::View* myView = NULL;
    $ C  w' n  o3 U
  7.     NXOpen::Point3d myCursor(0, 0, 0);9 b5 T, A. Q$ t
  8. & C) ]0 {2 Q7 ?+ o& u8 ^
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);- r: N# t$ F/ j. G8 t
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    * ]+ ~" ~- A# u) ^+ Q
  11.     {
    8 r" \5 i! c' q3 t. O( r8 k
  12.         // obtain the current default annotation plane where PMIs are placed on% i1 M2 @  B; N* Y* }& {  {3 {
  13.         NXOpen::Xform *xform1;
    ' Z2 a& p5 r3 `; Z% K$ q3 @
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);% H0 u6 B. ]; i% Y% _) J8 |5 \
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();9 A! [+ b9 }, l3 T( ~: @4 Y
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();% A) i( j% u0 }- Z4 o% T
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);) b4 Y2 G; |: ~! N# @) e) Y! S

  18. " P2 A& ?4 f. F
  19.         // create the ray 'into the screen' at the selected cursor position
    ; Z3 O3 f+ ~+ G+ v! m7 V
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    ! o# B; K6 R% @5 n1 r+ y) }
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);: y6 n7 {% J( d- {" S$ C
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);0 _4 g' A2 I! ?- O: K. p
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);# [6 U( l; B4 u5 j
  24.         lineRay->SetName("Ray");
    ! y3 x# ^! x2 \+ C  V% m
  25. : `. L# w( d/ [3 W- N0 c5 |$ L3 T
  26.         // create the plane from the view to intersect with the ray
    / C1 y' n8 T$ g0 H: J4 _
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    , ^+ i8 J& L  W2 Q& l- h* h
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, m3 A: T8 I$ \2 @' d: ~
  29.         planeView->SetName("ViewPlane");
    7 j( Z+ I8 ~4 n4 }6 a5 K
  30. 7 A; e7 i; e) Y
  31.         // now create the intersection point
    9 [1 |* y8 g& b5 H
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    % b( M5 s+ I* ~3 [: o
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
      _- x# _. H. ]2 z
  34.         pntInterSect->SeTColor(10);" Z9 s) g: s' G% u% Y) z
  35.         pntInterSect->SetName("Intersection");  j6 u4 q4 y5 _0 T- V- }
  36. 5 F3 ?6 b8 K  j
  37.         pos = pntInterSect->Coordinates();1 a5 K# I3 y: _& M
  38.         print("\nPMI Position:", pos);
    2 L8 z4 f3 {. Z, \6 V: t
  39.   i! j: D/ s' V. i# ^% ?) h
  40.         // clean up - comment to see intermediate objects
    1 T: H$ ^4 C: G0 _( d4 c1 g2 v) q
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    0 P+ i6 l$ ^8 w0 Q+ C% V
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);% A1 t0 a# I' }1 K. _, Z* ]
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);5 i6 m# c, |9 r& X% }4 y  B
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    1 b* L! U8 ]+ _" c6 l
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    & g* S6 Z7 S; l
  46.         m_session->DeleteUndoMark(markDel, NULL);
    & R+ ]7 M$ j9 K' @5 M
  47. : O) H7 L; s1 w& p& Q
  48.         return true;
    : Z  x! ^' s2 j3 W) x
  49.     }
    , x( T: L- c  M+ r. f

  50. ; z. Z/ h3 i: w( F
  51.     return false;0 t/ x3 E+ Q4 h  Y
  52. }
复制代码
( x9 k+ P% Y- }

, c4 P+ Y! x2 A" X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了