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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

' e) x; P/ E, t$ j. t/ a( d/ g! V& `: d/ a- c# [' K- m% g
如何获取选择点映射到视图空间中?源码分享1 A5 q$ \& Y5 l! ^2 k" c
" I' l, a$ {0 y1 W
  1. //------------------------------------------------------------------------------1 ], y8 [& A3 M& ~! I
  2. // Select Screen Position and map to Modeling View Plane+ y. y/ K7 N% l) V: G! l
  3. //------------------------------------------------------------------------------
    5 l5 @& F, X+ \0 b9 k) \0 f5 D
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)8 M" O% u# Y" }
  5. {
    , @: R7 t: i% }: Z* [" B
  6.     NXOpen::View* myView = NULL;* |+ s- c7 Q% R) O
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    ' g# K* {! ~# p0 V, G- J

  8. . |1 W4 w: i8 D2 B5 E. S
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    + F9 c! ^2 w$ P% d! K
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)" Y6 C9 c9 L% z, K. \2 |
  11.     {; |. d  Z0 @  m1 ^( \* f: d
  12.         // obtain the current default annotation plane where PMIs are placed on
    7 M3 W3 q3 m( b3 W
  13.         NXOpen::Xform *xform1;
    4 I& S1 i$ N8 t' H3 f2 Q) x
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    * j0 V. h( s6 M: o$ j( E1 `
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    ; x1 i- m" Z, `0 ]6 ~0 `2 ^* g
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    + P+ j7 Y, G& a$ q. ?! P. S1 ~
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);2 J% k# l6 |- G5 h8 U
  18. - K8 i+ u7 H' n2 R" r: \
  19.         // create the ray 'into the screen' at the selected cursor position
    - c! M2 ]$ H! H# x4 @! z; ?! P
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    8 }! y5 X* U' j0 O! ~
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);* ^0 D& W8 [3 h1 |% }
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);5 e5 h6 Q; |' B) A- R# L8 `
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);5 [3 @' Q2 I7 Q7 t3 p
  24.         lineRay->SetName("Ray");1 p( w; z9 G& o# S6 q. `

  25. ) i7 Z' h3 ?6 o
  26.         // create the plane from the view to intersect with the ray* u! w: {7 g; r+ G# `
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    - T2 ^# D5 K- C
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    - k) r3 ~  E: a) G2 `% G
  29.         planeView->SetName("ViewPlane");
    $ {( B- a# h, t1 \' X5 Y  J! I

  30. * [2 P4 Z% v# Q) y7 m" j3 C+ {5 h3 e
  31.         // now create the intersection point
    , ?) ]  ?, i' L+ _2 k
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ' F& T6 i# l- k8 J
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);% N0 A$ {, T1 m5 i8 d* u
  34.         pntInterSect->SeTColor(10);
    , x  T' _" o- F% l) y8 U
  35.         pntInterSect->SetName("Intersection");' U* v1 C. s6 k% }# b0 u# d

  36. ) ]1 U2 H) e% l( f' x
  37.         pos = pntInterSect->Coordinates();
    & N0 g9 _8 c( z
  38.         print("\nPMI Position:", pos);
    - A( b5 K- Z6 p) d$ w+ d6 e
  39. * |6 s$ K) F' ^( l+ \5 D' o
  40.         // clean up - comment to see intermediate objects
    ' I) L5 F3 K( o9 W9 x
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");/ U/ W& y1 M+ h. H. Q3 o
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    6 n: ^3 X7 n8 g* V
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);" Y7 a! \( O9 z" O
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    & r1 p) D( K5 l2 n1 r# B* r
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    : P! V' u+ y3 j
  46.         m_session->DeleteUndoMark(markDel, NULL);
    + S. f4 h  }. N% X% |
  47. + G# `' ~/ _0 N" L2 h$ ~
  48.         return true;6 N5 v  x) D3 t
  49.     }3 q6 q9 Q: r/ X: H* I

  50. : d+ h- d* w  G9 C& j0 L8 w* N5 W! i
  51.     return false;  o$ n" z6 r# ?# p2 X. w/ ^
  52. }
复制代码

( ~5 ?" p1 E4 \( W
) ]5 m! e6 f4 \8 s& {, f. d# w
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了