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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
3 ^' K! y+ r; n2 A( ~: F+ F  R" X

7 e6 F  x/ R: R$ k1 q4 a如何获取选择点映射到视图空间中?源码分享
; l4 S0 o5 X  M6 @
' r( i, u5 ^& x2 r* ?3 D
  1. //------------------------------------------------------------------------------
    , @  b$ r" v, E$ y* }" ?* K
  2. // Select Screen Position and map to Modeling View Plane
    5 G+ |7 j9 Q. [  o9 u& H& B
  3. //------------------------------------------------------------------------------
    7 n( L% E' J5 T6 ^8 a
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
      _0 h. z0 `4 o
  5. {0 G0 [2 C1 d+ b2 {
  6.     NXOpen::View* myView = NULL;
    % I0 |7 n0 k$ R5 E  N" P% P* l
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    1 L1 f: ]8 f& g4 f: ?) D

  8. % S1 L  u" w$ C$ y; ~4 ?9 W
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);4 |( @: q$ T0 o: D& ^- y: n6 |
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)/ j; _/ K+ C7 y7 r5 h( q9 w& K# ~
  11.     {0 b/ Z5 l6 s. S7 o% I1 e3 z  O
  12.         // obtain the current default annotation plane where PMIs are placed on( s3 h4 ^3 {2 y. q
  13.         NXOpen::Xform *xform1;
    1 u7 U1 m/ u! C3 N
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    ( [. R  O. ?* [/ i$ m" P4 ]* G4 ^
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();; x/ l- M1 t$ W; M9 E
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    ' H! [! T$ j/ B
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    3 \/ t% `2 d0 g! U

  18. " ^9 @- S; b& Z
  19.         // create the ray 'into the screen' at the selected cursor position
    5 R& |% H4 t# N+ O! k& Y
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    ) p3 @1 Q3 @& v
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);" Z4 U/ I2 q8 O# f1 x, C+ e1 l
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    # Y4 S; n; M3 E5 @3 P) H( ^+ P6 Q
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);/ V$ ?& f- r# R) |
  24.         lineRay->SetName("Ray");0 T! N1 p6 @" ~4 n

  25. + u, e' R  J8 O/ @: w& _& u
  26.         // create the plane from the view to intersect with the ray
    % @3 Q9 ^0 _- t' }
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);; {* j; N2 t% T, N
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; r- |+ g  [# {/ _1 W
  29.         planeView->SetName("ViewPlane");. s, v# ^2 u. P9 H. V% R; Q6 z
  30. 9 p# B1 ^' W) ~/ Q/ s
  31.         // now create the intersection point
    7 B& r# I# u/ H1 `1 i4 p
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);$ n' a* a( |& a0 [* f, e/ K8 H9 h: M
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);( l; W. o/ M& {' x
  34.         pntInterSect->SeTColor(10);
    ( D9 P4 r# x2 t7 ?
  35.         pntInterSect->SetName("Intersection");; j  c; Y- f/ D1 J# E# j, L
  36. " h; ?1 k0 y% t5 ]
  37.         pos = pntInterSect->Coordinates();% @3 n0 V2 M1 M
  38.         print("\nPMI Position:", pos);
    , ^' [; C; C+ O* |/ O

  39. 7 J# h& v# D% P- ~1 E7 u  t) m
  40.         // clean up - comment to see intermediate objects
    % h- C8 k( |, d8 g3 E& f
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");# M' R& H! B( S. @8 b. Y* n1 ?# X
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' D' J* W2 i4 V2 f6 o* P1 J( i" j
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    & n# n. C- l3 ?
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);9 l- o$ C0 e% C% I3 F$ J8 j
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);# Q0 S, o  e- H3 y! x- {
  46.         m_session->DeleteUndoMark(markDel, NULL);
    1 B! o1 \: L  Y3 T+ v% r

  47. 7 u7 V, \8 [7 W) E* `
  48.         return true;9 o9 E! c( E1 M
  49.     }
    6 M9 H9 f* w4 w5 X1 q" ?9 r) t
  50. - L) `1 ?4 H. R6 M
  51.     return false;
    : P/ |5 N3 q& B! x& U3 v, ]
  52. }
复制代码
' ~' L. p/ K5 f- f- h+ a
6 U* @2 a  a3 ?8 I' r
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了