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

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

- {; T/ ]4 J& M
4 L& T4 ?! j+ C7 |3 R8 I4 |如何获取选择点映射到视图空间中?源码分享
/ x0 K+ h/ x* M9 A3 p. D9 K' y2 v/ m) _) ~2 ?- Q2 V
  1. //------------------------------------------------------------------------------
    9 a8 r) V8 A* G* z; j6 m
  2. // Select Screen Position and map to Modeling View Plane
    ' p% E/ _) K/ S  O' M
  3. //------------------------------------------------------------------------------3 R( ^" l  S2 Y+ l% u- s/ E3 Z; W
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    ' z& H/ q# O1 h- W
  5. {( E2 r5 Z9 z; c$ h' S! W) z) i
  6.     NXOpen::View* myView = NULL;7 p/ {0 W4 x& g2 r: O- ?+ k) ^" E
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    " x7 U- \# X: L: B6 u: I' D+ _) F
  8.   \0 e- E9 Q( N' M6 l3 N
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    5 }2 u+ ?9 c! f  e9 u: e
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)/ Y  v1 x  z+ u5 ^
  11.     {
    8 m, _* _3 x3 Y+ o3 M
  12.         // obtain the current default annotation plane where PMIs are placed on
    , `7 I& W- p1 j- e) ^
  13.         NXOpen::Xform *xform1;
    " a2 A$ T" }6 O  G) y
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    # ?1 {- s8 A+ G: x7 ]& B2 l% T
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();
    % t2 C' u) Z! t' R
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();( Q. G9 P# Y. G9 B2 Q- j; z
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);* j+ x8 ]' X) U! h: b
  18. ) }5 E/ P( ~4 e: `" y9 g! }
  19.         // create the ray 'into the screen' at the selected cursor position2 @1 |1 l  r7 [( |  `! r0 u
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    $ F% g7 z* p9 U. w) f% y
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);' K4 |" r  u8 u7 Y" ~6 j
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);# J' M1 P6 j) J3 i1 J" S
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    ! D! d! y$ X$ P2 s( u
  24.         lineRay->SetName("Ray");
    " ?: ^7 O* m( y. E- |6 K: h' E
  25. " k" p: j" G, a0 p
  26.         // create the plane from the view to intersect with the ray
    ! s. [, t" U9 I7 B0 n2 v! A
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);. w0 F& W& q+ C+ j3 u
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);8 c. H: q6 }! ]& D: n2 h
  29.         planeView->SetName("ViewPlane");
    4 j7 z3 {! [0 ?: m

  30. 8 l& z  z2 \7 h9 f  \' h# {
  31.         // now create the intersection point
    " r& G' \" N0 m' c
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);2 V% b& Z  l- {6 O2 s8 R
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ' ?. |: @9 M* u) A: i
  34.         pntInterSect->SeTColor(10);
    ( X1 Y3 H* _" E+ O1 ~3 a& [1 N
  35.         pntInterSect->SetName("Intersection");" N: ^2 s0 h* o8 L
  36. 7 K" c  ^1 a* \' I
  37.         pos = pntInterSect->Coordinates();$ a! E6 B2 a" D* k4 q1 q) J
  38.         print("\nPMI Position:", pos);8 b: ^- H: T" d' i1 ~( f
  39. 7 v4 w$ V6 w( q+ @8 c' r1 o
  40.         // clean up - comment to see intermediate objects
    " {, u( c& O" H( k
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    4 `! [2 _2 k5 C5 q" g
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);8 @  B' [: i3 x" _) g
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);1 Z0 J/ p' J- M% l" t0 E5 B/ m
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);, z) X% J* b) g/ T
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);
    ! Z0 Q- k7 b& j9 |+ E& h. i
  46.         m_session->DeleteUndoMark(markDel, NULL);% E. B. U& R2 R2 @7 ]$ ]$ h

  47. 1 j" S: d8 Z/ I2 l2 u
  48.         return true;7 S6 @  D$ |9 f$ e$ q5 i
  49.     }% C3 \. ]9 O  v  O8 q$ f

  50. ( g- l$ o" n* c% T6 y
  51.     return false;/ L. r: O3 l; x3 q
  52. }
复制代码

6 b! n8 p5 }( |6 {0 Z! f  q- E% ?: R: a8 p
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了