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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

3 x' F* |2 J3 h+ k8 l. {# p- E( D1 P! B0 y) Q, h" D
如何获取选择点映射到视图空间中?源码分享- x. p( F' \& u, m2 r

5 ?. H0 ]% l( ^2 D' ~) X
  1. //------------------------------------------------------------------------------9 r- o. p: t+ c' [0 ~: g
  2. // Select Screen Position and map to Modeling View Plane0 x- E- ]8 l8 J: [' m  @
  3. //------------------------------------------------------------------------------
    . A$ z1 R" t  w6 `) m
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    ! x6 y8 U/ _! |' y
  5. {! ?( l( t& h3 `7 j& g
  6.     NXOpen::View* myView = NULL;3 K; Q. D1 h* N% i( D7 R# e
  7.     NXOpen::Point3d myCursor(0, 0, 0);" G% o' ?( A  q1 w0 B

  8. . U, h' q% J# R! Y
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);* @, e- B6 b- m2 c  \) {
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)5 C) ]( V7 y# i
  11.     {$ r3 ?6 u  R& i1 P
  12.         // obtain the current default annotation plane where PMIs are placed on
    # f/ |5 }: H& ~
  13.         NXOpen::Xform *xform1;
    3 D( n- g7 p; g" B  x0 C+ G
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    : k4 h6 q. h( r7 f( ?
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();* x, E/ B8 {! \; _
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    5 s. D7 a8 g2 C6 u6 \
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    4 D) `  j% d$ Q/ a2 O1 P! B2 q

  18. + F) k4 {, e8 j4 X# f: I) I# s
  19.         // create the ray 'into the screen' at the selected cursor position
    " U1 u* m/ _; F) [5 e1 E  K
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    " M) m% R9 Y; L% C/ L
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);$ Z7 B8 t6 H$ ^# S9 A: n
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);2 R! V' C9 N  Q% ?3 x/ }
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    + P4 M8 w, s4 x) z2 S: ~" S; P& D+ ~
  24.         lineRay->SetName("Ray");
    8 n" z1 U# S  d6 Z( I- t/ n
  25. ! N0 k  v( B9 D+ Y' a/ t" z
  26.         // create the plane from the view to intersect with the ray& u% N" m: n- i; R
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ! W: }' k% ?! D( E. h' k
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ; }* Z' u2 L; j& y& c3 C3 M
  29.         planeView->SetName("ViewPlane");
    ! O' Q$ a4 x( [% P6 _2 y
  30. 7 q: i- L1 A; ^; A7 f# a% Y
  31.         // now create the intersection point- l; R) p& ^( K5 c
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);$ x6 C9 o& b: h( N# a
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    . m7 d& r4 k2 b
  34.         pntInterSect->SeTColor(10);9 v) C  V, ~3 {- i) b9 N
  35.         pntInterSect->SetName("Intersection");
    - c! \5 h: |3 R& p. Z6 F1 Q, P4 J
  36. $ M% ~3 `. `, y3 I+ X  v
  37.         pos = pntInterSect->Coordinates();- P/ K! j) t6 h8 h( h) a# z1 T, G
  38.         print("\nPMI Position:", pos);
    2 d& w" t" }& e7 V8 q& H3 k4 V% @& u

  39. 7 ]# v1 G1 r, C; T. G) {
  40.         // clean up - comment to see intermediate objects
    9 G# E% }7 ?, ]3 X; _2 V
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    - _" S3 _; |; _  x; X+ \
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    / _7 O4 w6 ^, z3 _) X5 O; N
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    8 }( X5 A5 L' Z; p, `: a4 M
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    & `5 b  M/ w8 i
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);  e* y. I5 N1 f# d8 U  H, K; `
  46.         m_session->DeleteUndoMark(markDel, NULL);
    . y% y* T9 E0 R% p- A
  47. . z5 H) _  ?0 ]. A. Z
  48.         return true;; ^; _( f- i' Z5 `$ G
  49.     }/ ^! C6 H0 m& e3 k9 a% ]& L- n- w
  50. 9 P. h% l/ E  U+ H! {
  51.     return false;
    + e4 ^8 K" k4 q. N$ M
  52. }
复制代码
: W' L/ B. L1 D2 s1 t. a) f/ n/ R9 ]( ^
: H! l3 a" }+ n0 I( e
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了