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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
) ?6 Z, }+ h% b# b3 n8 V

& M( M6 s  P4 s/ a8 n* P* E如何获取选择点映射到视图空间中?源码分享7 _; o; L$ [1 U1 Y* J) X; j
* ]6 D$ c, z+ {7 Q9 G7 v
  1. //------------------------------------------------------------------------------
    8 A/ S2 X+ k' j
  2. // Select Screen Position and map to Modeling View Plane
    * X, V$ v4 K+ ^. y
  3. //------------------------------------------------------------------------------( ?9 X# j' R6 b8 P3 m
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    9 x  F# _* C& ?
  5. {# A/ ]* c( P& ~# @0 T$ l7 H
  6.     NXOpen::View* myView = NULL;
    8 \6 b7 \# S8 A. c0 y; N$ o0 E
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    ; s6 |3 w& P: c# {

  8.   K" T: U/ ~3 F# f
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    / w1 z3 }0 ^) _
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)* i6 D. Q. t, `9 S* X  O# n
  11.     {
    7 F' }, K) R% ]  ~
  12.         // obtain the current default annotation plane where PMIs are placed on
    * M; A; P9 {& ~) P* u5 x1 o& M
  13.         NXOpen::Xform *xform1;
    ( u, j3 ?% A' |+ a5 V5 K) O
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);# e4 L1 T5 Y1 b. S! ~0 a8 X
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();5 \2 H5 Z1 k, O' `1 U
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    3 [0 @" k  T. ^; ]* W2 m: ^0 K
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);: n: w9 O, g% a/ q3 A: }
  18. " m6 Y! z; r. B5 ~; L6 J
  19.         // create the ray 'into the screen' at the selected cursor position& v$ Z7 w& T/ A) g1 ]  u! S. R" _
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    7 t9 D! Q1 q% @3 }! C4 q7 W
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);" i. t, {+ i$ O5 G$ @2 Q2 l$ a
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);  V# O; x& A0 q7 m( [
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);8 m& Z7 }9 K3 J" K# X/ a6 x1 a
  24.         lineRay->SetName("Ray");8 _/ H9 {- }9 ?7 R
  25. 4 s  d8 c6 R! |9 c9 X
  26.         // create the plane from the view to intersect with the ray& `  ?3 X- G+ W! T
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    1 V/ b! n- {5 ~. l) B/ k
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    $ x7 B' ~9 ~! l# f
  29.         planeView->SetName("ViewPlane");
    9 H5 |. B( U5 l9 t: ~4 x! i
  30. ( U* f9 z1 ~6 H
  31.         // now create the intersection point
    : f! Q& f: l8 t0 `
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 L8 X4 t' |+ K
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    2 p1 d* i( U! E, h* H8 a* t% d
  34.         pntInterSect->SeTColor(10);! }1 n% g/ Y  K( m2 j1 z, {
  35.         pntInterSect->SetName("Intersection");6 }, b  M5 w0 F) F( v' I  \
  36. ' z# {) ]/ O- o9 p/ G
  37.         pos = pntInterSect->Coordinates();5 z  i7 q. m  D9 D
  38.         print("\nPMI Position:", pos);
    ' G4 q8 ?9 N  V1 F7 S$ q  D, v/ n

  39. 8 J" W& X6 [8 x# p8 l1 r" |
  40.         // clean up - comment to see intermediate objects
    1 _2 a/ J8 R5 f  @4 @# y' @
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    5 c. J% A# [0 J
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    " P4 E4 F/ P, ~
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    - Q# |' `( k7 }9 G3 t
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    ' C: s5 E" A( ?" z
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    " y4 U7 h' U. ]* V# W
  46.         m_session->DeleteUndoMark(markDel, NULL);! L4 x8 }5 b8 H% c; ~0 a( Z3 D

  47. ) T* l, j2 l5 u7 n, o8 U% o
  48.         return true;
    3 @2 g1 |; W" u  ]# N% j5 @
  49.     }
    . n6 a2 P/ [8 @0 ], M1 S

  50. 3 ]4 Q2 C2 Z; M+ @0 e+ U* ^. D9 ?
  51.     return false;
    4 j  X; f0 D1 h; a
  52. }
复制代码

3 V# q% i3 D8 z) L4 {* |. Y: d) {5 t
. R, c  }2 X/ d( 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二次开发专题模块培训报名开始啦

    我知道了