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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

) Z' M5 a1 a' r9 E- f
: V) y/ q+ b0 d! P7 o如何获取选择点映射到视图空间中?源码分享$ b/ t) O7 e$ w; Y/ n

/ z0 c) u0 W2 L" |! t' T
  1. //------------------------------------------------------------------------------
    ( q: l$ f+ o" d8 a3 ?7 P( S1 x
  2. // Select Screen Position and map to Modeling View Plane
      F# x9 e, f! |! N3 y
  3. //------------------------------------------------------------------------------
    $ |3 \0 E% u& I8 A' j
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    5 r2 \9 F4 D& \* k
  5. {. W; l$ P+ a1 }0 ~/ k
  6.     NXOpen::View* myView = NULL;, p* }3 U% n- f$ Q
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    ' L- w& l+ o9 s% F% f- e

  8. - ^9 e4 \/ c/ r- c  f; }
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    " W8 V! R& h$ m# A7 n- F
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)# n1 ~( V9 F/ r* m5 W/ U  m
  11.     {* B& k! [, i1 d. r
  12.         // obtain the current default annotation plane where PMIs are placed on  p  E( `7 a& J; _; Q# B4 h
  13.         NXOpen::Xform *xform1;, I+ {6 Q2 q' G
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    3 K3 I3 D" c; H& s
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();# q3 t: U9 Q9 j1 Y
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    1 s* V# o& ]6 B
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    . y5 R+ z! G- S/ O  Z

  18. - w# ^! a6 K* ]8 l
  19.         // create the ray 'into the screen' at the selected cursor position+ q4 p. X% d0 N
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    : r% q0 ~4 a9 L4 {
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    # K. D# J4 Q2 z+ Z2 c% k9 ?
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);7 \) p( E$ S1 o0 q" X
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ' a2 N# G% K2 V9 K, P$ \: Z
  24.         lineRay->SetName("Ray");
    0 ~# A6 T7 ~& t

  25. & [, U: t+ g8 ]) K; L" [) K* B
  26.         // create the plane from the view to intersect with the ray; o- `, I% [: ~/ ]5 E1 H
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    # a8 o. F; J' e) \0 D
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    & B/ ~$ _9 t/ J, {
  29.         planeView->SetName("ViewPlane");
    9 ~0 c! u1 D0 N/ ]  _, Q( O

  30. , f+ p$ c" c% j$ N
  31.         // now create the intersection point
    $ O4 ?2 k7 u, O# W4 k; B$ I
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);$ t* j, _% Q: g2 |+ X
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    / {0 K9 i+ t5 r- ]
  34.         pntInterSect->SeTColor(10);
    5 i9 ^2 J) n0 y. z  ~! `
  35.         pntInterSect->SetName("Intersection");
    * D# p# h" c; O
  36. 2 R( @2 T& B* r6 Q! z6 _3 C7 {, i
  37.         pos = pntInterSect->Coordinates();8 ^+ p: V4 A  P3 c
  38.         print("\nPMI Position:", pos);8 Z% `# a- C+ J3 y: @. q( q

  39. ; R) _! O1 n* U
  40.         // clean up - comment to see intermediate objects/ a4 @; Q# b3 l) x
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");& i% Y. d/ V( c# B* B% x
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    ; K. b$ I) ~( ?- ^4 {5 Z/ h- B  ~
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    0 d1 l; L% l0 U0 H( }+ ^
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    % H# Y; s5 e6 a! [& x0 f% s
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);8 |3 U" O0 k, s4 I& p' D+ l" Q
  46.         m_session->DeleteUndoMark(markDel, NULL);
    : C: X$ ^0 n6 [+ i

  47. $ l' ^/ B3 F3 I9 T5 R
  48.         return true;
    + l! E" {1 J( z$ a& e( S, o; O2 \
  49.     }
    ! j  [8 @8 @) Z+ W: f+ c# Z' z3 S* H9 a
  50. ; }3 v/ k5 \; _+ S; @' y9 c7 A+ ^
  51.     return false;
    / y* A& x9 v8 j
  52. }
复制代码

; F7 z' e* L5 G6 g1 Q
; d% |) X9 Z) C8 W, q7 d3 O
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了