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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
2 \+ R2 ^4 T$ C7 _$ W7 N

) O5 L( ~  I  x* F7 s如何获取选择点映射到视图空间中?源码分享% [* o( A& i7 m7 Y: k3 s  l

8 J& [# A! H% f7 g, O" m0 f
  1. //------------------------------------------------------------------------------
    " Z- ~9 e1 A9 u/ T
  2. // Select Screen Position and map to Modeling View Plane
    9 k* C4 g" b1 ]8 ?
  3. //------------------------------------------------------------------------------0 c2 B+ o! |( j0 K! Q9 M% H
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    2 L8 f  F5 G$ {, q
  5. {
    5 K. L& S6 d0 {, p
  6.     NXOpen::View* myView = NULL;
    : V- B2 k4 A& M* t
  7.     NXOpen::Point3d myCursor(0, 0, 0);7 ~: D+ \$ X4 d) t

  8. - ]! ^' k4 D2 o; M
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    ) m7 V# l7 T$ t* H
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick). S; T$ N8 W; \9 Z
  11.     {6 x5 }/ T: e% E% L$ A, C
  12.         // obtain the current default annotation plane where PMIs are placed on
    ) x9 ~) E7 }4 v. ?
  13.         NXOpen::Xform *xform1;
    ; S; S& B- o3 ]; h" h, K; O* M
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    . i% I3 N( Y% Q, X$ {; u
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
      `! l4 g; x- h' W( l, y3 J9 H# q, R7 H9 W
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    0 j2 |1 j' n6 Y  L4 C6 \
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);/ n, q5 a8 j4 a9 t( ]: R: P

  18. ; w& v6 M$ W, S
  19.         // create the ray 'into the screen' at the selected cursor position; M6 U4 {# S% I) @# F4 H$ G) G/ b
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    + |; Z8 k# s/ }% p9 s, ?6 p
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    , U8 x  R" o; G; o2 ^: v  z5 g
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);9 ?, J! f* `9 l" o
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);, h+ W0 ?7 t1 p4 d+ d0 x
  24.         lineRay->SetName("Ray");* z: X! {7 p; u& D
  25. + i3 l. Z; O" Y. H% c2 j- g
  26.         // create the plane from the view to intersect with the ray
    1 a% u5 G. z+ T: ?
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    , }* J4 e8 Z" p( t% b
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);0 ]; u2 i. S4 j6 v
  29.         planeView->SetName("ViewPlane");& V/ F& N- F, f8 Y& F! `
  30. " M9 p9 i. L3 O' ?  d; Z1 Y3 h7 D+ |
  31.         // now create the intersection point" y2 P. i  L' v) l/ a! V
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);6 O+ ^- j+ g+ e  q
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);$ W5 e, z7 w9 Z+ }8 K' g8 B1 Z/ }
  34.         pntInterSect->SeTColor(10);
    , _. j/ x1 V7 S  {& r: `
  35.         pntInterSect->SetName("Intersection");
    ; C4 u' |0 x6 B% [
  36. 7 v: i/ ~0 u' M1 Y. ^2 |
  37.         pos = pntInterSect->Coordinates();
    2 [+ E" _# b! b) _, [
  38.         print("\nPMI Position:", pos);' I5 ~: j7 T' |1 [$ u
  39. 2 I* H3 ~* @  _( a& m
  40.         // clean up - comment to see intermediate objects
    # b8 n# t$ r) A# C$ Z/ W  z
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");' r, @/ F1 y. f$ g: R
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);2 {9 }8 T8 i( ^. h* B* _
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);% ^! E3 X( h9 A4 Z
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);; s/ s$ B% ?' c: L' D% c7 L+ T
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);2 B( @" b" l) o* c( W
  46.         m_session->DeleteUndoMark(markDel, NULL);
    ! H1 M6 }# r: }6 o
  47. * q5 |2 e* l' ]# ^
  48.         return true;3 y+ P' f& p" l; b. Y* D5 x
  49.     }" }0 N" p8 D( S( r' m3 \
  50. 5 _% _  t" ~( e% Z: v7 m! T- f
  51.     return false;
    ( |, w* d' c" M( B  b
  52. }
复制代码
/ @7 j4 Y- q; W$ C( A  [

8 C, K; @4 E2 F0 F5 e1 }6 U6 a0 E7 u' p
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了