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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
2 M; {: B  O: U. r6 d! Y) q6 ?) }
# P+ p8 S2 ^+ I
如何获取选择点映射到视图空间中?源码分享& p+ o( h, K$ ~; Y
" K/ z, U5 p. a$ Q6 W
  1. //------------------------------------------------------------------------------* P8 n. r6 P/ S' p
  2. // Select Screen Position and map to Modeling View Plane* Q- |; E8 G1 o3 F
  3. //------------------------------------------------------------------------------1 e- K* \% E3 A; I/ \
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    % c" o, x5 z, ~5 c* g8 d) e5 z
  5. {# c2 i+ f+ M2 v* f, A4 ?& X
  6.     NXOpen::View* myView = NULL;
    5 M$ P' b) d, F2 U6 d
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    * O/ ^3 ~! D9 Z6 v
  8. ( ^& H' l- W' E% K9 {8 O
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);. {/ T* j" k8 B5 P
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)* U: n$ a- n/ \4 l
  11.     {
    1 k0 z4 i' P5 e' \- w. _
  12.         // obtain the current default annotation plane where PMIs are placed on2 O" p: S0 a3 A4 l
  13.         NXOpen::Xform *xform1;
      n9 t1 N8 {, p7 J: D6 g4 K
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);( H3 o5 }+ o( e, J: q& O
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();( e2 u8 B- H- `+ n7 Q: Q8 \
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    ! d2 f. F- R6 x: Y& ?+ `3 x
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);: q4 H; |: _3 y0 J0 O9 m

  18. & ~2 `* O- U# ?& s" H1 v
  19.         // create the ray 'into the screen' at the selected cursor position
    % @- y( A. @  ?) y5 m# x3 _
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();, w6 s4 Z2 j7 ~$ F0 b+ G$ o
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);7 m3 \- L+ n0 R$ q2 `; V# C, Z
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    8 s9 P9 x# w/ P1 y% f
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    5 \" P7 J" E% W! H
  24.         lineRay->SetName("Ray");0 v& S; H* B* j

  25. 4 Z7 A4 `2 N! T3 y2 S
  26.         // create the plane from the view to intersect with the ray- D4 T8 q) G4 q) W, P
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
      X% ^/ G$ [1 V" B* N5 @% ^4 l0 F- t3 D
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 P! K, t. J  l/ h
  29.         planeView->SetName("ViewPlane");6 p  `9 X$ u# |" a
  30. 3 |: E" D& X6 E0 D+ l
  31.         // now create the intersection point
    & [" O2 n  X7 e0 }# ^
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);& H' u2 \9 Y- |. C
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    6 s, O5 V4 A9 v# ^* {4 O& ^
  34.         pntInterSect->SeTColor(10);; Q8 {( [, ^2 \$ ]7 R+ I! T$ p
  35.         pntInterSect->SetName("Intersection");6 s; A$ E& t, l5 `# {/ z& w' M0 a' g
  36. + I! y% ?- G& ~+ [! \) y
  37.         pos = pntInterSect->Coordinates();' n8 r/ M6 l) ^+ ]& g7 K
  38.         print("\nPMI Position:", pos);3 u6 P: M. j5 `, V6 h0 `
  39. % l: `) |- Z0 s- P+ A
  40.         // clean up - comment to see intermediate objects1 r; O1 F5 o; Y# H' j
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");/ a1 k0 [/ Q" \  }' ^! O; ~
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    . E, g9 E1 L" S# i& S) \: `, S
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    + |$ V5 Z% n( H4 i" V' B4 \* t
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    " a; h. j/ v) J! S0 }" n: h3 L
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);: @# C% a7 ?6 Z2 Y1 R* j0 Z" k
  46.         m_session->DeleteUndoMark(markDel, NULL);" A% {6 }/ A8 ?1 O
  47. . L) j- `$ R0 j( T# n
  48.         return true;
    & X! n& X+ N+ w* e' T
  49.     }4 C# f: o2 z* D6 f# o; V

  50. ) I5 E7 `& y2 L9 K' m6 Y6 `
  51.     return false;5 |4 y; D- r- U1 e3 M
  52. }
复制代码

5 k2 b# A9 k$ b" N( K
* d/ G! r- q; Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了