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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
) {+ L- k3 ?3 w% \; W3 d& n& [0 @
2 t2 Y8 D5 [9 l
如何获取选择点映射到视图空间中?源码分享9 a7 R4 r  d: z- _3 ^! _

7 Z7 Y6 A' ?: q# V
  1. //------------------------------------------------------------------------------% |& \& n8 k0 N: @
  2. // Select Screen Position and map to Modeling View Plane
    4 ^* C& {/ f, B/ L1 Y
  3. //------------------------------------------------------------------------------" U7 U# d) W* N9 @( W4 P
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)8 k$ i1 [' G2 a
  5. {. p; B: `% I' W+ `! `$ n  ?
  6.     NXOpen::View* myView = NULL;  }# O4 G, C0 Y) N; ]2 e! k
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    3 G/ S# C- ^. V( S$ y

  8. ) m1 r. L' B! T1 M
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    0 i& k( y1 D: [0 e
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick); Z+ k) |9 `' ~5 j. g
  11.     {
    : k# N' ]/ E7 i/ ^9 o
  12.         // obtain the current default annotation plane where PMIs are placed on" h' p( [! I+ p7 Z% R
  13.         NXOpen::Xform *xform1;0 x: k+ {, {+ [" X% [3 e
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);9 g, l  l/ o& S* O4 u* O
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();" b" D9 a# m% k" \2 \. N
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();7 u' i  h& \+ D1 Z
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    * r* c% Q" Q; _" t, C5 O

  18.   m3 I& D( u/ Q1 K0 K3 F% |7 x4 q& B# r
  19.         // create the ray 'into the screen' at the selected cursor position
    8 H8 f3 Q, @& y
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    , n8 Q+ H% b' e: ?- E
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);, l6 g+ Y# s' e( B3 a
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);% k) U4 U; V8 M: W7 I2 ~: |
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    4 A1 C; X; ?& U9 B4 |4 x' o
  24.         lineRay->SetName("Ray");
    ' Y/ t$ o  O$ I7 I3 J, h) v

  25. 9 d2 J# C& H! Y9 z$ H- I( N
  26.         // create the plane from the view to intersect with the ray  Q- q! T3 P/ K" V6 y
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);$ {' ]# ~& ?* Y9 V& p! s
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    & V7 z1 \4 T7 h! g
  29.         planeView->SetName("ViewPlane");( x5 {0 e, |* C

  30.   w" m, k/ [: g/ k: F: A! ~) n
  31.         // now create the intersection point
    ! J+ Z7 A: B. {2 _
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);1 H1 m/ |- w7 e6 t- [7 Y5 d
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);  b  }9 `; T3 S1 q, U8 y- `
  34.         pntInterSect->SeTColor(10);0 e# H- V3 [/ H; e2 m' ?' Z
  35.         pntInterSect->SetName("Intersection");5 V4 M% x% E9 Q8 w; C
  36. ; r; r1 G' {& T1 F( U
  37.         pos = pntInterSect->Coordinates();& |7 a( a& S2 ]* ], |
  38.         print("\nPMI Position:", pos);8 k9 n3 V2 \, _5 r( \: |% D, l
  39. ! d6 D+ K: m; `- d1 [' |/ H
  40.         // clean up - comment to see intermediate objects. H+ p9 o% q& L1 J: t( K$ s2 {5 U
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    % M& K$ Y% M) ^8 S; b4 X
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);) V; b/ }6 S6 ^8 s3 D
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);8 R" A$ w$ s% o; d% m4 U/ e( _
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    # Q2 }, j& F4 O
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    # z( q. P9 L7 n/ E: v
  46.         m_session->DeleteUndoMark(markDel, NULL);' z, F  B' s! H) S

  47. 0 Q6 t2 d3 {  K6 O6 H& v4 n  _
  48.         return true;
    + F' _7 K# g1 T5 s3 q
  49.     }5 J3 r% n% J% n  P( P. w. X, }

  50. # y9 p9 C( v# m# A( `9 j! J8 \
  51.     return false;7 V/ _, d/ w! k1 a+ x/ W
  52. }
复制代码
5 |( L' g- Z6 d5 z
1 P$ W! _4 Q8 H" c0 i$ g
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了