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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

# p7 v  }% e8 {% x; b( b
& Y* p8 q- T( T# ~如何获取选择点映射到视图空间中?源码分享
9 @0 N) R3 E8 C& {% H+ r( t' e- ]1 q; [' p7 ?/ @( j, U
  1. //------------------------------------------------------------------------------
    4 f- I8 V& A' x/ X/ U
  2. // Select Screen Position and map to Modeling View Plane+ H8 t  G4 [5 \, W: ]7 q0 [
  3. //------------------------------------------------------------------------------% {( J) R# t( ?
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
      K) W, \+ [6 ^% `' T
  5. {: f: A  D! J" Q' l9 C3 V
  6.     NXOpen::View* myView = NULL;. {! l8 \/ l: S( L& w6 _
  7.     NXOpen::Point3d myCursor(0, 0, 0);& l$ G: b  d' K5 \

  8. 7 k; K+ Q* I8 c+ X/ K/ s
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    * ^! }5 o! a4 a2 u
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)
    + \2 K% d" f; A
  11.     {- L+ B9 m+ @, T% F
  12.         // obtain the current default annotation plane where PMIs are placed on' B" U8 ^, m" ?, d) t3 x2 G
  13.         NXOpen::Xform *xform1;
    9 t" S7 R+ C( F$ ^
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    + {( I5 z* m9 u+ V9 g2 o
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    + a& ?! c7 J1 V' X5 K
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    ; f; w9 S8 T; v# u5 M. l3 ]
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);/ N, K1 c0 H  g8 p. ~1 b$ M

  18. # V4 W- W% X  S9 F
  19.         // create the ray 'into the screen' at the selected cursor position6 K* G. n) M5 @6 p- ]8 w& L
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();) n/ e7 H$ |7 g
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);
    ! q$ t7 x0 D3 b) Q. ~
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);/ s. ^- k7 S" G) T& a# m6 w
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    , Y( ~& _! q+ H: l, c9 @  t
  24.         lineRay->SetName("Ray");
    ) k+ H& r& M# H" f! B% @
  25. 9 G! M+ S) \) i' s
  26.         // create the plane from the view to intersect with the ray6 M4 q( }5 g+ [9 U  D  d
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ( _8 F/ \4 J6 a
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ! y  I; b0 E$ k, Z2 D
  29.         planeView->SetName("ViewPlane");3 F) C3 W) z9 B: p1 z6 I( S& @
  30. . M$ h4 T0 o: [9 E1 H5 J
  31.         // now create the intersection point
    7 i1 V+ T. ?9 X( r4 x
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);
    ; f6 f$ h8 x( ]1 S6 |5 k
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);; D. V1 E0 o* W
  34.         pntInterSect->SeTColor(10);- _& L; d3 X1 G* Z% I
  35.         pntInterSect->SetName("Intersection");  ~; f- Y% K, M; ~
  36. " d$ E5 J/ T) l" G
  37.         pos = pntInterSect->Coordinates();" q4 o/ r' |( s% p/ T! h9 U  f) m
  38.         print("\nPMI Position:", pos);5 l. J( c( g5 T) x

  39. 4 g7 P- f% A4 e7 o4 n. ]
  40.         // clean up - comment to see intermediate objects
    - J+ w" i4 ~2 z3 D, X& ^/ c1 L
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");! I3 f* R. A$ L  o9 y0 Q. ^
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' w( P2 }3 @5 Q6 m
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);0 J6 B2 F' P3 D, z0 r9 B; G; Z
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);9 ~8 I% x: q5 H  X  X/ }( S
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);, L# x- H0 s* D" F8 H
  46.         m_session->DeleteUndoMark(markDel, NULL);
    # d5 ]/ L. @7 c. t6 N; Y; I
  47. % w: S0 t" l" a" [5 i  ?$ S
  48.         return true;
    $ Z4 ^# y- |5 U. {% O4 H* v
  49.     }% w3 Q8 y  o  x$ J* Z

  50. 3 K, k% j" b# v
  51.     return false;$ }7 g' s5 Z. G# Y
  52. }
复制代码
5 j6 G, h$ q/ ?
0 J' J- r2 F) V% X2 d, Q6 Y' G
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了