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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
$ w- z- T$ X2 E  U  D7 h

5 B9 x' d! n% [如何获取选择点映射到视图空间中?源码分享2 H' i* p; ?3 |# ~3 H
! |4 u5 s, p. J( h6 y4 Z4 I/ b" U3 D9 Z
  1. //------------------------------------------------------------------------------
    - R5 Z4 ?3 Q: R6 o1 d: E
  2. // Select Screen Position and map to Modeling View Plane1 Y, ^( S7 Q2 [5 h& Z
  3. //------------------------------------------------------------------------------
    % r4 h/ Z0 j, ?) B; c# ^
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    6 s1 w" {" y5 n/ ^
  5. {- ^% v8 ]  M7 J1 [
  6.     NXOpen::View* myView = NULL;: B1 ]9 r+ p/ i6 U$ F$ U6 R
  7.     NXOpen::Point3d myCursor(0, 0, 0);: ~6 x. U7 |: F3 M+ e

  8. # g( L( u; e/ k/ |2 ?6 G$ r, _2 G( B
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    / ?% w* r' I, w
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)' w) M6 I! C# A$ M/ ^; N, k. y
  11.     {
    ; l* {2 r9 a% J" t# r; P0 L
  12.         // obtain the current default annotation plane where PMIs are placed on
    + I! v6 @% m3 f1 E/ t
  13.         NXOpen::Xform *xform1;1 `0 `! ~" M0 s$ ~- |% l* a1 \
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);( _* k, [" n; l8 T4 Z
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();9 r" O5 q- g" ]- A) {( F
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();% K5 t6 n( @2 `+ n; w* e$ t+ ?+ a0 T
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    0 w2 N1 {- S' L+ ]

  18. 5 K& c* I( X3 O5 j( f- I9 \
  19.         // create the ray 'into the screen' at the selected cursor position
      `- x+ j/ U6 {# w4 [
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();. W% @' k1 T; H0 ^8 f* c
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    ) i4 j9 x) M# g: J/ C, D
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    7 L: y9 D4 F" a  s3 t; l+ y
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    & w; R, l/ g1 d8 k4 l  _
  24.         lineRay->SetName("Ray");- i2 N6 v) v6 ^4 q8 R( [2 N
  25. - X% Y8 K. w8 M0 j+ K3 S; u. T
  26.         // create the plane from the view to intersect with the ray; N3 \- Y: X8 L9 v% V
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    / e4 R$ o  B  V8 g! _
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    8 J# h; t& w1 `6 p# l5 p
  29.         planeView->SetName("ViewPlane");1 Q7 f. g  W$ j2 \: W
  30. # }6 K% b) o3 |! t$ |  R: {" Z
  31.         // now create the intersection point
    8 }3 I' y: p4 v/ Z, q* b0 R
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    / E  }( D! G/ n$ h
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);2 O6 Q4 {& G- p4 r/ i4 h
  34.         pntInterSect->SeTColor(10);
    4 F4 P- [1 G4 y1 W+ ~1 x
  35.         pntInterSect->SetName("Intersection");0 ?/ I$ A) }+ @* D" N' _
  36. - U- j) P9 y. A1 o  u: l
  37.         pos = pntInterSect->Coordinates();
    ' [$ D5 d: p6 ?* k( |- v
  38.         print("\nPMI Position:", pos);9 z. M4 n: W9 c, m. g/ k- S& g

  39. # Y; h* n8 f3 r7 M7 {0 w5 I; ?
  40.         // clean up - comment to see intermediate objects5 F+ Z" M4 K0 i4 e! p: }0 l, G
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    2 Y( K) Y. U3 _& Z6 B% p. C  x" n3 K
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    8 c2 H" |+ ]$ `' n  Z- L- ~
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    ; |% ~& m" k6 t/ }4 T( j6 E
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    6 B0 [; K& ?* F0 }9 }2 ^
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);2 q- y- f% p, A
  46.         m_session->DeleteUndoMark(markDel, NULL);
    % \1 Q6 I" j: G" V
  47. * L9 Q% `! {4 S/ m3 u8 d
  48.         return true;; t2 B! F' K- w9 y) @' o& ~
  49.     }3 _2 U: k# l: ^2 i! C
  50. & B$ X2 t+ b+ }1 v8 u# S
  51.     return false;
    # [* f% B/ i9 w" ~
  52. }
复制代码
5 p" Q4 d  I1 P- g; Q

; x& J6 _9 ]- T+ p2 O
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了