PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
( l4 S, i- L' H6 O
  u0 M8 A  }8 k- W6 t" s
如何获取选择点映射到视图空间中?源码分享9 w' }: ^5 L1 ?5 a! R

( Q8 ]" m1 R7 T% X7 q
  1. //------------------------------------------------------------------------------
    ( o3 L# ^7 O# e
  2. // Select Screen Position and map to Modeling View Plane
    9 v1 O' I: d- I' P
  3. //------------------------------------------------------------------------------) l; f" o7 P1 Q" J# y
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    ) s9 v; i% k! [; w5 @! {
  5. {2 P5 w3 ]9 w) l
  6.     NXOpen::View* myView = NULL;5 L/ J* ^& i! B( Y! W
  7.     NXOpen::Point3d myCursor(0, 0, 0);& |! p3 q7 M7 \# X4 I) G! z; s

  8. ! c' H3 l6 i. W1 H
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    1 O! d9 f, }& k: g
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)# j: l$ c# I: Y/ I0 z6 a7 f
  11.     {
    1 s! t5 ~2 t6 H( j5 a/ K5 D0 U
  12.         // obtain the current default annotation plane where PMIs are placed on
    & u$ x9 @3 O& d5 O* F# B" S
  13.         NXOpen::Xform *xform1;
    8 K- I+ D5 `* r% c$ v0 J' \
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);' L& J' q$ D2 O( e; h0 x9 l
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();/ n; _7 s! l+ r( {
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    3 o" K% H; v  h& v5 I( c3 m
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);( a; G4 t+ w6 A& l0 c! g/ J

  18. ' y5 l8 R9 O$ C- n6 Z. i/ i
  19.         // create the ray 'into the screen' at the selected cursor position+ ]! E; h0 B7 }' J
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    3 |0 g0 I9 m; i5 i3 L3 P
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);, x! Z4 k+ s1 j' t( V2 {& \( b
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    1 i" [) q7 S5 g" ~  v
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    $ ?9 o% Y! [% Z# M1 w
  24.         lineRay->SetName("Ray");
    4 u/ G) q0 U$ i6 x0 h$ s- t! n: H
  25. 5 I5 R0 C: Z3 n  x9 S0 K
  26.         // create the plane from the view to intersect with the ray
    4 I" T1 y! O, }( m7 u
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);, X1 @1 {* V1 B: X% Y
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
      f' m  E" l0 t; g6 m& w
  29.         planeView->SetName("ViewPlane");: L' e: R) u5 _/ a9 b

  30. ) a$ F0 |9 @; q7 z: v" z3 N. g
  31.         // now create the intersection point
    & w5 }7 [- |4 r3 [7 t. ~6 _* Q1 ?
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);! Z, }7 V. L8 {2 @9 N
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    # |) n4 Z" q$ U! G9 Q) c" ^( b
  34.         pntInterSect->SeTColor(10);9 [. y& l, o9 Y9 ~4 X
  35.         pntInterSect->SetName("Intersection");
    3 x# y& S5 T' U9 O3 w" {; R

  36. ; K( t$ ?' S: m! k
  37.         pos = pntInterSect->Coordinates();4 C$ w" X0 j5 ]" x- e/ c/ A
  38.         print("\nPMI Position:", pos);8 r% ~2 x( S% ?/ s" p9 [1 i

  39. : z0 k8 |4 V3 X1 ~) ]# f2 [( r
  40.         // clean up - comment to see intermediate objects0 K3 n. X0 x; K( r( q
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");. y1 O! w% o3 d5 c( X& l
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    0 n$ U" Z- b. T! e
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);7 r7 Z7 X& ~0 r9 d: D& ^
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);! {, g: i7 i5 h3 j8 B8 F% V
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    - h# i" z7 c( T  g4 q
  46.         m_session->DeleteUndoMark(markDel, NULL);6 E$ v1 X# e, ~" n4 K

  47. 4 z& v6 j0 W% V0 J, K* D  L
  48.         return true;0 G& W  U7 g( V0 a$ u; o
  49.     }0 h  O- S% a. W- V3 m3 m# H% M! N

  50. 9 ?1 C* k6 b" @6 d  d  h- ^/ B5 E
  51.     return false;. L. E9 Z! P4 G) o0 f; `
  52. }
复制代码
3 P( ~# f  k/ L- T
- j) ~! G* E+ H- k. ?8 Y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了