|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. S+ s: d, \/ X NNX二次开发源码: 装配中选点,并报告父对象7 a! ^3 m: \6 Q
+ i$ [! G& a# N% p4 s7 l- <P>Option Strict Off: D( n7 ~# k. I: _
- Imports System3 K' w& c) K/ `. {" y* G# f& J
- Imports NXOpen! |1 q1 D+ Q7 O/ c- c) h6 V5 F
- Imports NXOpen.UF# \$ I0 H- P3 K6 w5 u
-
8 C- p: Y% {( ?8 J - Module Module18 |6 W0 Y* i+ F l
-
, N! J/ \* O9 ]# S - Dim theSession As Session = Session.GetSession()
6 ~) O0 U6 Z2 |. i - Dim theUI As UI = UI.GetUI()
! F, b T) D; ]; W; M - Dim theUfSession As UFSession = UFSession.GetUFSession()
3 k5 W7 h( M, u* F s" }4 y - Dim lw As ListingWindow = theSession.ListingWindow9 f8 `6 a! O: V! d3 \* @ X
- Dim pickedPoint As Point
6 N! y. n3 w; _# u% M! k0 L - Dim myModelingTolerance As Double- i( I1 ?) c9 ~2 v) Y
-
% r, u, a& `9 G: ~ - Sub Main()
Q6 W S1 }0 h7 l, H -
0 M, W- E4 L7 D: u2 P! h2 W( y( h - theUfSession.Modl.AskDistanceTolerance(myModelingTolerance): s% I' n0 a, @9 e* ]
-
4 [& e( p& i7 N* U- R - Dim workPart As Part = theSession.Parts.Work
+ O; m, W9 i$ Q. [0 q - lw.Open()
% a& B2 V( d3 t0 @7 g, c& d -
& ]" K6 W7 p9 d* g - Dim myPointTag As Tag, X& H3 P) @! Z# K' Q7 v
- 0 n* q# ?+ X K# R/ B
- If Not select_point("Select Point", myPointTag) = UFConstants.UF_UI_OK Then
' w9 Q) D( Z% P! C& U - Exit Sub
. G* x& [0 @# [9 l - End If! H( f- u$ r6 y; |
-
2 q. W3 V0 ^! x8 ` - lw.WriteLine("pickedPoint: " & pickedPoint.Coordinates.ToString)
9 V; D6 D3 {3 Y -
( Z; D# [! M# e( I5 U$ H( A4 A3 Z - AskParents(myPointTag)
3 r" P6 _# ^. D# G% z3 P -
1 }* X1 B) ?5 [3 g9 w - End Sub
# e; I$ c5 [/ j - 3 Z3 d k- J T; n! l5 s
- Sub AskParents(ByVal objTag As Tag)
. _# h2 N: | T3 _ -
6 i# P& y/ U I+ r8 F3 g# c - Dim n_parents As Integer
7 x B# n1 N2 N( B6 o+ v8 W; @ - Dim parentTags As Tag()% O* N' t! G# U P8 |$ K9 c
- Dim myPoint As Point
c1 B& |* ?$ N' a/ r4 x4 C - Dim myEdge As Edge
; B9 D; ^7 d9 }5 q2 A) \ - Dim myXform As Xform
2 P* M d: o8 U5 Y - Dim myTaggedObject As TaggedObject% a$ q0 c2 J2 v( l- D+ o
- myTaggedObject = Utilities.NXObjectManager.Get(objTag)
. v# K8 u. [ ^7 u# k. |( L - 0 U. R; U. t1 _
- If myTaggedObject.GetType.ToString.ToLower.Contains("point") Then0 |2 q0 i4 y3 |% ^
- myPoint = myTaggedObject
5 p) x4 e- Q9 `* [6 I - lw.WriteLine("the tagged object: " & myTaggedObject.GetType.ToString)2 e: s# Q: T+ z" x& G6 e
- lw.WriteLine("")
3 g A) s3 f. }; l, [+ d5 ^ -
4 A: V+ q7 v3 j0 x3 F - Try l( n# e2 v; K
- theUfSession.So.AskParents(objTag, UFConstants.UF_SO_ASK_ALL_PARENTS, n_parents, parentTags)
+ A& g+ j# b. G( w; E' J0 Q$ F - lw.WriteLine("num parents: " & n_parents.ToString)% H9 W7 n4 O: J% S6 Z# ^
- For Each parentTag As Tag In parentTags0 s- Y$ R7 p$ I. ~: x' C
- Dim parent_object As TaggedObject = Utilities.NXObjectManager.Get(parentTag)
% Z i k, H/ ?4 u5 M" b+ z -
8 m' U, d( i, x: g5 Z - AskParents(parent_object.Tag): K/ C3 A; J* I M
-
* G; [$ b3 e" N6 U - If parent_object.ToString.ToLower.Contains("edge") Then
1 C( R4 l4 Z5 U5 r S, F$ h( `1 _ - myEdge = parent_object, }: \+ Q% W1 k$ R0 \2 U
- lw.WriteLine("")6 a' G0 O) u' Z. s$ Z' c
- lw.WriteLine("edge type: " & myEdge.SolidEdgeType.ToString)3 [; O) J& k% {
- lw.WriteLine("edge length: " & myEdge.GetLength.ToString)
$ i: k' H: T7 o& q% @7 E; s" E9 \ - lw.WriteLine("edge owning part: " & myEdge.OwningPart.FullPath.ToString)" \! X0 P& H. Q Z8 `6 `; @* `% g
- 9 V F) { C) e) I! _
- Dim partTag As Tag = myEdge.OwningPart.Tag8 b& `7 m N! b# Q; g
- Dim occTags() As Tag
/ J0 a- ?/ L+ y+ t/ @! n - theUfSession.Assem.AskOccsOfPart(Tag.Null, partTag, occTags)
3 Q/ C! d& \) p% i# }. U - lw.WriteLine("number of occurences: " & occTags.Length.ToString)
; K& a' [& P P - For Each temp As Tag In occTags
6 P- w( X, J' s6 G. T - Dim myComp As Assemblies.Component
) ?6 f3 h% s& N: s0 F7 H - myComp = Utilities.NXObjectManager.Get(temp)3 i3 T5 M; d+ s2 x: X3 @
- Dim myCompPos As Point3d
/ Q; z7 \: }% t1 C1 z - Dim myCompOrientation As Matrix3x38 [1 q0 E; Y' o3 S D3 t
- myComp.GetPosition(myCompPos, myCompOrientation)- d' ~: m. D O, _4 [
- ' g$ a; j; o4 a* U2 c' d3 t% I% x
- lw.WriteLine("")
9 u/ w% l; k' Y! k$ Z; Y3 G B T$ p! \ ] - lw.WriteLine("component name: " & myComp.Name)' |7 ^9 d5 z) b8 \/ N+ {* h, m
- lw.WriteLine("component display name: " & myComp.DisplayName)/ Z+ Y( f6 l5 |9 v6 F
- lw.WriteLine("distance from picked point: " & MeasureDistance(pickedPoint, myComp).ToString)/ t4 V. s$ [& X3 ~3 A4 _* q6 `5 f
-
5 a3 k6 b9 W6 F( s( Z - If MeasureDistance(pickedPoint, myComp) < myModelingTolerance Then" |; O: ]! ?- C
- lw.WriteLine("** This is the component that was picked **")2 g2 a+ b) a1 ?5 Z$ G5 N. `1 r/ u
- End If
7 t; M1 @# H% c; C* q - . a0 ~1 a1 ~* E# M) I6 ^
- lw.WriteLine(""): F# m4 \. \: a0 ?' R5 s
- Next
) V# j/ |# w9 f+ V -
- P" p; P, F+ ]4 |3 Z( f5 a - lw.WriteLine("")6 O0 J" {/ V- Q7 ?( g# g1 ~
- End If% z8 E' r) ^+ q3 ^- a) l2 r% r( N
- Next, n% \- v) N& R- U
- " D, j( K7 C1 i1 {1 P- q
- CaTCh ex As Exception: |" Y& |. S6 M6 F1 k. Q. W- r- j
- ' NXOpen.NXException: Current object is not smart& H% n$ h! J1 r6 p
- lw.WriteLine(" Error: " + ex.Message)( A4 R* j2 S8 V; _3 Y' c
- lw.WriteLine(" " & myTaggedObject.GetType.ToString)/ c' ?+ O7 c+ _2 |+ k- m
- End Try
v* z, t- l" m% g9 s6 V8 d - # d6 |8 N- U7 d8 o4 k& p( L, b; m
- / o) P# y+ R8 j, I+ A& j; S
- End If
. G$ I( ^# k1 v. F4 h5 _ -
5 D/ l5 u) b2 _ - * c7 |: F- ?" u$ D9 s
- End Sub
- v) v3 v; m8 v9 P. M0 G- p, S -
1 K! E0 g& n' K _ ^) M: n - Function select_point(ByVal cue As String, ByRef pt_tag As Tag) As Integer# `; V% i! q' B! N) n$ k
- - ]% T, f5 N2 Y' w0 V, ~& E
- Dim base_pt As Double() = New Double(2) {}
& l6 f8 R1 k& i* s3 I. x* c - 'Dim point_tag As NXOpen.Tag = NXOpen.Tag.Null
# h. m$ d. g1 W! ^ - Dim response As Integer = 0
; @7 ?8 A6 E7 K; W. L - Dim base_method As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointEndPt& m E3 B5 J9 j6 `8 T" e, m
- 7 w) g! o9 Z5 ^" Z0 l5 n
- theUfSession.Ui.LockUGAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
) h5 o n0 R9 W2 }5 z" b% q - theUfSession.Ui.PointConstruct(cue, base_method, pt_tag, base_pt, response)* Q- c. L- U/ Y4 I
- theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
- ~5 d7 a8 X8 O, p H - 2 k: l R$ L" b& X# w, t1 `
- Dim pointLocation As Point3d
& m$ `2 V" ?' r$ i; r# c - pointLocation.X = base_pt(0) a& F, D. Q7 T j, @
- pointLocation.Y = base_pt(1)
8 {0 P3 J/ \( J$ E" g8 l - pointLocation.Z = base_pt(2)4 Y4 \6 e/ i' B9 }; A
- pickedPoint = theSession.Parts.Display.Points.CreatePoint(pointLocation)
9 q2 {9 Z6 j* Z5 n - 'pickedPoint.SetVisibility(SmartObject.VisibilityOption.Visible)/ ^3 [4 S0 [0 U7 \
-
; _7 b1 a2 J, Z& y. B7 h& x - Return response
+ w0 _' q6 m; Z$ t9 | - 5 I4 ]& o7 s5 M9 G# R2 ~
- End Function, |7 S* K: Z" J* E% I6 O
- ! v. H9 a0 n3 C9 f
- Function SelectPointObject(ByVal prompt As String, ByRef selPoint As Point) As Selection.Response( {5 H. R- b& z' Z* N% A
- 7 z3 A: O$ e/ }. g
- Dim selObj As TaggedObject, C- d; [% Z5 x! \! B# W9 f$ o
- Dim theUI As UI = UI.GetUI
- t, n0 R. N/ b; q) x3 m# n - Dim title As String = "Select a Point" s4 f3 D, \' T( f
- Dim includeFeatures As Boolean = False1 d3 R2 ]$ j2 d+ m- m# Y% p; L
- Dim keepHighlighted As Boolean = False
1 k3 O1 G) h# D) J! j5 o - Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
0 U* q, d) `; I4 r - Dim cursor As Point3d
+ [# m. q% J3 p U" h - Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
: O- o- k/ U( I. z6 B) R2 v - Dim selectionMask_array(0) As Selection.MaskTriple
% \0 V6 t+ L6 |& Y2 O$ C4 ^( k% | -
( R& Q2 r# z0 ]+ V+ y& \; O7 u. j - With selectionMask_array(0)
5 ]& q8 ?' k4 W4 G( ^8 d3 ] - .Type = UFConstants.UF_point_type
/ y9 N- J3 W) O9 v1 v/ P# M# a - .Subtype = UFConstants.UF_all_subtype
/ P! c9 [, F* p8 z - End With
/ \* c/ O9 w u, k2 w# t* f -
# Q. G3 D5 `# p, \ - Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
2 V- k3 M; G$ N' O; U! S" T - title, scope, selAction, _
% a+ ^. g6 E8 l. D: A. o( G! G0 Q7 d - includeFeatures, keepHighlighted, selectionMask_array, _
7 a# t4 m8 _! P8 R/ H: a7 K - selobj, cursor); J5 F3 G: X- P( w0 |
- If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
1 p; T; N1 G' y - selPoint = selObj& J, E6 @4 ^1 y; C/ T
- Return Selection.Response.Ok
9 L6 ]# e5 `* K5 | - Else. l8 t! T* g8 _- ^: E% E! L
- Return Selection.Response.Cancel$ k* X- y- n8 T6 g$ A
- End If% [! y6 I6 V2 J
-
& m# i% m9 f& O5 D M% | - End Function, U# ^/ G P; f4 l: X5 {
-
, c$ A# _! c0 j6 C5 `1 c - Function MeasureDistance(ByVal obj1 As DisplayableObject, ByVal obj2 As DisplayableObject) As Double
* k) @, Z E4 {$ @0 E3 t! u - ( W, P0 E. ^; |3 g) o: ]1 H3 W
- Dim result As Double
* H5 k- m5 s9 t' C) b -
$ S: p3 C5 |% s) t$ M/ W - Try
2 Z7 f' g+ P w% I% {/ j3 Z+ U - Dim nullNXObject As NXObject = Nothing
, N1 v3 Z0 {6 C% ] - . j! @' [5 S% X1 t7 V1 C1 b
- Dim measureDistanceBuilder1 As MeasureDistanceBuilder
/ V' G$ X& y: k# }. `4 r: \; U - measureDistanceBuilder1 = theSession.Parts.Display.MeasureManager.CreateMeasureDistanceBuilder(nullNXObject)
2 Y4 a$ Y4 p6 b4 k -
, A K" p/ |$ g - measureDistanceBuilder1.InfoWindow = False
5 Z% u5 @# q8 f3 P8 F9 G& k' n( X -
# Z1 O( I. G5 }6 w( S - measureDistanceBuilder1.Mtype = MeasureDistanceBuilder.MeasureType.Minimum
0 h+ O Y, x, I7 p9 u% n -
! f2 @ g# }$ Z8 F6 p/ F - Dim nullUnit As Unit = Nothing5 v+ _, Y: o1 \9 c( I! g
-
9 |" o+ T G8 P0 E' d9 S. q; c - Dim measureDistance1 As MeasureDistance
9 w1 l9 f: L8 m1 y9 L; Q: s6 N# R# T% z. [ - measureDistance1 = theSession.Parts.Display.MeasureManager.NewDistance(nullUnit, MeasureManager.MeasureType.Minimum, obj1, obj2)7 g- V% o3 R l" u8 X- n
-
3 g& E9 g; e7 r s+ m/ R - result = measureDistance1.Value! o' g, I( S" D- U/ J
-
6 w2 a' A/ T8 M X! d - 'measureDistance1.Information(). k& D+ k: w1 V" |$ P; x
-
+ ]3 j. G* h' T1 t- h! G; |6 D' | - measureDistance1.Dispose()& G/ H; b9 n! O2 T
-
: p& O+ R7 }3 z( j$ b/ ]4 Y# [ - Catch ex As NXException
/ [' O1 S+ n j* `8 _ - MsgBox(ex.Message), V! c8 l( w2 p6 }, _) a5 K
- Return Nothing" G9 F% f0 |$ ?" Z% Q' A+ ?
- $ y4 ~3 f3 B3 [) H: M. T
- End Try1 g1 }1 W: a6 {& k& W. O/ I
-
0 W% I9 f* b' ~9 c; `7 v - , t B8 ~9 j. m! m7 j7 V. P8 [
- Return result
+ G% I- K/ `, l. C. r -
2 S" G* x" B1 B' E. ?( R! D/ H - End Function5 p* A$ y' N2 H9 q
-
4 V9 Q3 |1 y, g4 ^* v3 W -
& m% \, Z4 ]4 L - Public Function GetUnloadOption(ByVal dummy As String) As Integer
1 w% Q" t0 O6 e/ j m - # K: J4 [0 K7 m3 N4 t. f+ D- n
- 'Unloads the image when the NX session terminates( v# q3 g' e) k, H. _4 V O* k
- GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
7 i) [. M4 [) B/ {; |- L1 E, _ - + Z2 I& u% m; o" o- z& o9 D
- End Function9 k' j) S, l- J n q4 G/ F8 `2 j
- $ a5 h4 {* }5 n* Z- k0 H' h
- End Module2 U3 l5 K8 ]0 l; a3 x
- </P>
复制代码 & K/ [& F" K1 \" b( a/ j( s
|
|