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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
# P' V6 ]; b* d4 j( W6 y

! X( \  u4 h& H3 S如何获取选择点映射到视图空间中?源码分享
2 O' y2 ]" ^2 F4 }! C4 j. A, t4 s
  1. //------------------------------------------------------------------------------
    : j2 z% g: X1 t) A: w
  2. // Select Screen Position and map to Modeling View Plane
    ) x( F" R! S' O$ V& V+ h
  3. //------------------------------------------------------------------------------; R8 x5 O- e. [; }  }( ]
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    0 a1 Q* d% w2 q9 a4 K5 r# r
  5. {# I. D0 D/ Z2 I% |- G) K: Y
  6.     NXOpen::View* myView = NULL;' H3 R$ g: h' [. B8 R7 p- }1 v+ p( ~
  7.     NXOpen::Point3d myCursor(0, 0, 0);: b" x1 d3 K* v/ u
  8. : A0 J/ ^- N* o" d& R
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    ( w* C9 g9 N* _1 w& V& X2 {
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    - K8 ?. ]- `, C& r
  11.     {
    0 o" e! A$ _& l2 _- q
  12.         // obtain the current default annotation plane where PMIs are placed on
    7 ?! x! ^0 t: z% b! e& a: V- w
  13.         NXOpen::Xform *xform1;# k& x" Y) D# O" @2 S
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);6 Q  i* |, h9 O4 h, H
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    1 L  f3 C1 n- m5 b! e. E6 y: Y
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    ) B  n# P8 M% s
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    % v" _9 t4 V8 v/ N) X' Q& [4 F

  18. ! j; F4 f- {" D% X. g
  19.         // create the ray 'into the screen' at the selected cursor position7 u1 }$ v/ ]. w) |
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();4 c* j8 h% i5 z4 P
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    6 Y" n5 E) z% M! W. P
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    2 E0 C, c2 m/ |: a, g
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ) D9 M3 h4 s9 g! O- K9 ?8 _/ f" G
  24.         lineRay->SetName("Ray");) q8 o0 V' a# W% R* U* u+ `
  25. ! A' N4 i3 _% Y8 k
  26.         // create the plane from the view to intersect with the ray0 I, Z( p* n9 D* `8 W/ y; i
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);4 l& N# r. u+ {# L0 e3 E- A5 S% y
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);  N; X6 r/ B2 k! H2 X0 k" ~# r
  29.         planeView->SetName("ViewPlane");- i; v/ w5 w3 i( L

  30. + P4 |7 Y$ x) I' u' u: e
  31.         // now create the intersection point* {! X! e# i1 N! N
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);% D* F1 J) N- A! T5 M
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    3 H( ]" _; y4 ~9 N2 }% P  Y5 x
  34.         pntInterSect->SeTColor(10);
    * Y' t3 F; V$ i& X8 D3 u  T" N% c
  35.         pntInterSect->SetName("Intersection");# L1 c9 \% Y8 T7 u7 P

  36. ! g& @$ [3 S: x/ P
  37.         pos = pntInterSect->Coordinates();
    ) j. f, O6 j1 o* J& [+ J9 W' r' S; l
  38.         print("\nPMI Position:", pos);
    & g* y- ~0 u0 f* r8 n: \+ R+ O
  39. * w) [3 _3 I, w+ v! _' [
  40.         // clean up - comment to see intermediate objects
      F6 x/ B6 z* x# J4 T3 V
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    * Y0 G, q7 H/ d4 j% d4 o3 t
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);9 v  O; g2 m! M( R' V
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);; x, V; U) H1 s5 L3 v
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    ' t6 r( I8 d- Z, z2 Y- F
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    2 S; m! q) O& s/ _
  46.         m_session->DeleteUndoMark(markDel, NULL);
    , P7 M( a6 F3 N9 p5 e2 W+ e

  47. : U& \% S6 J5 e* `+ r* K
  48.         return true;; W6 I, \3 U4 v0 K) X8 G
  49.     }
    ! ~7 r& ^" {4 f, o0 N$ u" l+ V
  50. : Q+ |1 D9 [- h8 u# A1 ^3 _
  51.     return false;, z& Q4 |( u8 i- R0 i$ ?: D6 P( Q/ V
  52. }
复制代码
5 Q9 l* e$ X7 m# b$ o& [

! t5 `  i, [9 B% ~2 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二次开发专题模块培训报名开始啦

    我知道了