PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2023-7-15 12:08:47

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

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

x

6 Q  F1 I0 r1 \7 J
/ t& U& w. Z, |( I0 M* a如何获取选择点映射到视图空间中?源码分享$ @, Y% Q5 }7 I9 g* p9 y1 q6 j1 |

3 \7 r! A' l! m. c% v( ?" I
  1. //------------------------------------------------------------------------------  U1 ?! ?  e. @; J0 S
  2. // Select Screen Position and map to Modeling View Plane
    3 N/ f+ c( E9 ^  e7 X
  3. //------------------------------------------------------------------------------8 H+ D) p  C1 y/ W5 ^8 `7 y
  4. bool GtacPmi::SelectPmiPosition(NXOpen::Point3d &pos)
    % f# N/ e3 t* g: _9 O* j+ p
  5. {9 w% C5 R# U9 G/ o  q& p* x, q% W
  6.     NXOpen::View* myView = NULL;
    8 ~/ t! Z8 _% S; e( Q) x
  7.     NXOpen::Point3d myCursor(0, 0, 0);
    6 x5 A- m( |; f5 @! S$ R# x

  8. 3 P8 c$ t0 [* r: K0 u* ]) _
  9.     NXOpen::Selection::DialogResponse myResponse = m_ui->SelectionManager()->SelectScreenPosition("Select Screen Origin", &myView, &myCursor);
    ; j5 t4 a) C% S+ b3 l
  10.     if (myResponse == NXOpen::Selection::DialogResponsePick)/ ?- o8 S/ W2 g: f
  11.     {# N/ [" n% e' ]; R. s1 c+ y: g: h
  12.         // obtain the current default annotation plane where PMIs are placed on9 W; r4 [  t( {6 B9 I, }, M$ {
  13.         NXOpen::Xform *xform1;/ V* `3 d/ N7 J: L% |
  14.         xform1 = m_wpart->Annotations()->GetDefaultAnnotationPlane(NXOpen::Annotations::PmiDefaultPlaneModelView);
    3 S6 w& D4 J2 {  i" k
  15.         NXOpen::Matrix3x3 vmxDefaultPlane = xform1->Orientation();# X9 v4 Z) W2 C  ~1 Y
  16.         NXOpen::Point3d ptDefaultPlane = xform1->Origin();
    2 V# y8 j6 j6 S! T6 h
  17.         NXOpen::Vector3d vecDefaultPlane(vmxDefaultPlane.Zx, vmxDefaultPlane.Zy, vmxDefaultPlane.Zz);9 ]6 T1 `& g. A  i1 s
  18. 5 N2 V" [5 t' b, u' V
  19.         // create the ray 'into the screen' at the selected cursor position8 S( E" _2 i9 h$ V2 A+ J5 Q4 l
  20.         NXOpen::Matrix3x3 vmx = myView->Matrix();
    # l' N. Z; [6 V
  21.         NXOpen::Point3d p1(myCursor.X - vmx.Zx * 1000, myCursor.Y - vmx.Zy * 1000, myCursor.Z - vmx.Zz * 1000);$ u( N1 {5 S8 h6 ~& n+ x  ^3 D. c
  22.         NXOpen::Point3d p2(myCursor.X + vmx.Zx * 1000, myCursor.Y + vmx.Zy * 1000, myCursor.Z + vmx.Zz * 1000);
    % S% P+ E4 `1 L; j3 Y
  23.         NXOpen::Line *lineRay = m_wpart->Curves()->CreateLine(p1, p2);
    9 J, B1 F# Y0 |2 W! h+ d
  24.         lineRay->SetName("Ray");' ]0 D, s6 {1 |# ~
  25. * A6 p2 b  U7 j' z' S& a5 D
  26.         // create the plane from the view to intersect with the ray
    4 w9 i  A$ v. L* ?/ @* T& u/ j' u
  27.         NXOpen::Plane *planeView = m_wpart->Planes()->CreatePlane(ptDefaultPlane, vecDefaultPlane, NXOpen::SmartObject::UpdateOptionWithinModeling);
    # I7 q. j! O+ @8 |
  28.         planeView->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);
    ; v/ |& X5 L6 x2 \$ o
  29.         planeView->SetName("ViewPlane");
    6 u9 i/ y! X  k0 f* P
  30. # D6 o( A" Y, y* p2 z7 X
  31.         // now create the intersection point
    5 V1 {1 x" M9 H- a; N
  32.         NXOpen::Point *pntInterSect = m_wpart->Points()->CreatePoint(planeView, lineRay, NULL, NULL, NXOpen::SmartObject::UpdateOptionWithinModeling);3 ], y$ {' L" N" l! A
  33.         pntInterSect->SetVisibility(NXOpen::SmartObject::VisibilityOptionVisible);4 q  ~. j, X2 l5 Q% U6 h: n+ r
  34.         pntInterSect->SeTColor(10);; h5 F! M8 r4 D/ k! N: r6 `
  35.         pntInterSect->SetName("Intersection");
    0 V/ _( J0 ]% i4 S& ~7 C

  36. + l% {) M  z1 j3 v5 t
  37.         pos = pntInterSect->Coordinates();
    2 B$ g. }6 K" H8 q( ?; ^
  38.         print("\nPMI Position:", pos);
    ' q3 j4 ~+ U5 i5 h4 G
  39. . f) Q5 J# u% h
  40.         // clean up - comment to see intermediate objects
    & o0 ^' g* J) P
  41.         NXOpen::Session::UndoMarkId markDel = m_session->SetUndoMark(NXOpen::Session::MarkVisibilityVisible, "Delete");
    & q2 K, h7 h; }) b( d4 n
  42.         int nErrs1 = m_session->UpdateManager()->AddToDeleteList(pntInterSect);' l& h0 E$ B* z6 ?
  43.         int nErrs2 = m_session->UpdateManager()->AddToDeleteList(planeView);
    8 c$ l* A5 W' i- a% D: u
  44.         int nErrs3 = m_session->UpdateManager()->AddToDeleteList(lineRay);9 u4 Y9 I- @5 z+ c8 l
  45.         int nErrs4 = m_session->UpdateManager()->DoUpdate(markDel);# w4 ?& T3 p4 @! D4 ~) R
  46.         m_session->DeleteUndoMark(markDel, NULL);
    ! j& u$ Y. ~% \$ X+ D  J/ O6 p+ x, v0 L

  47. 4 Q  W4 V0 F  R  t' N1 k7 b
  48.         return true;% k5 K$ [" q! F7 l3 b. c; _
  49.     }7 V# ?5 y* R6 @5 @; E& q
  50. 1 I: W( W1 {2 V$ s
  51.     return false;
    % K1 ^5 O% I/ t" d
  52. }
复制代码
% k% Q' Y% C+ j
& \* q! U& W! F$ H. W$ U9 v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了