PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
/ ?$ P  i2 l( c( w
* t$ L) C1 |. n6 n( I6 s' t! ]
如何获取选择点映射到视图空间中?源码分享
- |/ M- v: u" T0 H8 l) N
  @! ^* q, ^3 U! |( N9 b; \
  1. //------------------------------------------------------------------------------
    , l' P' j* J$ Z' P% g5 U
  2. // Select Screen Position and map to Modeling View Plane4 q. O7 V7 j* @! c: n+ r8 P
  3. //------------------------------------------------------------------------------$ Z% h. j) U$ b: y! ]4 F1 ^: L
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)1 t6 n0 i7 `7 Q& o
  5. {, b3 ^0 f  ]/ f; r
  6.     NXOpen::View* myView = NULL;" `' d' J( A4 O" a6 n0 T4 |
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    ' p; N4 X- Z1 [) r+ l3 j. N; {+ D6 |

  8.   B  Z1 u/ |; [
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);2 u9 i3 J+ ?0 h0 I* D- A
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    & e% b) W  B6 c
  11.     {9 N# E/ ~9 Y! [0 c
  12.         // obtain the current default annotation plane where PMIs are placed on
    3 b0 z/ O4 P" M; e* C0 w
  13.         NXOpen::Xform *xform1;
    & I+ i3 [2 }& S8 t) _2 @: d
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    2 ?4 h* V5 c- ~! e, z) ^
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    1 C3 U  y. D4 @8 ]* @. T2 ?
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    7 Z: K+ q( J9 F' g: I. q" o
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    8 n* e+ C8 t+ P+ a, c! `/ a9 f

  18. , ~$ o. Y& L% g; U
  19.         // create the ray 'into the screen' at the selected cursor position6 r1 m8 M. `  A3 k# P  c! x
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();' C1 R9 w5 g* T0 j) ^: ]
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    ! [6 f% O- t& Z. V4 W
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    , t; A! C6 X* P& j
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);$ B" A  V9 ]! t- A! e
  24.         lineRay->SetName("Ray");
    9 A) V9 |7 W9 A0 E$ q

  25. & U% p) ~/ e0 h& s0 F) ^
  26.         // create the plane from the view to intersect with the ray
    0 ]" L* }! A  K
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);- w7 ^8 Z3 K8 j+ ^; r1 K9 {$ X% v
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    5 \9 n/ d! j- j% ^. f9 n
  29.         planeView->SetName("ViewPlane");
    3 c' z5 W, l2 \1 H

  30. 5 x3 k+ _, O1 [9 J  h
  31.         // now create the intersection point
    $ `9 w; p) c) L) {. O
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    3 B/ u( E5 @2 z4 m7 b3 H
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    3 d( H2 u. l  _' g
  34.         pntInterSect->SeTColor(10);
    / s$ v, ^9 r& Z$ j
  35.         pntInterSect->SetName("Intersection");7 ~1 [" w" f* J! F) i
  36. 4 E# [( q6 C& |9 F- W+ }# s, M& j
  37.         pos = pntInterSect->Coordinates();! t7 F4 h- ]+ E; u% Z( x
  38.         print("\nPMI Position:", pos);
    5 V& I6 n0 T7 T4 f  L9 y
  39. 2 g" X8 b" N# X4 @
  40.         // clean up - comment to see intermediate objects
    3 u1 O4 D/ s5 ~- @% B# Q# O
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");$ d5 p; A  `) D
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    # O, r9 h" N- P! }" j. q, f
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);& Y1 c) q5 m5 g' A  B! M1 p
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    ) r/ ]& X- k. u9 @+ c' ?5 l. _& ]
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    & |1 w" L/ X- r5 h8 T' ~+ F/ a
  46.         m_session->DeleteUndoMark(markDel, NULL);
    ! ~) j8 L( I/ N- N! `( x; W/ J
  47. 7 k* @( p, B% N9 U
  48.         return true;) o, U& f5 f+ Z: b1 f5 B
  49.     }
    . K& _& C' d# E& S" W) a1 ]

  50. : M/ h$ t  I+ `* x8 P; @4 c0 G& c( i
  51.     return false;) w9 A, o3 c+ N. y  {
  52. }
复制代码
; i* n* l& k0 n( J
; j& y/ E* E5 U* y& U
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了