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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
. H( a) H# b. O/ k0 k
2 r* ^# G) g8 |2 j& w+ @% A
如何获取选择点映射到视图空间中?源码分享& t) o! @- g( x+ S$ D! o  U2 l
$ I5 w$ l! Y' |2 T1 ~# l' O
  1. //------------------------------------------------------------------------------
    4 v* ~& ]5 b. C: g- c
  2. // Select Screen Position and map to Modeling View Plane/ C8 n/ O: C3 q% t" X1 H) q6 ?/ V4 \
  3. //------------------------------------------------------------------------------% }2 U2 U. ]2 a& B6 J' g
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)5 ]: ~% a9 `( ?( ?5 x% L7 l
  5. {) r4 B% \4 X7 a
  6.     NXOpen::View* myView = NULL;
    3 r- R5 G1 P. s1 d5 }( d
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    8 h, P" y7 h! g, l- _- d

  8. " J0 ~1 Y/ I- q- N4 Q
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    5 Z7 |( g& d3 b
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    9 [* \2 a$ D- d' i) k
  11.     {
    % v0 B& A1 H& r
  12.         // obtain the current default annotation plane where PMIs are placed on# K5 J7 y7 h) R5 p  b6 b
  13.         NXOpen::Xform *xform1;
    ! Y! l1 L9 j3 A7 P, l6 M3 M$ s
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    2 {5 G9 r# r% ?1 |& Y5 Z' G& E: l
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();' ~# n8 ~, T) b4 \
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();! x. d& @' _) f. m: w3 Y
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);4 c- \- R3 \2 X) X" k

  18. # b. l0 `$ V% w. \1 p3 ]
  19.         // create the ray 'into the screen' at the selected cursor position! A% A8 G5 t2 M, h! Y4 B+ e
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    , O+ f% v0 j) n/ B9 \. w
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);- u  ?7 o. b. R5 s- X: L
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    ) C  l/ W' f3 b2 Z
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);% A: v7 x$ W; }' O( t9 e- j9 E
  24.         lineRay->SetName("Ray");
    ; @0 t0 Q; b) ^

  25. 3 S  Y& F( s( ?8 P4 |5 D; @
  26.         // create the plane from the view to intersect with the ray7 a8 o; h* c- Q+ T( I* E5 P, |9 |/ [
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    * l) d1 w. I& c2 w$ G/ \
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);$ n; R- n- Q7 q5 q  g/ L
  29.         planeView->SetName("ViewPlane");& q/ b( I+ ~1 E2 f

  30.   |, B1 d" o* Y9 ?
  31.         // now create the intersection point
    * \  S: Q* a. ~9 K3 E
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);6 v( ^' Y0 a7 K% W5 E3 `, m# J- v: ]
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);6 \! H9 y8 h+ W9 I7 B. [1 M
  34.         pntInterSect->SeTColor(10);
    0 u, J# B8 M( {: }/ D
  35.         pntInterSect->SetName("Intersection");
    9 `! R9 q5 W, P" i

  36.   @: n# X- e" _/ w; W
  37.         pos = pntInterSect->Coordinates();
    . N8 k$ ^! B, m* A9 C
  38.         print("\nPMI Position:", pos);# ~# s) N; |' Q3 A

  39. " [4 c+ z: r9 {+ P  J% G. N
  40.         // clean up - comment to see intermediate objects
    0 ^* y$ k' K/ H% {
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    + a. h6 ?- E1 w  {  p4 t/ W; V
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    2 R/ o# o3 Z1 N. @# @
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    ) W6 t# b7 f& `# s: U% `4 U1 ~- N
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    8 ?: b! s# m3 d, e8 A& q9 F4 x
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
      G4 i8 \1 S% X7 p7 U% C  D1 w3 |
  46.         m_session->DeleteUndoMark(markDel, NULL);/ p% x9 M3 ^6 q. Z5 u* k

  47. , w$ h& U* P1 ]2 \$ r- p
  48.         return true;
    ; N5 U% K# Q/ ?* N3 d
  49.     }
    & i3 b& e( z) |( w& V6 p- o# G3 ^
  50. + f* w% u  m- n! G
  51.     return false;; q( i) c( t5 @) e; {! m+ V
  52. }
复制代码
9 B0 n9 H  D0 s3 q! [5 r

+ y% }/ E  {# C
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了