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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

/ L% b! ]( V* Z6 J6 l* D
( b) v" R. r) W6 h- p4 ]( U1 H如何获取选择点映射到视图空间中?源码分享
9 Z6 W! u1 z+ X+ n
& _/ a, o. l( a% v$ n' ~0 j( t
  1. //------------------------------------------------------------------------------2 ^+ M; u) D2 I% V5 J& L: N, T8 r
  2. // Select Screen Position and map to Modeling View Plane" ?8 X4 D9 i  u) D2 Q5 m3 R  Q+ s; I- C
  3. //------------------------------------------------------------------------------' ~* r# g6 K; [. q! G6 K# I
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos); b3 D/ q5 I2 \( q% y+ o* O0 y
  5. {  H; ]8 x$ I* f% ]
  6.     NXOpen::View* myView = NULL;
    ( e" `# y. A3 f1 R/ ]# m
  7.     NXOpen::Point3d myCursor(0, 0, 0);: F* w+ \# J, P. I5 m

  8. 9 F! s) F0 c. c# q! L* v; p" v
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    5 P6 g; ^: H8 \& K# V; m
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    # E* H2 q4 v6 Q9 H8 |
  11.     {# u/ [+ O, M4 w3 n# ~2 S. J6 y( p# y
  12.         // obtain the current default annotation plane where PMIs are placed on# S3 L( [. x4 e9 ^7 g: c
  13.         NXOpen::Xform *xform1;
    $ U6 ~- [' N3 j: R- `6 b- X8 X
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    7 S2 t4 e6 |* {# n$ p6 U9 I6 D
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    * n; Q, O& \4 n4 _! _# D
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();5 x7 `. v3 Q- A+ e5 I; C
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);; k4 F( `9 e6 O6 b. b

  18. 7 a  f- N( a- r0 E
  19.         // create the ray 'into the screen' at the selected cursor position5 `! d6 |: u, o9 F  }3 a6 R
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    " |/ R3 |4 p1 k8 R$ N# I, _
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);; m% g* w) O+ H+ G/ m6 j( G8 Q. o
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);) O: R' Z1 T; |
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);) a: G' W+ r5 d5 Z  ^% U; S% q& H% H
  24.         lineRay->SetName("Ray");
    ; T8 x( Z1 I8 d, \) l

  25. ' g# L. u5 l5 [
  26.         // create the plane from the view to intersect with the ray
    & ~0 P. K4 b( R2 H4 R7 s+ v; @
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    # D- [( t3 S( |
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 c# L% P, ?+ g6 R; A
  29.         planeView->SetName("ViewPlane");
    3 J& e) u3 W7 O7 Q- @
  30. / ~. K' v0 f8 T$ ?3 ~! M
  31.         // now create the intersection point
    8 k4 _: X8 d1 k+ a1 h
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 @/ V9 B6 l; C5 g
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    6 s6 F1 P/ i, N! I6 v# g4 L
  34.         pntInterSect->SeTColor(10);+ z* q$ a8 M1 @
  35.         pntInterSect->SetName("Intersection");
    2 N% y0 \" w# O( I

  36. ; Y+ ?! P" S" e
  37.         pos = pntInterSect->Coordinates();
    % |/ ~$ J+ Y$ J3 B, u  e7 E$ [
  38.         print("\nPMI Position:", pos);
    7 m- Q2 r! |$ d; N; R

  39. 7 t  T2 F% V( V  o# d' ?7 V
  40.         // clean up - comment to see intermediate objects5 y- i* P( ?4 W2 k; \1 b
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");: _/ R  Z- @9 F& d  G2 ~  K
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);" q  y6 d: K7 o  _2 u1 z
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);) m6 q: ~9 f+ z3 U% @: N9 }& k
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    6 ^3 w, |. ~' C0 ^
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    4 _9 i7 K, h8 Q4 D6 L! p) a! B) z
  46.         m_session->DeleteUndoMark(markDel, NULL);. `, D6 q, b- U" O+ T. r$ b" I

  47. 3 m" g9 ^% h$ n7 G$ W
  48.         return true;( C+ C' X4 w0 I9 y& z; [* c& [) B
  49.     }
    6 E6 y+ \% ~9 Z6 c
  50. 4 R" `& P6 g! |% b3 W
  51.     return false;
    - ^/ |4 a% c* d6 E; o# x1 Q
  52. }
复制代码
- X- N* H$ i' ?5 Q) A

' C- Q4 K; x; Q8 L2 V- e/ `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了