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

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

[复制链接]

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

2471

主题

1276

回帖

8万

积分

管理员

PLM之家站长

积分
82195
QQ
发表于 2023-7-15 12:08:47 | 显示全部楼层 |阅读模式

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

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

x

& n6 c; H, O, Y- M
6 I' j7 L+ g) h& I8 v6 c1 t如何获取选择点映射到视图空间中?源码分享
8 J* y; I0 e8 s. t
8 e9 H4 d, j! F3 a
  1. //------------------------------------------------------------------------------
    ) m4 A$ f6 Y7 k9 O
  2. // Select Screen Position and map to Modeling View Plane
    0 O3 b5 n$ ^1 p2 z$ X: Z. c
  3. //------------------------------------------------------------------------------1 ^+ J& c  P) n) ~
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    . ?" W0 h2 ~5 A
  5. {
    1 ~5 {, A# U+ C
  6.     NXOpen::View* myView = NULL;% g& z) S+ t; \9 F* o" E6 T" D0 {2 h
  7.     NXOpen::Point3d myCursor(0, 0, 0);; l! g; B! f! _6 r
  8. 5 x( v; m, k/ D3 X# W. U0 S
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);+ A* `( j' w" I, D
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)2 L1 C: J. b; ^* x
  11.     {
    0 |! Z0 A# s% P! L
  12.         // obtain the current default annotation plane where PMIs are placed on
    " g) [# {( ^0 @+ T( k& Z. V
  13.         NXOpen::Xform *xform1;
    5 \& W. l8 W' ~. |  X' k
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);2 ^5 I: E6 A4 W: \; S
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    7 t0 j& f6 o; G# l1 `* w: s  O* O6 c
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    7 u, @8 H$ W# `1 W8 `# ~
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    3 O* p( z0 N2 V2 b4 [+ p, [1 h0 B# J
  18. / ~. N0 k( N( v/ ]
  19.         // create the ray 'into the screen' at the selected cursor position
    3 m1 Q. P' \$ V# ?
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();( K2 N: [) Y. ?
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);" e# g' W: s5 q9 C
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);8 |1 @- a! \  g" x& N- a
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
      {5 S9 _( m% W6 w2 ^
  24.         lineRay->SetName("Ray");; C. ^, i: X0 I! [+ A5 P
  25. * K5 f1 D9 M5 B
  26.         // create the plane from the view to intersect with the ray
    5 B' H6 m) I" o! j; J
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);* D) o  K6 `8 D6 R0 z/ B
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);9 l  O' C, g0 P% _
  29.         planeView->SetName("ViewPlane");
    - o0 T6 m$ y% k" X/ X2 E

  30. 5 R5 ?* r/ r5 ~
  31.         // now create the intersection point
    7 d: b+ T3 E; A+ K
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    5 A! Z- M0 f6 T
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 z. n1 i  C1 \4 t# P
  34.         pntInterSect->SeTColor(10);
    2 S0 |' K( E4 U, ~3 ]5 D9 Z$ e
  35.         pntInterSect->SetName("Intersection");
    1 i& h4 G' x+ r

  36. ' v! M2 u$ |6 D9 c3 p
  37.         pos = pntInterSect->Coordinates();/ @  c5 U" W7 k0 r7 N1 A: \
  38.         print("\nPMI Position:", pos);0 f* S5 A+ u4 f

  39. . N% q; Z8 {( n5 u8 V
  40.         // clean up - comment to see intermediate objects5 P& f/ ^. H6 a) F# f2 b. F
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");- F5 v8 F" F' p
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    / Y  [( ~6 m, @2 {: e0 u7 B4 h3 C
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);& r9 n# Z; i1 c: \8 A* X
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    ! }& T4 |1 [- j9 ~& e5 X7 B
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);5 O( e5 t( @& q) J# o* a
  46.         m_session->DeleteUndoMark(markDel, NULL);
    : D0 ]2 R$ ?+ e0 A

  47. ' Y) P8 G! e3 S
  48.         return true;' Z0 r. Q/ t/ R. U# g& d
  49.     }
    9 k* E# N: L! C' E$ o; _
  50. + ~% y! F8 m# H8 U/ N1 U" S
  51.     return false;  H2 ?* U; s, d
  52. }
复制代码

# ?; U! ~1 @' J! ~0 N: n) ^; @' Q! M; x+ B4 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二次开发专题模块培训报名开始啦

    我知道了