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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
2 P$ h  Y1 d# R( x1 j7 n
+ \2 G3 W, A6 @4 k' @
如何获取选择点映射到视图空间中?源码分享
% Z; E$ {: @* v* ], U9 a  B8 Q. Y5 f& H% _  I; D' }, S
  1. //------------------------------------------------------------------------------
    ' r4 a4 n8 z9 m* T3 b  h5 ^# C
  2. // Select Screen Position and map to Modeling View Plane& U& S- i4 N4 K. V* G+ Z6 l
  3. //------------------------------------------------------------------------------
    ! Z. R- I3 B3 O: B( g
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    : ^$ O. s0 L0 n( I1 }
  5. {
      \2 S9 M8 v/ F& \: W
  6.     NXOpen::View* myView = NULL;
    ( e4 l7 \' A$ h# D  ?
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    3 _8 o/ l6 E, a! |( V/ X
  8. + m+ W5 A) a1 C5 F2 A( Z8 E! q0 N. N
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);& M2 R6 v( r8 Z
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick), v5 s. B% q" e. ^& ^/ ~2 r* I" ]( v
  11.     {9 _  W; q: l: p- p! m
  12.         // obtain the current default annotation plane where PMIs are placed on
    ( g6 _" L, }3 }+ j
  13.         NXOpen::Xform *xform1;4 z7 u, Y2 n7 Q5 z/ ]) }
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);  |2 b9 ?" m( m, n# L. t
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    # R. m! X0 O/ o: b! H$ w* s
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();2 ?9 e6 ]1 g2 {1 d6 s
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    " q7 |$ |/ y/ ?! Q' \0 z7 |0 R" }

  18. ( S6 H) r, J5 F3 i, e
  19.         // create the ray 'into the screen' at the selected cursor position
    & e: E1 j: m( R* u6 B4 L
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    7 u8 M5 N- L9 ?1 ^
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);  R, x4 h, j& S, Z2 J
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    # r+ p9 T+ C( l9 E
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);# G0 Z# v  I" q3 V. w
  24.         lineRay->SetName("Ray");7 Q3 c6 y6 m3 v+ c

  25. + W8 ]' p" n8 P
  26.         // create the plane from the view to intersect with the ray
      p2 r! e+ D; A& @! W  o% J& v
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
      y8 s; I0 P' R& Q- l$ I" q/ {+ K; Y
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ! X) K+ P& z/ J) T) K2 N+ c
  29.         planeView->SetName("ViewPlane");
    # f- N) x' u$ d0 v+ C5 A' e* x
  30. 2 ^9 ?# U, Z4 ]) |; w
  31.         // now create the intersection point
    ' k7 q; w0 X3 Y7 l/ q
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);/ }0 ]2 B' q# S3 w* l9 M+ @8 R' Z
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);1 h5 |; v- F2 O! o) k3 s4 l
  34.         pntInterSect->SeTColor(10);
      R& F8 f+ L7 V4 F% [; A$ J
  35.         pntInterSect->SetName("Intersection");
    , P# e: \$ H5 F: q
  36. 7 m! X- C2 B3 ?8 i; g
  37.         pos = pntInterSect->Coordinates();
    ) ?) d  ~" U# X( ~! E
  38.         print("\nPMI Position:", pos);* P& e) F6 l' ?0 e, ]* N' \9 i7 R. d

  39. # x* j; C3 ]. Y  I5 h# ?( B
  40.         // clean up - comment to see intermediate objects. q# Y( P: R2 J+ A2 L: R& h
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");2 Y* `; I" w- `* \2 O
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    + u  Z# i5 A: h" E" ^
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    5 `6 v# T8 z" V- w, _& W
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    " B2 n) o$ U/ G7 G
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    ! A6 M! m# w+ P( y, C
  46.         m_session->DeleteUndoMark(markDel, NULL);! Y7 P1 c  }; A

  47. " ^  T, o0 ?) a! D7 N
  48.         return true;0 S9 c3 o. X: }; J3 o
  49.     }
    ) p, k' t! H" W- {- ^7 P
  50. 0 Y3 j1 Z% r* h: {& N/ r! N8 l
  51.     return false;
      }( S! k' o) x) f& j) V+ M$ ]
  52. }
复制代码
5 E) g1 U7 Z0 Z. p+ w& {
2 w+ s  k" Z8 ]: l4 d
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了