|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
, v& O. _# p$ X' P6 r# ENX二次开发源码: 装配中选点,并报告父对象- s/ H8 D+ u# V0 g! Z' H" w
. v( i% E* V' W- q" O- <P>Option Strict Off( M4 t# ?; F# J% ?" w
- Imports System) U& C6 E# }7 `. O- D
- Imports NXOpen
4 r. B6 f& z C# K* }" I - Imports NXOpen.UF
- x, E7 s% t) }- Y -
3 m3 `7 R8 Y6 ]& _/ G/ v - Module Module1; e9 d) M9 N1 R. K6 A1 ^
-
, E3 |! p. ]8 H4 ^, |) u7 @ - Dim theSession As Session = Session.GetSession()* I; n) H9 m* s9 J2 l3 Z
- Dim theUI As UI = UI.GetUI()- R* `" v/ A% A" x: Q9 }6 N. R
- Dim theUfSession As UFSession = UFSession.GetUFSession()
1 Y3 k# ^$ f3 S, h+ b& Z - Dim lw As ListingWindow = theSession.ListingWindow
6 J% A3 N0 j% P! H# v - Dim pickedPoint As Point
4 v& [3 X/ ^9 r+ \* ] - Dim myModelingTolerance As Double" w! p) D8 _- q) p! F8 a/ e
- ; l! B1 Q) {$ X$ H' U2 P0 D9 d
- Sub Main()2 C6 D9 d" |* m0 _1 X
-
4 Q) @5 r/ r" N6 z. m7 K& n) Q/ @ - theUfSession.Modl.AskDistanceTolerance(myModelingTolerance). z5 ^5 l$ m& l% v8 V8 [
-
0 g, g$ M( G( c2 e( c; ` - Dim workPart As Part = theSession.Parts.Work
' Y$ C% I6 a/ F - lw.Open()
" n' k" Y0 `! G - 3 f( q3 Q) e8 j e3 {6 f
- Dim myPointTag As Tag
3 ]. i; f/ X7 B4 Q% W" v - / |* h( i1 n& N( R) B1 M
- If Not select_point("Select Point", myPointTag) = UFConstants.UF_UI_OK Then
5 W- [) o7 l4 J) A0 Q; j; Y7 T - Exit Sub ]% S, H$ }) f3 h. T" W
- End If7 T2 @! B, j* h
-
; `5 g4 s1 E$ v# T" B h+ Z0 F0 q - lw.WriteLine("pickedPoint: " & pickedPoint.Coordinates.ToString)
! P0 u# ?7 W f; p8 Q -
3 G t& J7 V. E - AskParents(myPointTag)% t( ]6 H' U& i+ ]% f2 I
- 4 X% u9 s; T/ t2 t- Z5 K
- End Sub0 |8 T- t# z" G' i# z# j6 T
- 9 H' n! @' ~) @# W( { q
- Sub AskParents(ByVal objTag As Tag)
3 U# h& {- [! y# @& e d$ U* e1 z! P - # C+ k3 Y4 h" d( {. U! |# \
- Dim n_parents As Integer
' |" p! O* J1 f3 i$ m - Dim parentTags As Tag()& R% W* U \ w9 r- K
- Dim myPoint As Point8 e, Y2 _# I- z- d3 {$ H4 W
- Dim myEdge As Edge
8 z3 u+ s/ f: O - Dim myXform As Xform
" P3 r( r! p) ? - Dim myTaggedObject As TaggedObject
4 \7 ^- d7 a3 g/ t - myTaggedObject = Utilities.NXObjectManager.Get(objTag)
4 w3 M! M! L0 w -
0 P8 D J6 Y( C9 K9 f" x: g3 ? - If myTaggedObject.GetType.ToString.ToLower.Contains("point") Then
) B, n, u( |' C0 L& ? - myPoint = myTaggedObject- M6 Z4 x- m& c* y
- lw.WriteLine("the tagged object: " & myTaggedObject.GetType.ToString)
& M& A( W3 o& s0 W( f1 T; n - lw.WriteLine("")1 w7 j$ M0 D9 f; \
-
4 l, r N, a$ T) x5 m8 o - Try
0 p" W' K, E$ R - theUfSession.So.AskParents(objTag, UFConstants.UF_SO_ASK_ALL_PARENTS, n_parents, parentTags)4 K, Z1 Y/ s5 S+ E9 W+ ?
- lw.WriteLine("num parents: " & n_parents.ToString)0 P; \2 R7 E1 @9 s
- For Each parentTag As Tag In parentTags" L( v4 U6 x% }' L% e
- Dim parent_object As TaggedObject = Utilities.NXObjectManager.Get(parentTag)
4 R; j; N' ^& G6 l4 e6 ? - ' d. z' m9 H, U
- AskParents(parent_object.Tag)
{' M- L3 ]# n0 f8 m1 h - ' r+ b- E/ z( N, v" u2 R/ Y
- If parent_object.ToString.ToLower.Contains("edge") Then
9 D5 I( Z7 Y0 Q3 ] - myEdge = parent_object- F1 }! B. m# N
- lw.WriteLine("")
) e& T' y0 o* C; ], C - lw.WriteLine("edge type: " & myEdge.SolidEdgeType.ToString)9 D& y1 Q Z( x G6 t
- lw.WriteLine("edge length: " & myEdge.GetLength.ToString)
& L4 Q! C' `5 g7 ^' ~ - lw.WriteLine("edge owning part: " & myEdge.OwningPart.FullPath.ToString)
5 G/ h6 r% o2 K# t6 b - * U r0 U! ^" y2 _! H. C
- Dim partTag As Tag = myEdge.OwningPart.Tag
z' i$ M5 ]4 ?# d - Dim occTags() As Tag
1 U8 h; l2 K! |7 t. N1 J8 r$ a, P - theUfSession.Assem.AskOccsOfPart(Tag.Null, partTag, occTags): }& e" T4 h. H2 }; s
- lw.WriteLine("number of occurences: " & occTags.Length.ToString)
: d. b8 V# `( J$ D( [ - For Each temp As Tag In occTags
' ~9 G: l( S' d5 N9 g5 ^3 Z - Dim myComp As Assemblies.Component% V8 [- g5 P* p5 x3 j3 h0 E
- myComp = Utilities.NXObjectManager.Get(temp) {( A9 r# n, M, Q6 f; s
- Dim myCompPos As Point3d
* a; e9 E; I! M. Y$ R% p- F0 r - Dim myCompOrientation As Matrix3x3
9 [' w, d8 `5 ^: o% y( w" n - myComp.GetPosition(myCompPos, myCompOrientation)
7 U( P+ {; j/ \1 [* x4 `2 w - / [% I3 R6 L- b3 r i1 b
- lw.WriteLine("")
# ~% a/ p. J+ I: X - lw.WriteLine("component name: " & myComp.Name)' k) W& x" C/ J0 T6 Y
- lw.WriteLine("component display name: " & myComp.DisplayName)& D1 L9 p* A6 I3 R% m; V0 I
- lw.WriteLine("distance from picked point: " & MeasureDistance(pickedPoint, myComp).ToString)
, U/ ^5 d0 T$ ~4 ? - ( Y! i5 u' Z. ], _9 A7 ^
- If MeasureDistance(pickedPoint, myComp) < myModelingTolerance Then+ J+ q5 {" m0 {
- lw.WriteLine("** This is the component that was picked **")/ k+ P$ S$ I) B
- End If& ?5 f8 T N- m
-
: p' V" x/ k. k, x - lw.WriteLine("")
" s8 \- x$ B" C3 N - Next
$ j' s- z" I/ I- H5 `4 r& ? - 4 w, Z" O# |4 C! Q6 a
- lw.WriteLine("")& J8 a3 V1 d% {6 w r. D, m2 |0 }
- End If
% G* I% z. `, H2 x) Q8 f @" n - Next
3 w k; O$ t' ]0 W c% M- e -
7 ^% d6 g. Q- W- [0 F - CaTCh ex As Exception( n: @9 q# B/ L2 V
- ' NXOpen.NXException: Current object is not smart1 n4 V' \( o+ c- r! }
- lw.WriteLine(" Error: " + ex.Message)% O: ^* s7 y* g
- lw.WriteLine(" " & myTaggedObject.GetType.ToString)
( e4 n5 ]5 s5 e1 D - End Try; R+ p5 b b& W$ _% G& w
-
6 K2 s. p5 D: ]7 v% y8 Q7 [4 B7 u -
! }) Y" T. \# }" }+ M3 O e - End If7 j, H* r* V+ R. P. N
-
- `) R) O! y1 `0 ^ -
' |7 W/ f, W+ N* L% T+ U! v - End Sub2 o! H; `# K) z J, C
-
; d9 p1 e4 K+ K, u4 P) z - Function select_point(ByVal cue As String, ByRef pt_tag As Tag) As Integer1 z' g8 w7 L. e7 p. w
-
. @; p2 N% m2 F2 a% Y* N - Dim base_pt As Double() = New Double(2) {}
) @" O* {7 p/ u& g - 'Dim point_tag As NXOpen.Tag = NXOpen.Tag.Null& W6 ?. n* z# h3 B; p
- Dim response As Integer = 0* d/ N0 R# r1 o3 T+ |- u* S
- Dim base_method As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointEndPt7 Q5 N: }- D: A7 n
-
/ @$ E- K: v+ u6 K - theUfSession.Ui.LockUGAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
+ U7 \- M/ T* S U - theUfSession.Ui.PointConstruct(cue, base_method, pt_tag, base_pt, response)
9 D4 g* u1 H U$ d& r - theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
, E" W3 V6 ~# O+ l1 m p - 4 u! A8 E; j# B5 O. k# Z5 f
- Dim pointLocation As Point3d! [. b- P" s" S" f' I
- pointLocation.X = base_pt(0)4 X" j7 v4 T, ^( S5 z/ m
- pointLocation.Y = base_pt(1)0 y- x- w+ X& z! w. Z: V& ~# b
- pointLocation.Z = base_pt(2)4 M8 Y, p) d# [) |
- pickedPoint = theSession.Parts.Display.Points.CreatePoint(pointLocation)& z: X1 R6 [9 z% F9 ]+ y5 d
- 'pickedPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
! S" H# F- O! @( Y( b -
3 u8 ], \4 C/ S, q - Return response
1 v' |2 q6 \ q - / E( X9 F2 w$ Y6 R4 P6 i; A& O
- End Function
2 D5 `4 S/ m3 g - " P& z+ A3 m( {, Y# P1 [
- Function SelectPointObject(ByVal prompt As String, ByRef selPoint As Point) As Selection.Response' B, o# ]. t+ R' S' x. y
-
# m8 a( B/ x/ D7 [2 ?) f! @ - Dim selObj As TaggedObject/ Q& a k* S9 c& Y
- Dim theUI As UI = UI.GetUI3 z$ o# I8 j8 U$ @6 r% s
- Dim title As String = "Select a Point"1 ]1 Z! f9 r% c$ X" N/ V \! i8 T
- Dim includeFeatures As Boolean = False f$ x( _ w" N o% R5 [: z7 ]& c
- Dim keepHighlighted As Boolean = False
+ ]# B. W' I& G: P' W - Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
) {1 T7 W5 C( I9 I8 Q8 S - Dim cursor As Point3d) g' S5 u! K# Z7 g2 t I
- Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
; Y/ ~& X) ]3 V5 Y( s - Dim selectionMask_array(0) As Selection.MaskTriple
8 o3 e) T* W- s. O - # V v) v0 T2 P& K& u* c
- With selectionMask_array(0)
" ^6 F9 f" n( h' s - .Type = UFConstants.UF_point_type
4 z$ M+ g; S* W" ` - .Subtype = UFConstants.UF_all_subtype
) O5 A j- m! j; O - End With
. Z4 U) s$ S% Y. L - 0 v, {& X+ @$ ^) @. _; C
- Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
4 u. @3 A" f( D/ u1 T) [$ Q - title, scope, selAction, _9 c( }. a8 i6 o) Z' e! e T
- includeFeatures, keepHighlighted, selectionMask_array, _
# `& k" W. ]$ _5 [+ D - selobj, cursor)1 c1 B" L3 C1 P/ J; m
- If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
1 j) j w x8 @' e8 V - selPoint = selObj4 f6 Q- m0 y: c2 E" b9 f
- Return Selection.Response.Ok1 k/ f1 r! F4 [9 D! @0 t9 V, L
- Else$ Z" `! n d- O- c6 H, T
- Return Selection.Response.Cancel7 a; _+ b x0 ^0 b) y# n
- End If
+ \+ C9 e' D" V2 N2 B' V! n - 4 K3 H- @4 u# l' m# E, f5 g
- End Function
# G ~1 M; O# C7 s- ?' U - 8 I" t5 z* j$ E! ?
- Function MeasureDistance(ByVal obj1 As DisplayableObject, ByVal obj2 As DisplayableObject) As Double, L! m5 @7 M& j# W+ ^
-
: D E# D% B4 f# ^ - Dim result As Double
9 }% l: f& ?- W2 b/ `: x, U -
* S; A2 F5 g; M - Try4 t5 g, k; s) Q* r6 I# P
- Dim nullNXObject As NXObject = Nothing
/ g* l# Z7 c4 i* Q -
3 |) b% q; H* g; b" ? r - Dim measureDistanceBuilder1 As MeasureDistanceBuilder( L; l- ` z) q; g( D3 U( T
- measureDistanceBuilder1 = theSession.Parts.Display.MeasureManager.CreateMeasureDistanceBuilder(nullNXObject), Y5 N# v y; }+ I
- ' M0 f' b7 l$ O; Y
- measureDistanceBuilder1.InfoWindow = False
! ?/ E1 r# o' G* K$ B1 F -
2 V% h8 K0 O. M3 Z9 v0 g* L - measureDistanceBuilder1.Mtype = MeasureDistanceBuilder.MeasureType.Minimum, |" s* c5 L |& R0 O! A
-
% X- s/ {) U. _$ c( a - Dim nullUnit As Unit = Nothing
. @( g, }2 W7 q ` - 3 e0 {# b1 x' g. I
- Dim measureDistance1 As MeasureDistance
) k- ?1 }2 G/ g8 M - measureDistance1 = theSession.Parts.Display.MeasureManager.NewDistance(nullUnit, MeasureManager.MeasureType.Minimum, obj1, obj2)( x5 k; d! y+ ^, s5 c# g7 c
-
) E. a' \$ b' H4 f+ j* ]( c - result = measureDistance1.Value
2 E/ |9 Y `" X: L7 {7 d - , V" j# M, y' z" s9 w6 d
- 'measureDistance1.Information()
) ~* Q4 [6 U" L! Y! l - - e' N& i2 O9 O- x7 t7 P- [
- measureDistance1.Dispose()
' Z' j' S j: C7 N1 }) z -
: ^, U- H+ J |0 `4 Q5 W - Catch ex As NXException- N' r" h% b+ S+ Q
- MsgBox(ex.Message)% _" h5 T/ W T$ \( K2 ^) {
- Return Nothing
0 m1 w: e0 E# m- b- v -
% A+ f( }5 W" m' { - End Try) h; e; N4 U8 v
-
5 F% M: x4 i8 g1 b5 p9 ~ -
9 h) t1 g9 c, y# ]' a9 ^: }! ~+ T - Return result1 U1 K, }/ b" Y" C0 S T* X
- 5 i8 M6 z4 q/ j5 }+ C* C) g4 w
- End Function* _; g4 t1 p; I, Y
- ) A6 v/ C8 D E; x) [3 T. \ s: M
-
+ M8 g* m; c9 w3 b* \ - Public Function GetUnloadOption(ByVal dummy As String) As Integer( e; W6 i7 ]' c: ?
-
" X0 g% i# j( }0 r) ` N - 'Unloads the image when the NX session terminates
0 ~& I3 G% q- T9 l - GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination! B; {. Q+ d+ x# a( R2 D3 `# M, s
- & F, v: [2 W7 m$ o3 ~5 s
- End Function
% Y2 J- P( Y# h5 R7 w -
$ R6 v4 t! v1 o - End Module# p; o7 x1 c5 ] Q6 q( `: W/ e0 m
- </P>
复制代码
+ M( m4 k+ C! G9 L, m |
|