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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

5 w( z/ O; V( @6 J( [% T: \' _6 o* T8 A; U9 ?3 q' x
如何获取选择点映射到视图空间中?源码分享
1 U7 m/ J  o0 T- F7 A
' P- ?- Z9 H, g  g
  1. //------------------------------------------------------------------------------4 U5 o& m4 V5 C( ]
  2. // Select Screen Position and map to Modeling View Plane
    / }& [6 Q: a0 h$ R
  3. //------------------------------------------------------------------------------; |, M4 T; s/ W! K' r% ^9 f( o
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    ) H; c: Z4 e3 R- ^( N. u
  5. {
    - {5 Z, X, {4 b! M' h: ~4 W
  6.     NXOpen::View* myView = NULL;
      n+ {% _: p# {. T& n
  7.     NXOpen::Point3d myCursor(0, 0, 0);  c- ]) |. j3 S* F
  8. ) P5 O6 t$ {* I+ A4 Q
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);+ V) U/ Y, N' w) ^7 }
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    / z* ]$ s% j8 _0 j# y; M* L
  11.     {
    / F* Y) |' ~  F- P" G
  12.         // obtain the current default annotation plane where PMIs are placed on2 a7 \7 b9 i/ ]# u/ J7 Z" R$ H6 G
  13.         NXOpen::Xform *xform1;
    * y  b- J+ f) H- F/ A
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    * j. Y: b' o7 ~9 L8 n' d
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    , p1 \  c! x" {: O5 Y
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();; y0 I7 @, d5 {4 R; ]3 c
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);
    # _, c6 }. p8 ?$ V/ c

  18. ! @, k* G, k- @1 W) P
  19.         // create the ray 'into the screen' at the selected cursor position6 [! W  M) I% Z) J; k" h5 f
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();" E7 t% k8 c1 [8 z
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);6 U, W/ Q$ w. ^  Y
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);2 H1 a4 Z+ T, p, R( ]# k
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);( M$ |* d$ `- P) P* o
  24.         lineRay->SetName("Ray");
    8 ^! m( x( |8 R# ]4 S+ @. S/ C* [

  25. ! e6 g0 Y& D: w' P* o& H
  26.         // create the plane from the view to intersect with the ray3 N3 F5 C6 J& }9 H, q9 A* ~& |% X
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
      K9 y/ P8 [6 Y# ^
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);% V' j- h* k! _' m1 F
  29.         planeView->SetName("ViewPlane");
    + ]( J! ^8 w# v! k( g) t* Y

  30. 5 W. |0 F/ g& W+ J# T3 p
  31.         // now create the intersection point
    ( ?- v; B5 r! x4 R3 K# S& q
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    8 z2 R; K# {# v9 P3 B
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);, h+ j6 ~- w$ e7 l1 h. j9 D" ?/ a
  34.         pntInterSect->SeTColor(10);9 V8 Y) N, r: W0 c
  35.         pntInterSect->SetName("Intersection");# z8 b, s: N* P+ `  X9 v

  36. ; l- L7 x; g  J( e' W' w
  37.         pos = pntInterSect->Coordinates();4 l: d/ f# s( `2 p4 e- |9 e- }" |
  38.         print("\nPMI Position:", pos);. W9 b1 q) Z+ r5 g" d7 \
  39. % B4 y, m2 R4 E& ~- b
  40.         // clean up - comment to see intermediate objects+ _* M( ]3 S7 y' C* q4 `0 v( H. a
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");# P6 f) g5 D9 \& F
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);6 ]) ?7 D6 Q9 w5 q) l
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);+ ~/ Z% f! R+ x6 N
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);  h9 B% r9 d: D
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    ' m/ M/ i( N) v! \4 F4 X: E" R; O
  46.         m_session->DeleteUndoMark(markDel, NULL);
    . y/ S0 Q, j1 i* [+ V) O; }* u
  47. # |# K# s. A) p% |
  48.         return true;8 c1 p& ?% B- v
  49.     }
    / J/ a3 M2 o- @8 V' D' y
  50. : W" u% E' t) h/ ~. v" }
  51.     return false;- R% l2 i# l  l7 q" V, K
  52. }
复制代码
7 E) p1 H4 z2 O& \* t8 @1 n& \$ `
% m7 F" c) N' I
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了