PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x
% f. P) L* U: L& W

/ l/ u# [0 O8 R2 [5 l9 O6 d如何获取选择点映射到视图空间中?源码分享% Y! e' J5 C) T. u0 l: M
+ ]6 k+ Q: f! t6 s0 n
  1. //------------------------------------------------------------------------------
    4 I) f5 @! f9 ]6 s% U
  2. // Select Screen Position and map to Modeling View Plane
    5 ~6 r/ z# v3 n+ M( i
  3. //------------------------------------------------------------------------------
    " v" H4 l5 `. I
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos), R" r# ]" \2 `
  5. {; R7 j/ T3 {1 K- }/ S
  6.     NXOpen::View* myView = NULL;9 e7 Y8 t7 A5 s* k, O
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    * x% W' y& Y' X5 X0 `) f; C
  8. 9 T. \$ q9 h1 A$ n
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);! U" _2 q( E5 s+ U6 x
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    7 ?' B7 B5 o+ s( L
  11.     {: f1 q+ F) o6 D: s: a: I
  12.         // obtain the current default annotation plane where PMIs are placed on: ~4 ~7 S, F# Q# e8 m6 P
  13.         NXOpen::Xform *xform1;
    7 C# Y# _7 R- i# J6 ]
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);) i& ^7 B+ C9 o& c) F/ c2 S
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();6 [( U. a: o# g& l
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();9 I3 z  }* \, r* d9 N
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);: Y" a9 t$ l1 e( I: c5 U5 Z

  18. / V) Y' u- t5 k8 c% p0 b' Q
  19.         // create the ray 'into the screen' at the selected cursor position. j: i7 y  M- r6 r+ _
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();4 c9 K  n# r  y5 U) a
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);. D. A! A# o( e5 G1 h# `
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);* W2 E! P( O  N9 Z; ]' H5 u& |
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);7 B+ o7 i7 \6 Y9 r; A- e% {& j/ Z
  24.         lineRay->SetName("Ray");
      `+ k# b, J8 p7 G2 Q* Z3 Q2 N& g

  25. + O6 J! O0 W+ Z  V2 }" O
  26.         // create the plane from the view to intersect with the ray/ |/ Z/ k( U0 F! d( E: D
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ) d! h) J2 j! n
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);4 D% {# @- V8 [* R
  29.         planeView->SetName("ViewPlane");
    3 u" n6 d+ l4 S& K
  30. $ G0 h1 [( |5 d# {8 O' q4 Y
  31.         // now create the intersection point
    + ^) ]4 @3 f' l1 D: @  D! m; n8 Z
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    , M; W0 E$ @7 A# E4 Z
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);* c$ K* C+ s2 n' q& {
  34.         pntInterSect->SeTColor(10);
    . h6 A' j% D& |
  35.         pntInterSect->SetName("Intersection");
    * ?0 V6 x5 {% D
  36. 0 R7 v1 O. H0 ?
  37.         pos = pntInterSect->Coordinates();0 X$ X: `$ j4 E! b5 w4 B+ D2 @
  38.         print("\nPMI Position:", pos);
    7 f  @1 q$ L- S0 N
  39. & j+ p5 P' ~- f7 F! o" a3 ]
  40.         // clean up - comment to see intermediate objects7 E! K0 g- E0 }; v6 {. a$ O4 I
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");" k5 |0 \/ ~/ O6 B4 g4 L3 d: h$ V
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);
    0 z4 p( `( _* u" t5 R
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);2 q) q' ^( v' P+ h. V2 P9 n: z+ k
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    4 a" |5 Z, k$ |+ Z2 P5 C- s
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);; G% j! N2 U% v$ m1 y
  46.         m_session->DeleteUndoMark(markDel, NULL);
    5 x: [* G/ V3 N. h

  47. 2 T' j% L5 Z" z3 x7 p8 J- l% x
  48.         return true;6 L% e5 ~& S+ Y
  49.     }2 ~6 F; J( X( m  e: L" G

  50. & T2 L6 N  c/ O+ d( n
  51.     return false;/ ^5 T, ]! e4 K" x- N
  52. }
复制代码
9 S8 N" Q' m3 \3 [+ j. I* s
( y1 W" ?0 X0 J* u# S' e# d+ A+ N
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了