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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
: t( ]9 r2 ^( T6 S4 U+ {; H9 A
9 a! T8 H4 y' I( P/ |( x6 ^- W
如何获取选择点映射到视图空间中?源码分享, B. n6 f! d' f. F5 P& [
( F4 L3 y: H- N7 i
  1. //------------------------------------------------------------------------------
    % |- S! i9 t  S& m, k( R
  2. // Select Screen Position and map to Modeling View Plane: q* b0 z9 B  w$ f$ ^5 A
  3. //------------------------------------------------------------------------------
      @5 V' g% h% l# q
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    % l( n' Y/ C" |! `8 W8 i9 K5 ?" d
  5. {
    * ~% \# W' ]1 B
  6.     NXOpen::View* myView = NULL;' c$ B: Z2 h2 n3 I
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    & M0 r" d  r3 ]1 g. J7 W' Y
  8. 1 C# {& c$ N( m) i* M$ X
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    1 P3 T7 d1 H0 L# z: V
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    0 u$ f: [2 L; i# r) I9 a
  11.     {4 x% [: [* c" a& L4 ^8 q) x) n$ ~
  12.         // obtain the current default annotation plane where PMIs are placed on
    9 q( Y1 [* r" O: g( R' a4 ^
  13.         NXOpen::Xform *xform1;
    & {- s1 K7 W3 p2 e0 T! `
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    # O) ~+ F% R- |
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();" d+ E3 h/ U" N2 b$ ?
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    $ }. C* P3 g1 }( U
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);5 j0 a6 Q; @6 z9 `$ F$ z; n! p% n& |

  18. % s+ _! g3 R" r( M* E6 [: I* p
  19.         // create the ray 'into the screen' at the selected cursor position
    6 z9 @7 \, X9 \. Q3 M3 ~
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();4 C" s* X, X% W. N7 ^0 E# Q2 q1 M- D
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    8 J% T2 u# d5 T. A; ]+ X- l2 a7 s
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    # B3 C9 F& \8 J6 w
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);' e/ k. g4 e. u7 b- C, Y/ y/ Q
  24.         lineRay->SetName("Ray");
    8 v! R' ^7 V6 c
  25. ) s5 {# N0 X2 ~$ ?! b
  26.         // create the plane from the view to intersect with the ray
    0 C: L( I2 S4 S5 I
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ; m& U; }1 L7 F- W! u* ]
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ( a9 B+ `( y; q: L/ X9 F
  29.         planeView->SetName("ViewPlane");
    9 I2 h; f1 s7 N7 _1 ?& e& I
  30. 0 C8 R% ~5 ^; u/ O9 A) Z$ M6 k* S" M
  31.         // now create the intersection point' C9 E, P. U- |2 m6 n! f
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    6 |$ t9 X% Q2 i3 r' x" f/ p/ V
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);. V7 z& h. x1 @! I
  34.         pntInterSect->SeTColor(10);/ ]& u3 g. D8 ]* y
  35.         pntInterSect->SetName("Intersection");
    ! B" r9 f8 E/ |
  36. : M+ \8 t0 S/ h$ P: M+ t
  37.         pos = pntInterSect->Coordinates();
    . Z: S+ f# b( w5 H! a2 s' B
  38.         print("\nPMI Position:", pos);9 K4 L9 d1 G( [7 Y5 @% W  F+ [* S

  39. ( E4 O1 q& c+ v. F2 w. O
  40.         // clean up - comment to see intermediate objects
    ' d( K- I8 k$ I9 q4 s
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    : d! n; i. }- {7 M" t* m  W3 U' e
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);) P3 |8 q' U8 u. C* f6 o
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);! I1 _1 ~1 w' p/ @' I
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    . @2 W5 f+ F/ I+ p( x
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    ' K+ B4 u7 s* O) Q/ J! k
  46.         m_session->DeleteUndoMark(markDel, NULL);3 F; `  p) g8 b, B# h

  47. : u5 R$ |% O4 {. G* ^: o
  48.         return true;
    , A. f* }: d7 y: |/ w! T
  49.     }
    ' g7 m& M! N  M" n) L
  50. 9 A+ M' H7 j. n8 C: w5 r
  51.     return false;
    9 t5 [! @+ F. N1 A0 a
  52. }
复制代码

# |. o9 k+ N5 G/ G$ _
* `  z! p$ q( K, n: i; x* y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了