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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

+ \; O; _1 T1 j4 d) v# t' E5 {' e9 C, D  w0 {% P
如何获取选择点映射到视图空间中?源码分享
" L: F5 g" e; L9 F# e
, I' E/ v+ j6 @
  1. //------------------------------------------------------------------------------
    1 @) Q) o3 j7 J% h/ j" m
  2. // Select Screen Position and map to Modeling View Plane% ^' X5 O! w6 f; @& ^3 K
  3. //------------------------------------------------------------------------------
    4 d5 z  I+ f/ ]6 P% ^
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    + }2 V0 G" @# W! `
  5. {
    + c$ E' \1 v1 |" u6 F: ~2 F' j
  6.     NXOpen::View* myView = NULL;" p2 s! O6 I, E. j4 a( F( ?
  7.     NXOpen::Point3d myCursor(0, 0, 0);1 W' k- D/ R) n9 \# d8 B9 \
  8. 4 e: G$ U: J" L# V5 l9 F( X8 I
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);, b8 B. l+ z  F7 _- W+ Y
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)( i- \  M2 u" R; i* L
  11.     {# R: O3 f' m, M2 X2 s+ L% w
  12.         // obtain the current default annotation plane where PMIs are placed on
    1 `: n: X3 S+ g- r% v% b, h* f5 g
  13.         NXOpen::Xform *xform1;1 w  s6 k/ \- F2 w0 ]
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    ! h" }8 e- \" v% h' u
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    3 }) @' D# C0 @5 I1 `9 h
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();6 F% J/ f" V6 F9 j
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    + ]1 r4 k7 q' O) v
  18. & w7 X5 z% {1 H
  19.         // create the ray 'into the screen' at the selected cursor position
    3 I- y9 n7 e) O6 W
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();8 A# W/ p( \. s7 E% w  V+ D
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    ! f: j9 x5 r5 D) @  O' }* v) Z! F6 f$ ~
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
      G' m  Y3 O0 S5 z1 ]
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);1 R+ P; c' Y) Y& I
  24.         lineRay->SetName("Ray");
    ) y! ]& x, |7 a+ R
  25. 6 Y# i4 _2 N( p# ?
  26.         // create the plane from the view to intersect with the ray; N1 g' {! @% B3 n6 {% {1 v- `. d
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);+ ~+ h) N: V- ]) c6 h9 W7 l
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    : J5 Q+ E6 |. {$ l9 r1 p, o7 w
  29.         planeView->SetName("ViewPlane");3 {; H; t+ x/ S

  30. ; B) o9 X! \% P% z- c2 L
  31.         // now create the intersection point
    % s" ^/ ^0 F: j$ ^1 \
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    . j# w+ ?- V9 b  y9 Z" Y
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    * p9 c1 H$ Q% R2 w! b/ ~" C# R2 M
  34.         pntInterSect->SeTColor(10);
    * W8 \  m  E; W9 g) l
  35.         pntInterSect->SetName("Intersection");) _1 t3 G4 L% B5 {' }/ {8 I
  36. * e7 c0 X% N% \  s6 e$ H
  37.         pos = pntInterSect->Coordinates();
    & @8 L5 ~- G/ t( y$ `6 f" z8 q
  38.         print("\nPMI Position:", pos);" O" a1 f# F1 R# \7 ?) I% m7 @

  39. # ]" H  ?! `: J  e. Q- t
  40.         // clean up - comment to see intermediate objects
    3 `" A7 }* P6 X6 k9 G% D1 m$ H
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    - G0 k4 C4 i; J
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' G: [( x" |" j' M; ?, i' s
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);. f6 [3 Q( y! q* m& k( Z6 _
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    ) C5 L3 g; m5 v) G3 t
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);  K/ g" n& z  h6 b; q8 u
  46.         m_session->DeleteUndoMark(markDel, NULL);
    9 R' {, v/ [7 J4 Q

  47. 7 E+ U5 j3 e# N+ ^
  48.         return true;5 y# x$ G2 c9 e  f/ V4 {" S
  49.     }
    - k% p' Q9 z3 X
  50. 2 O, Z' ^9 G9 M' F/ D6 U  R& y
  51.     return false;
    ! X; O4 p/ ^3 i( M$ a. G
  52. }
复制代码

0 J6 U" i6 ?3 H' B: x/ c3 p8 h: W2 O
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了