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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

, A2 d* c' h6 b6 P
! z( q+ x. O8 h如何获取选择点映射到视图空间中?源码分享$ [4 F+ z3 n2 n

; F+ J( x2 p% i) M
  1. //------------------------------------------------------------------------------
    " v' `6 x4 `0 p7 p& d
  2. // Select Screen Position and map to Modeling View Plane
    - q2 x/ w0 h5 T
  3. //------------------------------------------------------------------------------5 ^5 N7 C5 r2 q$ c; V
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)) K7 x! l7 P  S8 n  ~7 P+ {
  5. {* w/ C# U/ @0 Z4 l( z1 m
  6.     NXOpen::View* myView = NULL;6 |- g6 D/ l9 Z' D& K( q' G, B8 I1 T
  7.     NXOpen::Point3d myCursor(0, 0, 0);
      L! L. E# y9 b+ q

  8. + W9 |8 r. K! p
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);2 [& h0 M7 `" J% F" `3 r
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    " L( p7 g& L. _( e8 b8 Q# o
  11.     {
    * ~0 }4 F. {' ]& ?0 ^5 k, |
  12.         // obtain the current default annotation plane where PMIs are placed on6 C) `0 w7 T9 o4 b" E% l. A7 U6 `
  13.         NXOpen::Xform *xform1;
      r+ U4 t! f7 p. O; V
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);# O' a7 p* _- v, |' X: Q8 l
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    ; q6 D6 A  J; U6 A9 e
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    1 |7 E& G0 q0 Q$ s2 s1 h
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    $ ]% g; W3 V- Y$ Z% ^, c+ T
  18. 0 y+ A$ Q8 Z8 K6 f+ b
  19.         // create the ray 'into the screen' at the selected cursor position
    . {# [" r2 z5 |. n/ T
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();4 D: {1 a. p3 e$ r! z+ j
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    9 H9 Q3 Y. C: q
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    : n# d$ _1 ^" a7 j; Q
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ; d+ D5 x3 v5 Y& r+ s- Z
  24.         lineRay->SetName("Ray");3 O2 V' P8 {% e4 N
  25. 3 E' b: K& N( i7 n% o  G+ ^5 R/ J1 t
  26.         // create the plane from the view to intersect with the ray
    " \. Q: Y1 `; _* Z- @/ E  J& l
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);$ {! |' [& V+ K+ ]) t
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    8 C! k& C! l1 Y- T9 h
  29.         planeView->SetName("ViewPlane");6 j3 m% c. j; B. P, a7 J# n5 a! t

  30. 6 k5 B" L+ C# \( _/ ^
  31.         // now create the intersection point/ Q; v/ \2 H3 t
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    : O) q5 X' U' x1 |+ V
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    : `$ R. Y$ K& E# G" R" W
  34.         pntInterSect->SeTColor(10);
    # K3 [2 O, {2 k
  35.         pntInterSect->SetName("Intersection");  y) Z  C$ k1 @, s
  36. $ {/ P* T" G. c. l9 Y5 W
  37.         pos = pntInterSect->Coordinates();
    # f: t2 q4 T: f5 e+ [  u
  38.         print("\nPMI Position:", pos);& Z8 n( N1 r+ t2 T
  39. , I7 [. H& U9 `4 G
  40.         // clean up - comment to see intermediate objects
    7 I& G/ r; o( o+ f; f+ ^
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    , J; v+ l" S/ Q9 u# L0 N
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);# I$ h( |: P1 g  v, B) h
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);- k! I% Y* }+ V1 G2 M( B6 D
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    9 i: w; n) a6 ~9 p, C5 F
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);+ X0 S. Q6 ^' [3 q' p& ~$ ^& }: H
  46.         m_session->DeleteUndoMark(markDel, NULL);
    ( e0 r. a1 N# J% O7 H" {( V' h# b
  47. 5 j  `% u) R* A
  48.         return true;$ W: e0 U3 C/ ]1 b( f+ J
  49.     }6 ]& p) r9 W, e3 v) c" ?
  50. 1 J" M: |" ^# l9 V
  51.     return false;6 Q5 Y8 ^* u% k5 D; z8 w' ?
  52. }
复制代码

6 Q! z% C! ]- T5 [" [, @
# g' g+ L0 D0 C2 C: T2 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二次开发专题模块培训报名开始啦

    我知道了