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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
$ a0 ]( [* r; j  _# h( J

; F" k+ V5 H9 E+ b0 w如何获取选择点映射到视图空间中?源码分享1 f0 [6 `( z; X- a. F- M7 {
5 \& n4 Z, @% \  Q
  1. //------------------------------------------------------------------------------# W  g* _4 V, J" `: C0 i
  2. // Select Screen Position and map to Modeling View Plane" O2 F4 A6 b: ]/ a! F" E
  3. //------------------------------------------------------------------------------
    4 r% K: @6 @, c
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)5 T; z0 d1 Z0 Z$ |8 m
  5. {$ l5 x1 Y. x5 }$ k# b$ r( F
  6.     NXOpen::View* myView = NULL;
    - H! m( W' l) z  }
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    ! X8 A# R+ G4 U5 l" I0 A6 P

  8. 3 d0 e( e  ^/ u* s2 r6 \
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);: G, C8 @+ d: u7 w
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)4 m* D$ z3 A5 U9 x8 Z3 j* ~! q
  11.     {% J7 ?, d  T4 ^1 [
  12.         // obtain the current default annotation plane where PMIs are placed on
    7 d0 ^. Z& Z1 K4 c7 j/ z
  13.         NXOpen::Xform *xform1;
    ) ^9 E# T! F9 P. b
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);: X& G" \6 G8 E/ x1 R/ x4 i
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    & c$ H7 L1 F# g2 L; X! U' J
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    1 F+ e9 R) Z" K1 q( b1 ^/ h: Q
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);7 l4 ]+ m, y1 q/ n4 O& s0 u6 @; B

  18. * s( a2 U3 _3 U$ i9 z
  19.         // create the ray 'into the screen' at the selected cursor position( j. O' Q+ Z3 D5 ]7 O) @: o* m
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();+ C' O$ G/ ^! L8 N; |( F& {4 u3 `
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);! N: c" K  n: ^; I
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    1 g4 Q% F9 r/ G/ X. m* q" [
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);$ g9 O; S: c* w1 \  R& f- X
  24.         lineRay->SetName("Ray");
    - R$ H& O! k5 k1 z3 g! n
  25. 8 s+ c; N9 A$ ~. h7 @
  26.         // create the plane from the view to intersect with the ray* a! @$ q* v$ M, J; U
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);+ n- q7 P0 m9 I# I3 d" e
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);  O5 [$ `( I, e! \# g) b; B1 G3 @3 t
  29.         planeView->SetName("ViewPlane");
    2 G  z1 o- |# S- K% X1 }

  30. 8 y9 L4 t3 F# G( q+ A0 T' |
  31.         // now create the intersection point
    & Q  U4 B) v" p; Y4 w3 o2 S
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    1 j' g2 r! Y9 [( F+ w( K, N' |$ x
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);7 d3 S0 D+ N. \1 B
  34.         pntInterSect->SeTColor(10);: D( J- z# e9 d7 s; R
  35.         pntInterSect->SetName("Intersection");
    + Z$ y0 N6 b7 Q5 @2 l( t! s

  36. 6 P% _$ d3 q! r, V7 J6 {
  37.         pos = pntInterSect->Coordinates();
    ( M- j) E2 v5 h% Z9 {$ p$ h3 J* Q
  38.         print("\nPMI Position:", pos);
    ; O. A- n' d4 t" _$ \+ j

  39. . Z( o# P8 H- ^% L# i* _
  40.         // clean up - comment to see intermediate objects
    4 P  u9 u$ G$ j  K% `* z
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");! O& [  S( [3 @7 s0 v3 e
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);4 _1 y% N0 W$ j! N1 b. Y0 t
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    # |# a  p  ]9 G2 A
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);3 V* K  F  t4 h2 R2 @6 i
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    % b2 p2 {$ Y0 A
  46.         m_session->DeleteUndoMark(markDel, NULL);
    6 W& ~5 B6 v8 q- X) @0 {  f
  47. % T( U1 C6 J7 i. [, `. H, s
  48.         return true;/ H6 g! U7 O7 t3 J+ {. e' p  T
  49.     }
    " j. ?3 V' @) s( w& [3 E

  50. 0 p1 x! N0 ?: F% m- k& p
  51.     return false;
    # Y5 A. ?# v9 @
  52. }
复制代码

' N4 f( Y2 |+ ~* c. [) I$ z
4 c# l( v9 M/ d; h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了