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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
: P# a( ?# U2 Y! g  u7 |9 J2 H

6 q% q3 Y7 r& j5 {, D如何获取选择点映射到视图空间中?源码分享3 P+ ^9 k7 g" ]# Q
; q# ^1 [. z6 m
  1. //------------------------------------------------------------------------------
    3 V: l6 F& Y  K) x
  2. // Select Screen Position and map to Modeling View Plane2 A: o) r/ A) \' F6 J+ ?
  3. //------------------------------------------------------------------------------
    + l% d- {/ ]$ L* K* {  n7 ^( M
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)% U5 h! U8 ^3 Z, V
  5. {: a  L$ {/ Z% |% `: ?, V" W
  6.     NXOpen::View* myView = NULL;( K0 j+ Z! H- n, p# H5 @3 B$ T
  7.     NXOpen::Point3d myCursor(0, 0, 0);/ d1 l) k# H. s$ q* z
  8. # i- o9 Q) y" _" Z) h
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    % i$ Z- k. ~: a1 p, q
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)- R3 q  b5 [- t$ v$ c! I
  11.     {
    ) Q9 Z+ M! L1 Z* T. B
  12.         // obtain the current default annotation plane where PMIs are placed on5 v8 M1 P. Y- |
  13.         NXOpen::Xform *xform1;
    ( Z/ q3 \/ ^) d( _$ R" u
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);1 [* A( ^1 e9 a9 }0 }! O- K2 n4 p6 j
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    / u. R+ z" ~1 H8 y0 p, Q
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();' @- H2 v6 Z  {' j* j' w. d
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);1 P" c$ U- q$ G1 s# {
  18. ' d! g/ M$ B- f% v
  19.         // create the ray 'into the screen' at the selected cursor position. t) J4 o$ Y# T' h$ B+ {
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();  l3 d, V, ~0 e* S2 t4 N; e/ p8 t% l7 q
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    . E7 ]& J: A9 N( i
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);+ ^- c5 g0 Q; X$ [2 ^: w8 f
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ) r4 U" h* R, c( A  N, |
  24.         lineRay->SetName("Ray");6 h8 Z+ G' t$ i& e, W5 R% p5 B# a

  25. ( U& O' I$ }8 c) ?7 e
  26.         // create the plane from the view to intersect with the ray. ~# D" k$ O! L: T8 W: V
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    * {3 _* o+ T5 S
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* H' ~3 {* E+ M$ q0 ^" i
  29.         planeView->SetName("ViewPlane");
    ( w7 H& q, ~$ D2 J$ O4 `9 L3 [

  30. 8 N( g2 ^% I% E, H4 n2 F: J
  31.         // now create the intersection point
    * b) @' m: g+ S  N' V. X
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);" e' c( Y/ C: b% [, @4 O
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);+ ?) e; |- m5 h$ Y' X, K8 w; Y
  34.         pntInterSect->SeTColor(10);: a$ `, k& a3 A% }8 L* s
  35.         pntInterSect->SetName("Intersection");
    ' }. ]* S/ Y5 }) \3 I

  36. " X, o; w* x, L% V* D
  37.         pos = pntInterSect->Coordinates();2 T' J$ O0 c/ F$ d! P9 C& Z
  38.         print("\nPMI Position:", pos);5 b% f( i, _# v7 |$ \
  39. 1 j, y9 {) Z% e( m0 [7 p
  40.         // clean up - comment to see intermediate objects( r# `" N& B- t: |  K
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    3 \  B# e; l; ]# ?
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    / l8 M- L9 d$ w7 y
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
      L# x3 o1 i2 H' K+ o; @
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    7 S' |7 K; B" ?! E4 E! |1 p
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);& F2 K3 J+ p: K- g4 G1 u" j, u
  46.         m_session->DeleteUndoMark(markDel, NULL);
    " {8 e" n# C# A( i7 u4 n* ]: O' b9 @
  47. # l+ f1 u( h' C4 N: j9 [% A/ R
  48.         return true;
    4 G  _7 d& c6 u( ?- ~5 o
  49.     }
    ) U# n- _+ u+ L, l! h3 [% d
  50. & w- ^. ?2 d% f0 g  ~1 X  e0 f
  51.     return false;$ n! I' K# L) @( q2 D. D, l
  52. }
复制代码

/ H. u* B, `5 M
* J7 t4 ?1 c1 ]: N8 k
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了