|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* ~/ K( l$ C" {! k# U- Z4 h! Y, \6 yNX二次开发源码: 装配中选点,并报告父对象
4 g4 F( ]3 |8 o
; G8 o% R, @- T- s# f7 b- <P>Option Strict Off: b" ]: U7 U2 ]/ _$ p) P
- Imports System& g l) O. j x- q, Q. W
- Imports NXOpen/ i6 F/ f& |. ]. J% ~$ f# d+ ]
- Imports NXOpen.UF7 k4 v5 ^, D. a6 S1 H
-
+ R5 r i4 ]/ a2 x6 D- ] - Module Module1
7 R3 e5 @0 [1 L1 ]3 @7 }9 D" D - ! \* H# X* @/ I5 i3 b9 k
- Dim theSession As Session = Session.GetSession(); I9 _- ?' T8 I/ ?0 x
- Dim theUI As UI = UI.GetUI()
1 k2 y# }, ^ _0 y4 a/ [7 X- q5 ? - Dim theUfSession As UFSession = UFSession.GetUFSession()/ h: e6 B( [- k3 \; o- R% r" j
- Dim lw As ListingWindow = theSession.ListingWindow
. ?: g) f: z( C; A" {; A - Dim pickedPoint As Point5 H& S5 n. q: k; C; H4 m
- Dim myModelingTolerance As Double0 W S% n# g/ r# z
-
, K: v6 w- L* H: G; o% u/ I# n - Sub Main()
{* s2 `; ^/ g& c2 T -
1 x, u1 ~& O8 {, S/ H, G - theUfSession.Modl.AskDistanceTolerance(myModelingTolerance)
, K3 k8 B+ w% x -
, K4 l, N) Q7 O' i - Dim workPart As Part = theSession.Parts.Work, \: O1 q! [* \, M
- lw.Open()" n: _ t9 \7 S8 O5 z) j
-
/ y' U/ n0 L4 g7 A1 e - Dim myPointTag As Tag
: V& T7 U& p% f N - - z7 W7 L: z9 C/ I- B+ U5 E0 I) Q
- If Not select_point("Select Point", myPointTag) = UFConstants.UF_UI_OK Then
% s. v' J& I" m5 c - Exit Sub
. C: m A% a( @# [ ` - End If
. T: V, j( {9 B, O) ~ -
, [; l+ U: Y5 Y2 h - lw.WriteLine("pickedPoint: " & pickedPoint.Coordinates.ToString)( z& q% J9 q) K
-
3 O0 t* {) q, f5 r - AskParents(myPointTag)
! n6 D9 D/ M& W7 M -
+ U( ~: I" i. i" ^4 A9 d L - End Sub2 d0 H3 O8 w; a7 v- x, l& b
- / b" G8 e" e _' G* M; w
- Sub AskParents(ByVal objTag As Tag)
0 |3 K: K: p7 y -
" x5 l) A" }; @7 y( U5 s% v - Dim n_parents As Integer g: b9 r. m# U) T0 C$ `
- Dim parentTags As Tag()
( O- X$ P5 m6 {/ R [ - Dim myPoint As Point
d+ w9 \) z5 \' @" d1 i2 q - Dim myEdge As Edge
4 m6 c* q0 Q" u" j. i - Dim myXform As Xform3 ]) ^$ s, n: K- y: ~! p
- Dim myTaggedObject As TaggedObject
% F( N" k" P" f# `- A! [. f. v - myTaggedObject = Utilities.NXObjectManager.Get(objTag)/ n9 `% B0 N2 A5 ?
- + |. _/ [7 [2 Y- j7 |1 g
- If myTaggedObject.GetType.ToString.ToLower.Contains("point") Then
& U3 _# i; _6 p# Q. b - myPoint = myTaggedObject# T; r: y6 j* q! n
- lw.WriteLine("the tagged object: " & myTaggedObject.GetType.ToString)/ w) P; c- W! {/ `6 z' S
- lw.WriteLine("")
7 X; t# Z7 T: i% R- b - + s: m- l4 i, f+ a
- Try1 L3 F7 G% \# a) \1 a2 I- b
- theUfSession.So.AskParents(objTag, UFConstants.UF_SO_ASK_ALL_PARENTS, n_parents, parentTags)7 E {4 N- j0 P
- lw.WriteLine("num parents: " & n_parents.ToString)
0 }& H% e- y4 C: N5 J) o& c - For Each parentTag As Tag In parentTags
+ ?7 c# |! E3 |& e7 Q - Dim parent_object As TaggedObject = Utilities.NXObjectManager.Get(parentTag)
6 L5 u" y+ }7 u -
9 J8 Q$ J6 d5 o - AskParents(parent_object.Tag)
" a0 d# t2 C) {8 ` - 5 `* e ?" i. L8 U
- If parent_object.ToString.ToLower.Contains("edge") Then+ A9 V S3 L0 U8 D5 |; u
- myEdge = parent_object
3 t1 J! N! V, U) n' a R( P9 _% B& E - lw.WriteLine("")" T# C% o& j8 D* B. o; x' p( c
- lw.WriteLine("edge type: " & myEdge.SolidEdgeType.ToString)
: f8 h' p' e2 a7 L2 @- R; M: ~8 a - lw.WriteLine("edge length: " & myEdge.GetLength.ToString)( }, s2 p) i" P0 [7 f* N
- lw.WriteLine("edge owning part: " & myEdge.OwningPart.FullPath.ToString)( o" _' }5 e# M( M) R& j+ T
-
, S% Z; z7 E: C. \- v - Dim partTag As Tag = myEdge.OwningPart.Tag
9 r D! N3 n, ^5 ` - Dim occTags() As Tag
) e7 C/ F* B, n: O - theUfSession.Assem.AskOccsOfPart(Tag.Null, partTag, occTags)
B- T3 ]3 X6 ], } - lw.WriteLine("number of occurences: " & occTags.Length.ToString)
6 T. d t+ l$ k1 U/ Q - For Each temp As Tag In occTags
5 A: S# {4 R$ G6 D8 ^6 ~6 s - Dim myComp As Assemblies.Component
# o7 @$ Z! v0 Z - myComp = Utilities.NXObjectManager.Get(temp): v9 o+ J( {6 ]4 n* f
- Dim myCompPos As Point3d5 w8 m6 T- i$ W& R( E8 W
- Dim myCompOrientation As Matrix3x3
; Z+ J$ z# `. P0 r, `. T - myComp.GetPosition(myCompPos, myCompOrientation)! ?1 z) F6 c8 e
-
( f1 _) `! B( N5 @' T - lw.WriteLine("")
6 a0 R, V* S. E - lw.WriteLine("component name: " & myComp.Name)- d3 M5 D* Y3 | u: g
- lw.WriteLine("component display name: " & myComp.DisplayName)
) [$ T" m8 M! x5 @: I' P2 }! K0 @8 ^, ~ - lw.WriteLine("distance from picked point: " & MeasureDistance(pickedPoint, myComp).ToString)
: z8 }& d! j7 h4 ` -
! ~# ^/ ]0 e( @! _- ~* z+ @: S4 G - If MeasureDistance(pickedPoint, myComp) < myModelingTolerance Then
& i6 h5 f' T$ d$ z5 ] - lw.WriteLine("** This is the component that was picked **")% ]4 t4 J5 r4 u( f+ ]1 m
- End If1 F3 K7 Z# u, a: n0 w
-
+ X: P, a- v9 C" w - lw.WriteLine("")
6 x& y. R9 l( i+ O- p! X8 u - Next
6 D0 S% p9 C6 q/ q - 5 o6 }! ^0 L, ]6 Z; j1 A2 S7 U) j" ~
- lw.WriteLine("")6 K5 t1 D! @- d" w3 h7 o! \
- End If7 B9 k# M: X& Z8 q- @- E
- Next, _, M/ o8 _+ I; ~1 F( D
-
) I& u: v" G* j) j - CaTCh ex As Exception) O* ?6 r6 K0 C6 I( V
- ' NXOpen.NXException: Current object is not smart
6 v1 J1 w9 d/ n1 y - lw.WriteLine(" Error: " + ex.Message). b7 s* L w! f% T4 W* Z
- lw.WriteLine(" " & myTaggedObject.GetType.ToString)
$ T1 N( B* h$ W/ h - End Try
1 g% c" g- e' d5 k -
6 R9 o' |, Y3 f - & B! D% w; ]/ I( Z& n
- End If
( a4 e8 M( \$ R! l -
( @! Z) o4 M+ h" }8 a( X! | -
: `! X2 ^! I- w, F s5 o3 V - End Sub* P; d2 {; E/ E: Z# T
- ; U* Q" B/ [- a# R" n% b' ?+ }! g
- Function select_point(ByVal cue As String, ByRef pt_tag As Tag) As Integer7 j* ~/ Y5 f7 t5 Y( b. S
- # T) ~- P; _6 S- h$ N7 M, C
- Dim base_pt As Double() = New Double(2) {}2 P6 P; E6 k0 q
- 'Dim point_tag As NXOpen.Tag = NXOpen.Tag.Null
/ ]' q+ M, ?$ O% i+ m& N8 g - Dim response As Integer = 08 z, g! T7 _4 o9 ]. H4 e. P
- Dim base_method As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointEndPt
: q& G% ~; [8 b/ j - # ~ z: H/ u7 U9 @& C9 W
- theUfSession.Ui.LockUGAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)# P% D5 l/ `, m9 P
- theUfSession.Ui.PointConstruct(cue, base_method, pt_tag, base_pt, response)7 P, S1 Q6 p/ f2 o" ~
- theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)- i; }1 \$ m/ D) G% l" V
-
2 g7 Z6 e: {& i: T; v! L - Dim pointLocation As Point3d
2 Q+ b2 h" }2 q& U3 o& F: {: z - pointLocation.X = base_pt(0)* M9 g: A" e" v/ S9 R! k
- pointLocation.Y = base_pt(1), _ p Q! A3 N5 F2 y1 M
- pointLocation.Z = base_pt(2)0 E1 H: ~: B$ U
- pickedPoint = theSession.Parts.Display.Points.CreatePoint(pointLocation)
1 O6 w! w; W+ T! R j4 I2 V* g - 'pickedPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
+ W3 U3 [; |- |1 x - # C) K' v& ?: J" L6 {6 R }
- Return response
7 E2 I* Y6 m4 [6 d -
" g# I$ }0 Y* \6 o* } - End Function
, V! y) I- f5 }/ O' H -
3 ]6 `: r; C- c; i3 s1 E" A7 H - Function SelectPointObject(ByVal prompt As String, ByRef selPoint As Point) As Selection.Response
5 z: y5 y) B* H* ]5 T) U - ( t( M; e, ]' @- I0 ?6 e+ C
- Dim selObj As TaggedObject
1 w! [- D8 z8 F. z0 C - Dim theUI As UI = UI.GetUI
" y& Y/ l% K5 l* D - Dim title As String = "Select a Point"
; s# k7 f# m0 r- _ - Dim includeFeatures As Boolean = False
; Q, v: g+ q4 n* S& U8 C9 F2 [ - Dim keepHighlighted As Boolean = False
H6 l2 \7 t' ]+ i: h+ Z - Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific1 D0 M! V, x, v
- Dim cursor As Point3d' [" e, l- t1 i5 x. r* ^! |
- Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly9 M. s' E* \2 m
- Dim selectionMask_array(0) As Selection.MaskTriple! O+ P! N# Z2 A) I' G
-
( a' s0 F; w; W- w& D - With selectionMask_array(0)
5 \+ ~0 d& ?" Z7 b- C& W* M; G - .Type = UFConstants.UF_point_type2 d+ t/ a9 Y0 a; h s' W
- .Subtype = UFConstants.UF_all_subtype$ R. S, E3 a& R
- End With
/ |" `6 l2 L% X# O; x+ X; r% W) `% o - $ T& I& r' F, M, d1 O& U9 g0 J2 \- c
- Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
7 f' [" A2 T# e8 b - title, scope, selAction, _
2 ^5 O! R& X$ g8 H7 ?4 Y9 w6 O - includeFeatures, keepHighlighted, selectionMask_array, _- `% b8 i, M; P. S
- selobj, cursor)0 i4 O. O7 T3 {; S2 B2 D
- If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then2 k5 @' S5 A, T
- selPoint = selObj
" l/ q; C) Z0 W( E3 ]: n* p - Return Selection.Response.Ok# K0 p' x8 x2 G- k
- Else
4 ?% z" [$ L, c* h- a; H8 V - Return Selection.Response.Cancel1 L1 Z$ G$ n6 L i/ w1 |) @ j
- End If
# h! B2 W) a3 l) ^ - - d2 V6 ` P) w& Y
- End Function8 y2 O' P/ p& T* p, s8 Y
-
# z1 q' Q) o; t4 E - Function MeasureDistance(ByVal obj1 As DisplayableObject, ByVal obj2 As DisplayableObject) As Double$ }3 H h6 P' s7 y: ?0 y3 n7 l, S$ Q
- + t; y- Z2 ?8 k: W/ K# g1 [
- Dim result As Double# U1 I8 r5 l# ~* S& Z7 f, V U2 l
- / W! F0 Q3 u0 H* M
- Try
2 ]8 O c3 K3 P7 f Y, W# H( | - Dim nullNXObject As NXObject = Nothing9 z! Z2 K7 m0 Z: H! h6 n
- : P3 z5 Q1 K5 @* b. [
- Dim measureDistanceBuilder1 As MeasureDistanceBuilder. s& f. k* X' x. a& M T! Y
- measureDistanceBuilder1 = theSession.Parts.Display.MeasureManager.CreateMeasureDistanceBuilder(nullNXObject)
5 f# S+ O' d$ `& b5 Y -
5 p2 d* E f2 A# G9 G - measureDistanceBuilder1.InfoWindow = False
* E5 R$ m6 d, Z7 O - 8 o' Q: e: Q2 M) o/ u* r6 G0 K
- measureDistanceBuilder1.Mtype = MeasureDistanceBuilder.MeasureType.Minimum
% H* m( M1 ^- U9 m6 @) ~: S6 a - 2 B4 p: h- e+ n- V6 c' C9 K
- Dim nullUnit As Unit = Nothing
5 y; P7 i3 j; ]6 X- x9 S. h! T - 7 }$ b }7 |8 n1 r5 ^4 @ i
- Dim measureDistance1 As MeasureDistance5 L A. @; S1 Y8 L) }+ {
- measureDistance1 = theSession.Parts.Display.MeasureManager.NewDistance(nullUnit, MeasureManager.MeasureType.Minimum, obj1, obj2)
8 v7 A. n; Y- n# ~2 l+ K% F& E - 3 N# J# N! F- I+ u$ j& c& K( N- G/ l
- result = measureDistance1.Value1 _2 Q( Q$ h4 {; J0 x- E, l
- * `8 k: [- W! f& j& O: Y
- 'measureDistance1.Information()7 e; H, J1 r* x3 I8 Y% j
-
9 } t l. i. x1 ]- w9 H5 C4 J - measureDistance1.Dispose()" l2 }. U, T" U" L* a0 r
- % [, B- s) @3 b1 t0 L) {% l3 w
- Catch ex As NXException4 Q, W9 ^4 K+ ?, }
- MsgBox(ex.Message)" P* e* n7 u& w" F
- Return Nothing9 F* e$ G# g* K
- 5 W1 _! m" I6 o* I! r9 I
- End Try9 T/ r% Y8 m/ C4 W
-
0 a0 K! O. s' u1 n4 ?% l5 D -
6 Z5 J9 y' ]2 n, z9 d/ h( a9 Q. P0 J" h. G - Return result
9 M, X. o% a6 y0 T - * K" i& V8 ?" _0 m. L) r# N
- End Function
6 B3 N( B# V! I$ V H9 U( Y - 1 s* X2 I3 e' ~8 l4 v
-
# i+ \7 w! G: ~2 V' r g( q0 k& | Y - Public Function GetUnloadOption(ByVal dummy As String) As Integer8 X& |8 ~" l! l% v$ S7 C& ?
- 4 G1 n- B% t) |' V
- 'Unloads the image when the NX session terminates% ? f: d" ~% C8 l, x; m7 |
- GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
3 T2 G, V- \- k, ]( {4 s# D - ' ~5 \& A$ M {' \1 m; H# ^
- End Function
* `' W; ^, I ~6 F2 `! D/ E - : \ L- k p5 z( ~
- End Module
6 T7 K" H; j- \+ l4 i6 { - </P>
复制代码 7 Y, f7 |0 r" x* w
|
|