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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

9 O3 E* W- J* F8 U7 P; v. \6 J2 Q/ z/ a6 |
如何获取选择点映射到视图空间中?源码分享( R, T# i1 [/ G! b! [& o

& D, q. R+ U. A# j2 c, m
  1. //------------------------------------------------------------------------------
    ' I1 j7 }" c( c9 O1 G$ G
  2. // Select Screen Position and map to Modeling View Plane' r  \6 l: e1 C0 Y% o8 N
  3. //------------------------------------------------------------------------------
    + ?* r5 V; L& W( N# J$ c- R
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    0 o2 }; B, x1 _% Z" m- F
  5. {
    3 s' c" ]% [3 g) Q  u0 n
  6.     NXOpen::View* myView = NULL;- S( q. ?+ f2 P
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    & z; E3 J1 W  R1 H+ O* t

  8. 9 u0 Q0 x( T0 y" n  I6 J7 P! t
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);5 i$ v. o1 R/ {& e* W
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    . i( f6 d* V' V* K3 X9 _1 c
  11.     {" W& e; w6 f2 O: w; p3 q: U
  12.         // obtain the current default annotation plane where PMIs are placed on
    # i" v! H3 A9 b9 W7 ?
  13.         NXOpen::Xform *xform1;9 `0 A! f& e$ X. F, F
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    * v+ ^: U; h+ E4 z0 l- M
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();+ _9 y- @. `: w5 z0 ^7 c2 ^& u4 o- [
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();& R9 v- c0 C' f' a& k& q& F! n
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 s! |; E: z2 V+ H* I7 u

  18. " t1 ?* ?( q9 U. |
  19.         // create the ray 'into the screen' at the selected cursor position
    + z; a5 h& Z+ d# K; Z
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    9 S+ i" I7 C' h/ j6 D! |0 y- x
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);3 J5 G  [6 ^& l! L, p. K( K
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    / l- Y& n. \6 z4 s/ P: c
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ( `8 p4 T% V# }2 ~% U$ y: ?8 h
  24.         lineRay->SetName("Ray");
    ) Q0 ^- Z+ d4 i0 ?- Q3 I

  25.   o' u9 x& @" P% x
  26.         // create the plane from the view to intersect with the ray/ y, U( j" S* v  ?  t( N! h" o
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    1 L- c4 C( o" Q
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);- S0 r& @7 r7 o  N
  29.         planeView->SetName("ViewPlane");
    ; b6 m8 M) e1 L; j% ]9 X2 H0 ?
  30. $ f; s+ C7 a8 u3 K  R
  31.         // now create the intersection point
    2 O7 c5 E- q' s1 ~
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 d& K1 o& B: W3 Q! ]+ ]5 D& w" Z
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);3 J" ^9 c- u2 W' T
  34.         pntInterSect->SeTColor(10);
    5 f# Q) X" `. W8 ^
  35.         pntInterSect->SetName("Intersection");' ]; r  R9 {/ l2 H
  36. * e1 H2 N5 O! A" j! {' I% a/ z( z
  37.         pos = pntInterSect->Coordinates();0 J' i/ J4 N: N
  38.         print("\nPMI Position:", pos);
    7 H/ O. m9 n! y! `; I
  39. 2 u5 l3 \( Z/ u5 G$ ~
  40.         // clean up - comment to see intermediate objects% f+ K) Z" y- i4 E5 c( ^1 F# R$ P  N
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");  }. L% T: M- f6 k; m( _* `. C
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);& G( f$ B  [* l; {5 w+ e& [) M8 k; ^  k
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    / f! U$ N, _+ G1 J
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    9 o; M9 T% y; }8 z: _, r; B# k9 a
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    1 q( h6 n: n# b( p6 X, x- \9 b
  46.         m_session->DeleteUndoMark(markDel, NULL);% n+ I2 v; Y, p. j4 U4 K* x
  47. $ I2 o. i4 e& q; i9 F. h6 D
  48.         return true;  h( B) Z9 Y" C3 S/ |
  49.     }! H* o4 g8 F1 @% a
  50. # t- f, H* T' d) D+ q4 g6 [
  51.     return false;9 l8 p! S9 K6 U& O
  52. }
复制代码

) Y: C% _! N% _, Y$ K
1 A$ S8 l( ?) i+ ~- b5 [
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了