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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
+ w  P$ c' m3 Y+ L8 w/ @

5 T4 F5 v0 B; a8 V( y+ A1 s如何获取选择点映射到视图空间中?源码分享
( {8 s0 I5 j! H5 t* ]. X; z+ m/ I( }  o2 F1 t. T& I2 E
  1. //------------------------------------------------------------------------------, D7 P  P5 K- Q; E
  2. // Select Screen Position and map to Modeling View Plane
    & B: K: F; w6 t! Y' j" N# b% h
  3. //------------------------------------------------------------------------------
    # ?+ S* d/ k0 O6 h) z$ {- x; |
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos): S) z: N2 _% |5 y- F
  5. {5 n" w  e( G3 \+ p7 o8 H0 Q; G
  6.     NXOpen::View* myView = NULL;* x0 Q% z, I- C8 J) Y" b% e
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    7 X2 _3 F) T$ W; D  E
  8. ) s' p8 c' J3 Q, K- b) x
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    9 O( D4 p0 y1 M8 i
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)4 U0 Y2 d+ h* ]- D$ v8 {
  11.     {9 C; t4 |$ C6 D( D( c
  12.         // obtain the current default annotation plane where PMIs are placed on
    " f) w- u% |- h- g
  13.         NXOpen::Xform *xform1;: l# w/ I- W* R; H1 }. l; M
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    3 }$ \4 G# Y' {1 k9 @0 v# y0 S9 I
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();2 Y7 }, T/ M1 j, ~2 q
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    . Q! J: x7 Y  E  K$ m
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    ! v2 L* n& X) l- ~' Q6 Y- ~8 j

  18. 7 [% n/ ]: ^; [8 ^/ L0 \
  19.         // create the ray 'into the screen' at the selected cursor position( r7 r- b: ~6 s/ g
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();3 r3 d9 X  U) G: `; Q' b& @
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    " n" ~; R2 D* v/ O* c: e2 \9 j+ o
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    1 J0 X4 t. q9 E$ X$ D+ ~" X
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);4 c( O, }1 w1 S( i
  24.         lineRay->SetName("Ray");7 K( K  o& u1 r1 P- A6 g' ~! ~
  25. 7 `& X  @/ p% I0 p! w/ w
  26.         // create the plane from the view to intersect with the ray
    8 `8 F3 G0 S9 _5 Q) {1 M" G
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    . @" a0 w) l3 L4 Y. x% X) w
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);5 s* ~/ y% X- v9 S1 o
  29.         planeView->SetName("ViewPlane");
    8 Z* [4 ^; f" y& ?9 R0 v

  30. : l% {6 s, H) N2 s) v9 d1 R# w
  31.         // now create the intersection point" A3 D; l9 E8 K: W4 A
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    # G* g$ }- W7 A2 W; \0 P3 _
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    . L! i# R: J8 W  w5 q4 q. x1 I  F
  34.         pntInterSect->SeTColor(10);4 P# m. X3 S; z/ m
  35.         pntInterSect->SetName("Intersection");
    * |2 R. l, s# d% r: V( D

  36. 6 F4 D# D* o( C0 o
  37.         pos = pntInterSect->Coordinates();
    / l6 E: |* v. y! g; L& W
  38.         print("\nPMI Position:", pos);" c) l9 E( J8 x8 a: j3 w5 r* |

  39. ) d% [2 A( i' N0 O
  40.         // clean up - comment to see intermediate objects" \6 l' n9 x9 s% p# d- v
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    - {& f4 u+ }2 U
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    ) m0 q$ P6 o7 b' M& u! J6 J
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);5 _3 |/ O$ F% z) W& I/ B4 q- @  F9 O
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    - A6 t! j5 ]" ~& E
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);- z, [9 q( B* U) W& o0 {  |7 L/ b
  46.         m_session->DeleteUndoMark(markDel, NULL);
    6 j4 p8 ^/ R& d' @

  47. & D: `( T; k, U; o2 ?7 V
  48.         return true;
    * m6 ^% W9 P" L6 l$ C9 \
  49.     }% S, V( T( S9 X- D* g; j5 W
  50. 5 z* D1 y0 ?  y1 Z; k2 o/ G
  51.     return false;
    8 K$ x# h" U& T
  52. }
复制代码
5 ^2 ~& B2 A9 E% ]9 ~6 ~
: W% d+ r' L. c% |2 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二次开发专题模块培训报名开始啦

    我知道了