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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
0 ?  L- w$ U1 W& Q  k4 w
. c) `5 K7 g( q4 Q9 Y4 E2 E: f
如何获取选择点映射到视图空间中?源码分享) o+ U5 m* I3 f* G! L/ q
) _' S% J- Z% b& U
  1. //------------------------------------------------------------------------------) l) Z  d- |8 M% R- ]; f
  2. // Select Screen Position and map to Modeling View Plane
    " v" W8 m( |/ t& n
  3. //------------------------------------------------------------------------------) n2 H8 y' {5 u5 _( E. p( P
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)0 `6 o; `( U- r$ J* c
  5. {
    ! s) Q% |5 ]$ e8 L' p8 W  \
  6.     NXOpen::View* myView = NULL;
    0 |1 p# E% u5 Y2 Q  d0 I/ [8 K
  7.     NXOpen::Point3d myCursor(0, 0, 0);& r/ i) V9 V$ g

  8. 5 v! g- x, d2 Y  ^; l5 V+ w: I
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    6 W; B$ n  _5 F9 W9 v
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    . e0 N% v  O$ g% @) j: u2 r
  11.     {
    7 k$ S+ s0 ?- a3 A" o' m2 v
  12.         // obtain the current default annotation plane where PMIs are placed on& P7 N8 l5 p% c8 e+ R. B
  13.         NXOpen::Xform *xform1;1 q! [( w2 o% ?& z
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);: M1 {% q& k9 b' u8 V
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    7 G5 d6 p4 n6 _$ m
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    % s& l- ]5 ]% Y2 D2 z$ G& j% x: }
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);' a; B0 k: _7 `( w# P8 I0 C# ^3 x* l, l

  18. " c. Q/ v) J+ o$ P/ T
  19.         // create the ray 'into the screen' at the selected cursor position
    0 ?* E6 g4 j/ v
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();: E( d- ~" p4 c8 f' H0 I7 {
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);3 d6 h& c% C+ B& d
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);9 U% \; X, l4 B/ v$ M" S
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    / J) Z4 a! `, X/ I" q+ |
  24.         lineRay->SetName("Ray");
    - E% Q' |7 v3 o1 T! b$ z

  25. : Y1 J9 u/ I9 I  q0 Q6 ^  ^
  26.         // create the plane from the view to intersect with the ray
    0 D( S8 t$ R% T! X; l6 T
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);( T- P9 _! n8 X( A
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);/ t/ x7 s/ |5 \9 ?8 h+ ~! X
  29.         planeView->SetName("ViewPlane");
    ) C1 I, O- L: G* M: F

  30. 5 ^3 |0 C# L5 D- x. `  L9 P  B, m
  31.         // now create the intersection point
    8 Y4 ~9 T) O/ x' X: V! I
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);0 f0 d: ?. l* l
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);4 |7 K1 i4 P3 U' S
  34.         pntInterSect->SeTColor(10);
    / }5 ?/ |# F/ V8 r' J) k. l
  35.         pntInterSect->SetName("Intersection");$ m" M$ I# \- c: s9 r+ p9 n

  36. ) l7 u, M8 S3 t  q2 @8 T9 d
  37.         pos = pntInterSect->Coordinates();+ r' ^# {- t% M2 Q+ [1 X3 _- v* a
  38.         print("\nPMI Position:", pos);( p1 H+ T; C2 s4 N# ?3 ]
  39. 6 t, }( @. l# s5 X2 a
  40.         // clean up - comment to see intermediate objects
    ; B7 X5 g8 K5 s: |3 H4 d, e) E
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    6 p3 y) x9 I$ P6 J8 @
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);- ^5 G" ~5 H) W7 H: \' [
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);& D- X1 P" r3 _: [
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    ' F7 W* J9 v! i: a4 M. m
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);( e1 y+ f- z3 J$ ]
  46.         m_session->DeleteUndoMark(markDel, NULL);
    ; U3 L% X2 X- x6 B2 I( N% s9 F; d

  47. 3 |2 l  B4 M& e* S
  48.         return true;2 D: s1 |+ x2 F
  49.     }$ I! y; z% u4 @+ q" y

  50. 3 }; S. J6 B0 j. h  q
  51.     return false;' L7 b' J% t8 X. f  [0 ]' ~# i. g0 {
  52. }
复制代码

+ z3 _7 R& C9 V7 t- X
4 M! _+ w; ~: x0 v4 J2 h$ t' _
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了