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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
6 S+ z3 r+ B' n& F% q
  }5 G2 P& Q0 B- G
如何获取选择点映射到视图空间中?源码分享  ]+ x/ s0 a3 h
+ n# F7 h1 @: b: d8 O
  1. //------------------------------------------------------------------------------
    ( A* f) d6 A1 m, k
  2. // Select Screen Position and map to Modeling View Plane2 C' M$ s: Q- s
  3. //------------------------------------------------------------------------------
    ! j; s0 @+ T, P2 V( z, j7 N8 S& a
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos): B5 _, J2 p6 J- j5 P
  5. {/ G! e3 _0 F' Z9 j
  6.     NXOpen::View* myView = NULL;
    ( a( K; y- \! N; N$ t: h, K5 q
  7.     NXOpen::Point3d myCursor(0, 0, 0);
      ~7 @* Y: g( Z, h
  8.   V; G. c8 }. o4 C: `
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);; J/ i) c% w; x" R6 i. X% }
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)4 ]" l/ U0 C/ g2 F" h( d- k
  11.     {
    2 h8 |# R+ I. k& b% C, Y
  12.         // obtain the current default annotation plane where PMIs are placed on& m6 i& `8 r  |  ?$ J0 Z
  13.         NXOpen::Xform *xform1;
    6 J) i: e# B. X( E
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    ) R! S; k7 O2 _" F5 _5 j( o* z8 x- N
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();/ @6 S6 V+ _! v) T6 T7 v
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();# E0 Q/ H# A' s# V( T  j
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    3 @" |% f2 J' W( d- A% r( v
  18. : |4 ]9 g% s( o0 N- _" n" s
  19.         // create the ray 'into the screen' at the selected cursor position& U* z7 y8 S, u; K$ _
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    2 e, G7 h+ _2 U' x( N4 F) C
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    7 ?, j! d: |  q% j$ }
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    3 ?- U" r" i# ~1 H, G# O
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);) }# T/ T8 a+ q1 C; P8 w
  24.         lineRay->SetName("Ray");
    & O$ Q9 I( b& h- ?

  25. % g: Q: J8 o0 N  j0 K. I! a2 Z+ ~2 ~
  26.         // create the plane from the view to intersect with the ray8 x; v+ ^! G) R+ r
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);& k' ~( I+ y% C; c. l3 T$ @$ O2 Z
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    " j" R9 y/ d( c  e6 }! s
  29.         planeView->SetName("ViewPlane");
      |3 y0 {. i0 N' U  p

  30. 5 K5 U& P- t: e" E# e& F
  31.         // now create the intersection point# I% H$ g. J" z
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    4 s: N; F& g7 e2 H
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    / j) k( ~. A* k8 u7 R, C
  34.         pntInterSect->SeTColor(10);
    ) q) ^9 Z4 _3 R1 h! K3 h
  35.         pntInterSect->SetName("Intersection");
    8 a: E9 `5 r8 o$ s1 _/ A5 d1 X
  36. 7 e, S: r% O3 E
  37.         pos = pntInterSect->Coordinates();
    ; F* G3 w. D5 q3 o# J' _/ O
  38.         print("\nPMI Position:", pos);6 v5 ^( C3 C' [
  39. , U3 P( f- V. p% T( j
  40.         // clean up - comment to see intermediate objects6 @, Q1 v" e, N% t( q' U2 s! V8 R/ a
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    , U$ \9 y0 o; J' E
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
      N5 R/ g, U% E8 u0 D9 K
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    # ]0 r. n( m& S3 T+ Z* x
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    ; R* D& ?6 k7 W! W! u" u  c2 l5 c
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    ' d2 N+ X) B& A; b9 H1 Y4 z9 v9 n
  46.         m_session->DeleteUndoMark(markDel, NULL);  d/ F5 e- z& u$ Y% y9 J
  47. - i# @/ Y$ o% E6 C. F3 V. P, N
  48.         return true;% t& B7 e) y4 c- l; u
  49.     }
    ; D% M( M8 `6 |8 ~8 V6 y8 {
  50. + P: [/ j9 ^8 F' u+ p# d; k: w
  51.     return false;- H9 j, g* [. Q+ v+ @
  52. }
复制代码
* e) r9 y0 D* b1 Y, g

. |2 b5 N5 U2 C( x# @- P7 b
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了