|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
5 Q( b- |" c) ~
# q0 t2 F! a5 k) E: F- |NX二次开发源码分享: 使用NXOpen获取对象最小距离
9 @: h$ E& @3 ]4 ^/ G k2 u& |" Q+ k- E2 S
/ Y2 O8 R" Y% w6 L9 Q Q+ u5 u[mw_shl_code=csharp,true]
8 m- C2 f, Y" C5 q9 w Dim theSession As Session = Session.GetSession()/ ^, x# N. T# |* O2 ?( A- W$ q7 {; M
Dim workPart As Part = theSession.Parts.Work
5 o9 C9 k' h/ g- x% u/ A9 [$ R9 U7 G1 A' V; {3 ~, Y7 |5 z
Dim object1 As DisplayableObject = SelectAnObject("First Object")3 C; r4 ?+ X2 L7 S1 A
Dim object2 As DisplayableObject = SelectAnObject("Second Object")
) [, N) d- ^0 v# t9 S( |3 d9 O" x9 n( I4 }
' either obtain Unit as desired or use default (null) unit
# x/ J& ?7 a7 X) P& Z# @' o Dim unitMM As Unit = CType(workPart.UniTCollection.FindObject("MilliMeter"), Unit)
: O. ^2 v, E- n* j! O Dim nullUnit As Unit = Nothing9 Y4 h8 B7 J3 Q; {
Dim measureDistance1 As MeasureDistance
3 H& m. o, |# |4 w) o v; G
% s! x% R9 C* j measureDistance1 = workPart.MeasureManager.NewDistance(nullUnit, _6 l8 o! s9 I6 M$ p; F' [
MeasureManager.MeasureType.Minimum, object1, object2)4 g. a& W/ f; Z$ I
; y7 V$ {6 X" l6 A5 `' { Dim theLW As ListingWindow = theSession.ListingWindow! s; v6 K9 F# z) {7 e
theLW.Open()* W% ?( }* ?* H) b7 x
theLW.WriteLine("Minimum distance = " & measureDistance1.Value.ToString("F6"))- T4 G' G5 C8 }0 O2 b" Z! |
* C# P6 f# W' b4 }
' optionally, create Distance Measurement feature (needs solid_modeling)$ T& E+ N2 @) k& D( }$ z4 I& H
' Dim measure1 As NXOpen.Measure = measureDistance1.CreateFeature()
9 S' B) {1 M4 [2 s' ?. Y; | measureDistance1.Dispose()[/mw_shl_code]
, v# V3 S5 k, d( l! e7 W |
|