PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

" w3 d1 t0 B8 S. u- }' a/ n1 }9 @! Z$ o; p2 `& O
如何获取选择点映射到视图空间中?源码分享
- R9 L% h$ E& C0 X+ \3 g0 U, w4 c
+ d2 i- m6 Y' K3 H$ Y: W
  1. //------------------------------------------------------------------------------
    0 h* q) z- y6 R3 n. f4 Q  E8 p. G
  2. // Select Screen Position and map to Modeling View Plane3 [$ h5 v! c* H! A* j1 e. n
  3. //------------------------------------------------------------------------------/ L1 B/ K9 z4 w, H" r5 z
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    " y! G9 M7 w$ |0 W& w% `
  5. {
    6 e! Q) L- \; Y" w) ~
  6.     NXOpen::View* myView = NULL;
    . G: ?2 d  T: J8 J. }
  7.     NXOpen::Point3d myCursor(0, 0, 0);; x9 R( `  H, m, `2 Q1 B$ ^) S% ?
  8. ) J  ^1 `& B$ `" o7 {4 y
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);' r* U( ]/ z8 P1 ]/ P3 ~, O
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick); @4 j. [  e; ~, [7 z# C
  11.     {
    5 {* d: o( }, L' n8 z7 j0 k
  12.         // obtain the current default annotation plane where PMIs are placed on
    8 D: Y# V) v3 e. R6 A
  13.         NXOpen::Xform *xform1;
    " ~1 [! }  I7 j# y. H/ d
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    ) I7 ]& s" ?' g/ u3 d2 ?
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    ( h; s# R4 w' \9 ]3 q. D5 H% {
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    9 X( k% O' ]5 B) Y3 Y9 ^8 H
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);% a% N/ b2 N7 s! M3 m% |

  18. 9 V% T* E' V& z+ L+ K6 L
  19.         // create the ray 'into the screen' at the selected cursor position7 |' p% ?7 Z" i* s6 {
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    4 q2 c& n9 e! ?4 D
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    / h" U: i+ }# N3 u# i
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);: S, p/ E1 @# |- L
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    3 s& Q0 L6 u1 v" Z" v
  24.         lineRay->SetName("Ray");
    2 _3 Y' V' B; [/ E
  25. 9 X- U% i' c% t. E4 o' P, c
  26.         // create the plane from the view to intersect with the ray
    % N" X; g' u/ _5 O4 m1 g2 X3 @% f9 M
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);# P; `7 S' G2 b! V  Z: T( l# W
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    / V7 s: a# ^" f* i
  29.         planeView->SetName("ViewPlane");  C  X% v5 L; N* F9 F
  30. ; V# d2 I, H" j) P: B0 J# s0 `* ?
  31.         // now create the intersection point8 Q  k3 `) W/ l( d4 p! U* P! _
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    5 v3 S# ]! D0 i4 D  S/ {
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ; R" l& x! b5 H, B& e3 ?
  34.         pntInterSect->SeTColor(10);
    8 B" }% F2 v3 [: W
  35.         pntInterSect->SetName("Intersection");8 y" }5 l5 t4 ?) `$ F/ Z! }
  36. 9 Y, ]# k* r* j" B+ L2 G; A
  37.         pos = pntInterSect->Coordinates();2 Z1 v' {/ K; U
  38.         print("\nPMI Position:", pos);: ^2 r8 K4 O) J2 @3 h

  39. 3 b- `& g7 y* ^' r' |
  40.         // clean up - comment to see intermediate objects
    5 \# V+ A8 m4 N$ q6 O" X
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");8 |: _* Q' B) q0 V/ k( ]( I1 G: h- Z
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);9 L" `' ?( s. f4 R/ d
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);5 y' O" o! m) f
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);
    7 J0 T0 d8 Y& [6 Y# n2 T
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);8 \2 [6 ]# {; X: a1 s  K
  46.         m_session->DeleteUndoMark(markDel, NULL);! V0 s5 F+ ?  w1 e; B2 X' N# I, Z
  47. 7 X9 K6 s# p1 L2 o6 b: r
  48.         return true;+ N8 x" m, h+ q4 _% E  _, |: K
  49.     }" `: Z5 a; Q8 a) v( u' B8 Y

  50. $ l) o& M. x1 N1 H' D8 u
  51.     return false;
    , V  k3 D- e$ l/ C" N* G7 ~
  52. }
复制代码

' n% Z) F6 c1 o6 }* g, v7 b
# P% `* u8 |) I* K6 p" ]
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了