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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
7 w8 ?& o) y4 G& R
4 f7 v' e% O; \( s, N- T
如何获取选择点映射到视图空间中?源码分享2 V# E2 R/ c2 e

, s& U0 g: k1 X+ `" v- i; Z/ T
  1. //------------------------------------------------------------------------------2 ?. E: e$ w6 d, M6 A
  2. // Select Screen Position and map to Modeling View Plane
    % V/ t; e% f6 _, K
  3. //------------------------------------------------------------------------------1 {0 k4 F5 @" n) L( n
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)' o4 I. e8 q" x% W. Q! z' ?+ L
  5. {$ @: a' G% g5 v9 T" T, o
  6.     NXOpen::View* myView = NULL;- B* l" x$ B4 N& q
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    $ \7 _0 C- u, s3 k

  8. % l7 D$ e" R- B- m
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);- K5 o: X. w. n1 w! M
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)& d/ H) b* K# V7 C$ {- l
  11.     {8 \$ {+ J) l5 [8 j8 B* a" h
  12.         // obtain the current default annotation plane where PMIs are placed on! {; z. w$ Q* a* e' Q
  13.         NXOpen::Xform *xform1;
    # W- G/ H  ]2 ^
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    7 I( J- U6 ?8 g+ }( m
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    - v. F3 o9 G2 I; O
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();7 }- w+ D* Z2 F/ ^
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    + }- u' k+ ?4 H2 ?  W$ L

  18. & r5 f) y. g+ `
  19.         // create the ray 'into the screen' at the selected cursor position4 u' d4 D( o* Y1 ]
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();" C7 B0 C+ L* G
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);( l& [( p4 j+ n+ ~- p0 M6 f8 H
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);. S& v+ |( z9 \; S3 L& d
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    . o* [# X7 I3 i9 U6 X
  24.         lineRay->SetName("Ray");
    ; ?/ V' K7 [' E3 `; M8 d& Q( b
  25. ; N: P7 a0 X  F1 O$ H' p
  26.         // create the plane from the view to intersect with the ray
    ) X4 C7 u/ e- d, W* m3 ]- h
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    . X# ]  Q$ A% C: H# M' n0 w  Z; |& i6 L
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);. o/ e& J  y! c1 f6 M% G2 L
  29.         planeView->SetName("ViewPlane");
    6 T3 @5 Y6 t) o5 m2 ~
  30. 2 u4 B* B; [, a* e5 F: D- F; O! U
  31.         // now create the intersection point% [) \' K1 p* S* y+ O7 Z5 v7 z- p
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);# i" d% t( F; G" M" O+ I
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 N# w. _+ I0 `+ O
  34.         pntInterSect->SeTColor(10);# Z3 ?2 I  ?4 h, o5 i/ q% ]
  35.         pntInterSect->SetName("Intersection");0 `3 [9 s5 j( S" G- ~

  36. ( t" I1 l, r9 u* Q- c
  37.         pos = pntInterSect->Coordinates();
    5 R0 L+ H& J8 ]4 g
  38.         print("\nPMI Position:", pos);
    3 U4 K4 w2 S* l' I  R7 Z3 J. q

  39. ! _8 c( x. y. b3 G  Y. }/ O) Y
  40.         // clean up - comment to see intermediate objects- _5 C2 ?/ s4 l8 D, h
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");+ R  B& c5 E8 O. p. U7 Y
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    $ v- q/ n8 }+ o" J. W# o& R8 E" A' _
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    6 D$ S5 \+ U  D( A$ r+ w; d
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    + I2 _! y, G, {# h
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    & w1 ~' C7 A4 Y$ k, d( q
  46.         m_session->DeleteUndoMark(markDel, NULL);
    2 O* [# k/ G% ~# s+ G5 }
  47. # @: o1 v& I+ ~1 N7 s1 ^- Y: ?
  48.         return true;
      z0 Z* n' u% h4 s4 z" B" y( a8 D6 L
  49.     }& v& w# l1 m( `8 S5 R
  50. 9 {% l1 ?5 g$ v8 C, X
  51.     return false;
    6 t2 V! K' W: a) e
  52. }
复制代码

# f, i8 @+ t' H+ Z% ^( O% R- W$ j5 h7 n0 M  t  ?2 H9 ?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了