|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
- b6 n9 ?. `* ?* A) j8 JNX二次开发源码: 装配中选点,并报告父对象; T, ^7 B% X H: `
- ; {0 R- g3 w, v
- <P>Option Strict Off* T0 A/ f4 y( r6 r' P- Q2 Z4 ?8 I
- Imports System# S; P2 @ g8 r/ l2 @" ~' f) q) q# F0 h
- Imports NXOpen+ H" _+ s: g- ]. M4 y% q. q
- Imports NXOpen.UF
$ b: l+ I- E3 y+ Y2 F -
* j+ v( y) Y. \: R* A4 E7 E - Module Module1
, D2 L. X! e( d6 I; O - ! X& i. D( p3 s7 d# k% h
- Dim theSession As Session = Session.GetSession()
% [1 Q! [) C' c: F4 L E5 o5 e - Dim theUI As UI = UI.GetUI()
n( i$ O0 P' k- t1 C9 @ - Dim theUfSession As UFSession = UFSession.GetUFSession()1 ]& X8 [' U4 O4 A
- Dim lw As ListingWindow = theSession.ListingWindow! ] i/ d$ P% F& H' [
- Dim pickedPoint As Point6 `8 W I3 `) J9 t& A
- Dim myModelingTolerance As Double1 r: R% r) ?* r8 ^5 T% ~/ P( m
- , _4 |/ p8 X% y: p: F% W
- Sub Main()
$ J4 G5 U+ Q) J" c: ]$ l - 6 G. C- I# x4 H0 j- n8 h, K, B
- theUfSession.Modl.AskDistanceTolerance(myModelingTolerance)( K8 I; ~. e: ?, X1 c
- 4 | \$ a; H) O8 ]. h+ p
- Dim workPart As Part = theSession.Parts.Work p* ]8 ]; m0 Q5 D1 J
- lw.Open()
$ R9 w" T B! H2 D0 W/ l -
$ c! v& s& L { - Dim myPointTag As Tag G" `* o* k" \4 R
- 4 `# }! U+ j& v p( f& |
- If Not select_point("Select Point", myPointTag) = UFConstants.UF_UI_OK Then
, D2 o# u8 i% y |0 y6 x - Exit Sub; O7 E: Y5 B! T1 t+ Y- x: m
- End If1 g5 i8 M! [1 H& J8 q5 n+ d8 ?; n! u
-
}4 e4 p- e- n2 v - lw.WriteLine("pickedPoint: " & pickedPoint.Coordinates.ToString)
) Q: o; A6 B! J$ l% { - : c% y$ U, H' o; |
- AskParents(myPointTag)8 J$ c! k* ^1 G* c% m6 G2 k
-
9 M$ C" d6 g9 ? - End Sub
6 X/ e( x0 S' v, r$ [1 E - . x2 v& v6 w% c! i4 W4 R+ H: A8 s" Q* h
- Sub AskParents(ByVal objTag As Tag)% ?7 u7 b \% G# B
- % o8 X) t+ J( f5 q \ l1 t
- Dim n_parents As Integer
9 k" N# N1 I( p( W$ Y( e6 F - Dim parentTags As Tag()
& e' t/ e4 N7 V! r1 ? - Dim myPoint As Point0 m" N' m, o+ c, w# D( B, w. N d8 R! V
- Dim myEdge As Edge0 a; d, H% G1 k0 G3 q3 l' [( m
- Dim myXform As Xform
6 W) E6 P5 @# n& F0 ~* m* z - Dim myTaggedObject As TaggedObject
: J+ L) r; D) s1 P4 G+ Z3 _ - myTaggedObject = Utilities.NXObjectManager.Get(objTag)/ P* r. b6 J. p3 \ z, `- u
-
5 q+ P8 a- M" M - If myTaggedObject.GetType.ToString.ToLower.Contains("point") Then2 X: L y* o: E. `: f6 b/ ?
- myPoint = myTaggedObject
8 G" ? w7 E' Y( E) n/ |( | - lw.WriteLine("the tagged object: " & myTaggedObject.GetType.ToString)0 C' y* r5 t' w: i7 k9 w
- lw.WriteLine(""); y/ ]8 j" a4 r4 a% \, x
- $ H$ R' S" s3 }- m4 L
- Try
, I, L) L& x+ p, i, j. k - theUfSession.So.AskParents(objTag, UFConstants.UF_SO_ASK_ALL_PARENTS, n_parents, parentTags)
! [% D% V1 Q2 o - lw.WriteLine("num parents: " & n_parents.ToString)
5 G6 M0 U/ X% p1 q1 ]! c1 W! J - For Each parentTag As Tag In parentTags* U5 y6 I8 ~2 f0 I3 ?- Q9 P2 [
- Dim parent_object As TaggedObject = Utilities.NXObjectManager.Get(parentTag). k4 {6 s0 g- @) n( u5 l
- 6 d- G- C9 Y$ F4 e+ L; O! N$ a
- AskParents(parent_object.Tag); Q9 w/ [' D2 h+ P8 i- j/ L8 E2 y
-
, m6 i; Z b3 A - If parent_object.ToString.ToLower.Contains("edge") Then0 t$ v3 i: }; _" R
- myEdge = parent_object8 n! p" X5 n+ W2 J7 l) T( O! R9 ^
- lw.WriteLine(""): B, |3 D/ ?; e+ Z$ w- R
- lw.WriteLine("edge type: " & myEdge.SolidEdgeType.ToString)
, @" [( t8 x" Q9 S* ^ - lw.WriteLine("edge length: " & myEdge.GetLength.ToString)* p( P" c: j% a
- lw.WriteLine("edge owning part: " & myEdge.OwningPart.FullPath.ToString)1 d; V" o" l4 Q; l- k1 n/ F9 b- ^
-
& L6 }2 x( V0 H: a, O+ V- y8 { - Dim partTag As Tag = myEdge.OwningPart.Tag
7 V' y! _* T9 V v" f l3 e) K! H - Dim occTags() As Tag
- O! y- \0 D# o; E - theUfSession.Assem.AskOccsOfPart(Tag.Null, partTag, occTags)
' n9 L Z" b! L - lw.WriteLine("number of occurences: " & occTags.Length.ToString)
" L/ h( ] W' f/ {$ b, O+ w1 b - For Each temp As Tag In occTags/ U! {7 f0 v; i$ [
- Dim myComp As Assemblies.Component' T7 h3 ]. @( Q) w6 x
- myComp = Utilities.NXObjectManager.Get(temp)
; f, t3 z& \4 J$ p# D - Dim myCompPos As Point3d: n p( Q D; R3 v* ?% d$ O, l
- Dim myCompOrientation As Matrix3x34 x8 [7 a" u, x
- myComp.GetPosition(myCompPos, myCompOrientation)) \. x, D) V# O' j) {! B K
-
/ p; `, \/ Q0 D" _5 v - lw.WriteLine("")) [- q! V0 S; F- |3 V1 a0 j
- lw.WriteLine("component name: " & myComp.Name)/ V" N0 b' r8 Z3 v4 t# {3 h8 u' g
- lw.WriteLine("component display name: " & myComp.DisplayName)5 s: x/ R3 g- w3 H. N8 Y1 ?* m1 m
- lw.WriteLine("distance from picked point: " & MeasureDistance(pickedPoint, myComp).ToString)3 o3 _9 @6 c, H7 w. X# Z x5 z
-
& k) ~) ]- ^: w4 F - If MeasureDistance(pickedPoint, myComp) < myModelingTolerance Then
+ l: `/ x7 I/ S- z& Z, |& D - lw.WriteLine("** This is the component that was picked **")6 i; e t' E) i/ R. I$ ^9 H
- End If
4 W/ @2 u4 U" `5 Z8 c. X* ] -
# g3 s: ~6 h/ v3 Z - lw.WriteLine("")
/ g) W3 B! @- S7 Z; ^! _1 v - Next1 v& A4 H3 w( N, V2 ~3 Y' N" Y
- 0 W; c8 E4 L2 \
- lw.WriteLine("")# q' o6 {" r- R
- End If
! V T+ q4 A8 P) @2 I4 [$ q - Next
6 c- R9 i" R2 N4 E -
: f* J' v6 Y" U, a+ v% ^ - CaTCh ex As Exception" T' g9 C; t' _! P5 O9 q
- ' NXOpen.NXException: Current object is not smart+ @9 s" s7 ~! H U
- lw.WriteLine(" Error: " + ex.Message)
6 ]7 B o% l9 k/ d( u% [4 J7 C- i - lw.WriteLine(" " & myTaggedObject.GetType.ToString). ]; g. y& m$ g% m
- End Try
, k0 Z, h0 h8 x% e$ d1 Y - 4 [* }: a' I- C) G* B0 i3 }4 k+ n& {
- 2 _0 E. I1 @4 s
- End If+ X) M0 g5 O! B+ B) O: S# Q
-
; p8 v ?3 [, @7 t, I: `* D -
8 U: ?* \4 v, }' }" ]. x - End Sub
! J. B9 `9 Q+ J" q2 x# I, k- J+ | - 5 z' d M' D3 e4 W1 E7 c2 f
- Function select_point(ByVal cue As String, ByRef pt_tag As Tag) As Integer( \# u" o" Y8 U
- 2 ^' B6 T9 \* A/ ^0 s
- Dim base_pt As Double() = New Double(2) {}
" C+ T. c- S/ p - 'Dim point_tag As NXOpen.Tag = NXOpen.Tag.Null
' u2 E' V+ |$ e* i# G, t/ c0 r - Dim response As Integer = 0! E- w/ A, Q' v) A
- Dim base_method As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointEndPt5 y6 \! w. R3 l
- 3 w" `5 d, A- j& V- [+ R' @
- theUfSession.Ui.LockUGAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
. }$ _. T. F# c$ j; c/ U5 Q1 y - theUfSession.Ui.PointConstruct(cue, base_method, pt_tag, base_pt, response)& ^' W, O0 x7 m+ a& |' b4 R
- theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
$ I2 @+ @% [' R: { V# @2 j -
* n0 A* ~ D; U - Dim pointLocation As Point3d# C$ P/ M4 w4 C- h. e
- pointLocation.X = base_pt(0)
$ b- g4 h4 X2 ~) ?! e8 i - pointLocation.Y = base_pt(1)
" y$ X# g" Q0 |$ G' t: X3 f - pointLocation.Z = base_pt(2)
7 K1 Y# l! D. N% C - pickedPoint = theSession.Parts.Display.Points.CreatePoint(pointLocation)4 J, K: A4 P' b. Q! v9 k
- 'pickedPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
1 y6 l& q7 k3 u& _; { - ( v, U; A5 X7 B) g6 f
- Return response
& P" i" [: ~5 j. q0 | -
+ z: p3 x; q8 D. t, a/ p# O; f - End Function( B) u4 z- ?+ S8 p# M
- ! N. e3 V6 X, g
- Function SelectPointObject(ByVal prompt As String, ByRef selPoint As Point) As Selection.Response
6 s- u9 v0 E# U H - . {5 P. G5 F5 B% E
- Dim selObj As TaggedObject# X- y. x+ n/ w7 M6 J1 A. k- c. j
- Dim theUI As UI = UI.GetUI1 w! U0 u6 @4 }
- Dim title As String = "Select a Point"
) t, e, O8 x6 M3 o# M6 [6 m - Dim includeFeatures As Boolean = False
5 O- l& b0 ~ ~* Q- M7 O6 n - Dim keepHighlighted As Boolean = False, H' a' c& h( H9 D% D
- Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
! R3 m, [" x; E - Dim cursor As Point3d
& I$ x4 w; ^, v/ H& [$ h - Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly' j# y- u5 f" K6 u5 x. l \
- Dim selectionMask_array(0) As Selection.MaskTriple1 v4 O6 e# ^ M6 v* J. n
-
$ @3 I3 w, O! N3 @ - With selectionMask_array(0)
) J5 U1 y* m9 y# X) q* [ - .Type = UFConstants.UF_point_type
% d- u( `( u8 j- |7 n - .Subtype = UFConstants.UF_all_subtype
3 z4 X5 ?+ M: z0 m - End With
0 M1 b R2 E" E, h F6 E. w B2 E -
4 ?. v) z- s! a- s5 O - Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _& {0 i' j" D4 G: O
- title, scope, selAction, _+ {% c2 M) G- Q0 l7 M
- includeFeatures, keepHighlighted, selectionMask_array, _
' _& j: }9 U! V8 M$ P - selobj, cursor)' M( X4 B+ E: |6 K/ M/ ]5 T
- If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
9 ]* }4 T+ w7 a. L& @2 u; C - selPoint = selObj( E2 l0 f0 |7 U5 c
- Return Selection.Response.Ok8 z% F" u; F$ G9 S+ M/ N
- Else: X, n/ q* R% |4 S0 f
- Return Selection.Response.Cancel, h& ^9 [4 b, _+ x% w7 q
- End If% `) r' C0 Y( J( x# e I( X! @
- $ a% z- y) m. v- S) }0 T- q% @7 f6 a
- End Function
' n& ~8 o& F3 ^, ~2 ], {$ ` }( e -
1 P# \1 r; i y3 L8 Q# m' y2 N1 b - Function MeasureDistance(ByVal obj1 As DisplayableObject, ByVal obj2 As DisplayableObject) As Double
$ W; [" _. R" a& `/ X% Z - ' e' A& m* c' o1 C
- Dim result As Double: N0 R8 N8 X5 S( Y8 X
- ( [: S v8 [( j Q4 E
- Try- _3 t8 _; v; }" v9 B* t
- Dim nullNXObject As NXObject = Nothing
" z: x, q/ F8 ~; \* g7 n - # d; a: M& J" e% K- p3 n; ~1 ?
- Dim measureDistanceBuilder1 As MeasureDistanceBuilder! ^* h1 R9 ~% G- o
- measureDistanceBuilder1 = theSession.Parts.Display.MeasureManager.CreateMeasureDistanceBuilder(nullNXObject)
3 q. O* M5 Q0 V+ M& P F4 i - & K l( Z7 r& E- v p! s. S% g7 M
- measureDistanceBuilder1.InfoWindow = False9 z3 z& W$ b) L( N& ~
- ' x7 Y) d# X: l
- measureDistanceBuilder1.Mtype = MeasureDistanceBuilder.MeasureType.Minimum
9 V( ]+ ?8 a" e! ?, h1 [: C9 J! \ -
+ K; X; d7 h) t" l! Q: v; s' @( o - Dim nullUnit As Unit = Nothing) T) i% u+ M- `2 P0 K/ X
-
# P8 c9 N4 _' n9 Y - Dim measureDistance1 As MeasureDistance4 L4 S8 K, X& |& Q- Z [; z, N
- measureDistance1 = theSession.Parts.Display.MeasureManager.NewDistance(nullUnit, MeasureManager.MeasureType.Minimum, obj1, obj2)
* c" T4 J; }2 H7 u1 M -
, |( x+ T; Q1 m- n0 a - result = measureDistance1.Value& c, S; J2 U9 }1 y
-
c7 I, ~9 p5 y5 N( }/ J( e - 'measureDistance1.Information()
: ~1 }$ G% n: Y - ( [8 e6 f* c$ B
- measureDistance1.Dispose()
" m# M5 T( D1 n9 ]1 _7 _ -
H" [1 v H; ^+ g/ i& e. V - Catch ex As NXException5 U/ ]; n. C& ]9 e7 r
- MsgBox(ex.Message)
9 s. e7 q1 }/ _" n/ M6 z+ J& B - Return Nothing
( p# g' R# D' N6 Y$ { -
) W2 ~$ e, @: q7 O- X7 v - End Try
! t! y1 j6 N# p: b& {9 `: `5 c$ M - ( c5 X" @' h9 s% x
-
# C1 D. d& I/ U# b - Return result
2 M" p8 o8 Q" _7 M/ ` - 5 d& e2 ?7 m2 {% y, f+ S. h
- End Function
$ _( b9 r: p# D! b4 ?0 |# P - ' N1 @7 `8 v) w0 P+ J2 b# N
- ' W N+ E8 c+ r% c
- Public Function GetUnloadOption(ByVal dummy As String) As Integer
7 C' f' w& {4 F/ @9 B( K: M - 3 e; j6 E7 l& P
- 'Unloads the image when the NX session terminates5 E/ P/ e9 O, ]; ]& R/ Z
- GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
7 r j4 O7 N% b0 r5 h - * i, T6 k: P$ w. g! q0 H) H
- End Function
! n! Q7 X5 k8 M - * w) w4 k# J; r) F4 \: M
- End Module
/ t$ q2 v' W5 }+ ] - </P>
复制代码 4 l7 `4 g. Q% S, |) X+ b: w& O l
|
|