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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
( ~! l$ d- T5 @4 w) T

/ M1 i  H, o& r如何获取选择点映射到视图空间中?源码分享7 n$ ~, n0 K0 a: W
7 i3 ?& ^+ ~8 U2 O
  1. //------------------------------------------------------------------------------' Y6 d( i" S, m0 y* R. w! w
  2. // Select Screen Position and map to Modeling View Plane+ m' C. @( O+ w1 o! a6 _; ]! E
  3. //------------------------------------------------------------------------------- y! w, O6 q; y- i
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    6 B8 d0 H) A" }1 e# f: w( V
  5. {
    ! l7 b  P, k5 A0 |, J) ^2 N
  6.     NXOpen::View* myView = NULL;% F- l1 w: k" D- x& @. o
  7.     NXOpen::Point3d myCursor(0, 0, 0);$ S- W3 ?: e8 m/ d* I
  8. : L8 ?% l+ l% u2 m
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    3 |7 C9 \3 u! B
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)$ ]0 t0 }) M- k
  11.     {$ ]' e7 R0 f' i9 n9 i% V. W
  12.         // obtain the current default annotation plane where PMIs are placed on
    - R" j, _4 d2 R+ `8 Z  G; A4 ?' k
  13.         NXOpen::Xform *xform1;
    + N) X' A3 L% e6 C
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);4 a$ x! O7 v  R3 O
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    , z$ q0 W% D# G- Q8 Y
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();: {0 ~" K9 P# J, Z8 A
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);5 W% S& g  `) s) T! }
  18. ' u7 ^8 Q' p$ [6 I4 P$ m6 Q
  19.         // create the ray 'into the screen' at the selected cursor position3 a# O4 _7 o+ V4 U) d* N
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();% Y! P! c" }+ d8 x$ `! I/ j
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);' @, v- B2 k  j% ^# W8 B
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    + m& {' d$ f; E/ k
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    . ?/ _+ I8 y* i% t
  24.         lineRay->SetName("Ray");
    ! Z% v5 }0 e9 \  \1 w! i1 o" c
  25. ' x5 L0 p% ]' ]" w1 `
  26.         // create the plane from the view to intersect with the ray* ~( g, g9 M: T( ]1 _2 [' d
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);" v1 O+ b: i  \% p7 T
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    $ u2 v- `# |4 e' Z2 P( E/ }* b
  29.         planeView->SetName("ViewPlane");( Y2 g/ y! |8 B1 j( h  r# X$ J

  30. : r8 B, x! a$ T- Q7 i
  31.         // now create the intersection point6 O  a! _/ `5 o3 m* j7 L% O& B
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);7 z! P& E/ q5 m6 W5 @1 p
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);& w; n! o+ w, \5 U( J$ ?- \8 c1 m
  34.         pntInterSect->SeTColor(10);. S4 K+ f- G' R4 B$ H
  35.         pntInterSect->SetName("Intersection");: f  K% p% Q  C
  36. . {- z- I2 \- p5 B" O
  37.         pos = pntInterSect->Coordinates();9 u- |- H2 G( V5 C
  38.         print("\nPMI Position:", pos);. |$ _2 q' b, q" Y: r8 X

  39. $ F! n5 u* p( c  @
  40.         // clean up - comment to see intermediate objects/ {4 h) M) S/ C+ Q5 ?8 Q
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");+ R5 K3 c( M  y8 m. a4 w$ Z
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    " T6 X: y# V3 G# Y( ~6 K
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    - q2 M% a+ m  K0 M" p9 n1 L. s
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);  h# h/ y/ s; N" V
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);: l, D8 P  l4 _0 X
  46.         m_session->DeleteUndoMark(markDel, NULL);
    : y% l' T% K* `5 M! \6 V

  47. 4 Q+ P) N( K$ M: J/ \  j
  48.         return true;
    : m9 e' J, _/ b3 X
  49.     }2 A7 V1 B5 ?  `2 Q& m

  50. ! h! `( K3 v; C
  51.     return false;
    3 M% ?" k$ e/ `5 s- i; s3 D
  52. }
复制代码
2 A* f3 ~+ Q5 H% |& O

4 P* r) y, V0 A' ~3 U# 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二次开发专题模块培训报名开始啦

    我知道了