|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. a3 l# R+ r6 R6 r$ \NX二次开发源码: 装配中选点,并报告父对象
% x( r$ J% k7 w1 W# [7 j
" Z6 |* h' @; Q% Y' H" P5 t* H- <P>Option Strict Off5 \% {' H. _# F8 v
- Imports System
Q" o y( S3 m: k, G# ]: b - Imports NXOpen: F3 E7 b, m7 P. H) h+ k2 R* ]2 g* d
- Imports NXOpen.UF+ i4 ]1 }/ N/ a7 Y0 w e' H
- , D, t( R$ j/ w- R% \9 C
- Module Module18 | K% ?. o; n4 m8 f6 r
- ) l* q" @7 `0 n
- Dim theSession As Session = Session.GetSession()) ?4 b# Y. L r3 y
- Dim theUI As UI = UI.GetUI()
' m M7 r! g0 I1 P' [ - Dim theUfSession As UFSession = UFSession.GetUFSession()$ j b% v; q7 |
- Dim lw As ListingWindow = theSession.ListingWindow& L! S& i6 |. c. B
- Dim pickedPoint As Point
$ C7 u3 h# w+ g% C. B' n: _0 `' l w - Dim myModelingTolerance As Double
3 W( w2 }- s/ k- |. f; S2 D% J -
v! { z4 z( Z1 r( t6 e" m - Sub Main()
9 k$ ?. w4 R% v -
7 T ]6 m7 [, m5 k C0 s* h F5 c" t - theUfSession.Modl.AskDistanceTolerance(myModelingTolerance)
6 |5 g# t7 S: G4 P) e! n - 4 i, o) N4 a+ _! X' d
- Dim workPart As Part = theSession.Parts.Work6 Q [1 G. W3 X
- lw.Open()6 S, i( d# A7 `% h0 N
-
/ f/ |- i7 d& S) l" f, }- C - Dim myPointTag As Tag6 [! ~ f/ }4 q2 S, k0 X
-
8 L* ]) z& V4 L - If Not select_point("Select Point", myPointTag) = UFConstants.UF_UI_OK Then
; n W7 _4 ]# a9 P% a - Exit Sub: I4 n7 Q0 E3 Q; S8 {5 z
- End If
, |, V# d* _- r. y0 B$ h -
# _! Q; u5 E2 M- f8 R/ j - lw.WriteLine("pickedPoint: " & pickedPoint.Coordinates.ToString)
9 J# p8 _# T a7 b - . T }8 e6 |5 h$ y' ]1 \ P
- AskParents(myPointTag)
/ J- ^* H, Q9 [3 m [! a; r3 ` X - 1 j9 S; L0 x& c' D/ ?
- End Sub1 z) e- x. e8 @- }
-
: P7 p& }: ^! b& C& U: q% {- b5 B g - Sub AskParents(ByVal objTag As Tag)
. o& X- o! W H" p7 @$ p - ( y0 I) o+ @0 m" v1 J, [# a8 M
- Dim n_parents As Integer
/ e Q& e0 Z1 h - Dim parentTags As Tag()0 q& M O4 x" n& n& [3 u- z
- Dim myPoint As Point7 E" f& s7 R' T" k) t+ h+ h
- Dim myEdge As Edge
9 s2 \9 o8 q( F8 }5 b - Dim myXform As Xform
1 ]9 s. N) K1 N - Dim myTaggedObject As TaggedObject v5 Q+ S6 H6 y
- myTaggedObject = Utilities.NXObjectManager.Get(objTag)) Y, U1 c, {8 A! S$ N+ y
- 3 m. w3 Z r a/ n
- If myTaggedObject.GetType.ToString.ToLower.Contains("point") Then3 h! ?; T+ O5 N( g
- myPoint = myTaggedObject
: k) ^) ~# t6 r - lw.WriteLine("the tagged object: " & myTaggedObject.GetType.ToString)) N% L/ ]- K1 T2 g& C* ?9 P
- lw.WriteLine("")3 T0 V9 j+ a4 k8 y! v
- - d- \9 K B3 W. o
- Try3 K6 f$ l% I- R* R: M) N( f8 Z9 T
- theUfSession.So.AskParents(objTag, UFConstants.UF_SO_ASK_ALL_PARENTS, n_parents, parentTags)+ i2 R. [% T7 ~$ L
- lw.WriteLine("num parents: " & n_parents.ToString)" q0 D/ R( U+ K- `9 k
- For Each parentTag As Tag In parentTags
7 H, n$ J8 C( y k0 O - Dim parent_object As TaggedObject = Utilities.NXObjectManager.Get(parentTag)8 i3 V8 q, M' h
- 1 N6 r2 } \' ]0 @ r
- AskParents(parent_object.Tag)
2 T3 f0 ~3 K4 {+ t% e% q -
( ^" M. {# B! ^! ^& i* S4 v - If parent_object.ToString.ToLower.Contains("edge") Then4 _$ K, w( R8 g% \* K$ h
- myEdge = parent_object
2 |" E: ~% N8 ]# u; f - lw.WriteLine("")/ o# S) H1 q g" ~ ]
- lw.WriteLine("edge type: " & myEdge.SolidEdgeType.ToString)- X/ }& H/ |; X( n. a
- lw.WriteLine("edge length: " & myEdge.GetLength.ToString)
7 c- R$ i& p7 K% h, I0 a - lw.WriteLine("edge owning part: " & myEdge.OwningPart.FullPath.ToString)
. v! {+ o* D( w S8 w - ( T* `/ g* I9 Q6 T W: r) w
- Dim partTag As Tag = myEdge.OwningPart.Tag% H r0 y, F# y1 l' N
- Dim occTags() As Tag
' m& b( y/ n J. _; k1 H - theUfSession.Assem.AskOccsOfPart(Tag.Null, partTag, occTags)! p) X( p4 `& n. m1 W) b
- lw.WriteLine("number of occurences: " & occTags.Length.ToString). [; d" ]& ~" l- J
- For Each temp As Tag In occTags8 [- ~) e' l; s; J/ M
- Dim myComp As Assemblies.Component
; X3 V- @8 e( b9 }1 K - myComp = Utilities.NXObjectManager.Get(temp)
4 l* V3 X" t' ~9 H% T - Dim myCompPos As Point3d1 F* `: g; K6 [% b
- Dim myCompOrientation As Matrix3x3
( w' F, O. y9 a# c, \3 X* t - myComp.GetPosition(myCompPos, myCompOrientation)
! T- n: o2 J @' y9 n - 7 Z& ?, Q! k& O2 J, i: i) E, P$ }5 C& w
- lw.WriteLine(""); u" v: ~, @2 P" }2 \! O
- lw.WriteLine("component name: " & myComp.Name)9 O5 b( M- m" y. H/ t, \3 G3 @
- lw.WriteLine("component display name: " & myComp.DisplayName)7 k9 D% Q! U u/ H; |; _& I- [
- lw.WriteLine("distance from picked point: " & MeasureDistance(pickedPoint, myComp).ToString)( V1 l' m/ O' X( Q
- / `" z7 e- W: s3 j1 Y+ S1 B; m
- If MeasureDistance(pickedPoint, myComp) < myModelingTolerance Then6 U# E5 X- f$ a" K& P1 l& ~
- lw.WriteLine("** This is the component that was picked **")2 [# D3 u" G7 p, Y
- End If
( K4 H4 ?: P: z- W S2 \ - ( t0 z: @4 D7 G+ |2 C$ s
- lw.WriteLine(""); D* V7 h+ q: S) F3 t+ k
- Next
3 f8 T9 R! [8 u6 K5 o9 U - 8 ^+ \; F1 Q+ ^8 p
- lw.WriteLine("")
& [( j' n5 K; V! r: H" c8 ^ - End If% R# Y; c0 I0 d& j: E
- Next0 Y3 T5 j5 f- ~/ K/ X; A
- X+ b: u+ f; m8 N
- CaTCh ex As Exception
$ \! A o6 V9 |8 Y5 A% a5 O - ' NXOpen.NXException: Current object is not smart
0 [) b0 e& h& v0 { - lw.WriteLine(" Error: " + ex.Message)
4 Y: t2 d1 u& U, Y a4 u( H - lw.WriteLine(" " & myTaggedObject.GetType.ToString)3 T% P+ g$ u8 H, l' I8 ^' H
- End Try
" O1 q% `0 m _/ | -
! l5 ]' ~ f3 A. N( p -
2 B b8 f% L2 e' W% ?- R4 w9 a - End If
* x: E9 f% g- z+ ] -
. d- y. `0 h3 {) u) `! m -
8 g8 k. B$ k2 r6 A - End Sub3 p/ ^/ H$ l; A3 v
- 4 d2 B6 h8 b' Y+ i6 ^# C I
- Function select_point(ByVal cue As String, ByRef pt_tag As Tag) As Integer
3 q9 k1 H: Y, \# j+ l: x i' w- Z; }0 Q -
4 O4 O/ @. X! ^, s# p - Dim base_pt As Double() = New Double(2) {}/ g1 B: h, {( [! F. c# P
- 'Dim point_tag As NXOpen.Tag = NXOpen.Tag.Null, f" d: r+ N0 M$ e, j2 Y; {! N
- Dim response As Integer = 0" `4 x G6 r7 _& H t& Q |
- Dim base_method As UFUi.PointBaseMethod = UFUi.PointBaseMethod.PointEndPt2 o3 C0 M1 p3 z: I. |/ _
- $ q9 W) K9 ?: |- { q
- theUfSession.Ui.LockUGAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)/ k2 \2 T8 z- f7 w+ C4 A* r* @& d
- theUfSession.Ui.PointConstruct(cue, base_method, pt_tag, base_pt, response)0 z6 a: X! H- A' d7 c0 F9 U b
- theUfSession.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
2 u) i% S" @! p2 p8 H0 c" u - ( z. [, W [8 _
- Dim pointLocation As Point3d
. K: t$ k/ h ]4 _; k! O - pointLocation.X = base_pt(0)
8 B+ x, r# t3 X% b - pointLocation.Y = base_pt(1)4 r: o4 `( c( v& ?6 n7 A4 B$ b
- pointLocation.Z = base_pt(2)
" Y0 N1 q# j1 C7 X" w6 [/ b: ] l2 G - pickedPoint = theSession.Parts.Display.Points.CreatePoint(pointLocation)
( p3 D2 L+ b8 ^5 Q- y [2 ] - 'pickedPoint.SetVisibility(SmartObject.VisibilityOption.Visible)
& f2 C8 l# b& U$ ?1 I. _$ w7 U7 F9 p t- r -
' F' f: ~$ y" W' [: X - Return response% p( E2 k* ^: e$ P: J7 Z
-
: m( P9 _* l6 [2 f- g# I - End Function
& E4 _5 ~" e- X4 y$ [ -
3 s: n5 |$ X" U) p5 _ - Function SelectPointObject(ByVal prompt As String, ByRef selPoint As Point) As Selection.Response
! }& X. h6 v& L g" @0 K9 R4 l3 h4 y% \ - . q* ^* |: v. E) ]+ K0 y
- Dim selObj As TaggedObject
5 C9 a7 ^1 q& |2 a* S5 O: K - Dim theUI As UI = UI.GetUI
; @0 R; v8 A# S+ v- I - Dim title As String = "Select a Point"
* U8 H g1 ]2 @) Z9 y4 @- d/ Y - Dim includeFeatures As Boolean = False% z+ I: r# [4 @6 R8 U; m$ `
- Dim keepHighlighted As Boolean = False1 P2 Z( I! ~' \7 b/ B' s2 V2 k' s
- Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific- @* s: ]5 M9 R! J9 {0 O
- Dim cursor As Point3d# A% n4 i" Y2 u7 Q$ e- ?2 M
- Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly( ?% D( G" |0 _- T' O+ u3 [
- Dim selectionMask_array(0) As Selection.MaskTriple
# @4 F2 v7 I- {% ~2 i - 1 n! ]8 d0 |% @$ ?( l: k8 C
- With selectionMask_array(0); l9 L# s) L% J
- .Type = UFConstants.UF_point_type
, j) [9 [$ \0 A0 b: C2 P4 { - .Subtype = UFConstants.UF_all_subtype6 ?) P2 t% H. o; ~
- End With
: D3 a: d& |0 K3 W6 { - $ [9 F7 w6 l# [( B
- Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
' a; x* D* r" u* T, E4 H- ^9 M - title, scope, selAction, _
3 m' d$ ], B8 I; s8 ?: r D - includeFeatures, keepHighlighted, selectionMask_array, _
Z4 O, M, T B! ^& c: @: H# K, Y2 V - selobj, cursor)
( w& q1 G s/ y' w: y3 Z1 g - If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
& H" O. T1 k* ~/ | - selPoint = selObj7 t" N" _: ]! V& l6 @
- Return Selection.Response.Ok
( L, O- H+ n; L' Y# s - Else) A1 j1 x6 M( ^2 G4 ?* S6 u1 W
- Return Selection.Response.Cancel
. M" |9 ]3 c0 q S! |0 U w - End If
# N( A) q [: l5 x2 d -
, ?) u: [/ m, ^3 ]8 V - End Function
+ [+ @& o7 B$ K4 r -
9 N! n0 f$ }& H: x0 | - Function MeasureDistance(ByVal obj1 As DisplayableObject, ByVal obj2 As DisplayableObject) As Double6 F; F& D: k V5 V _8 r
- % r9 u6 |" @6 l
- Dim result As Double
9 ?0 j* b2 B5 X W9 r -
/ A- g- S! [6 q7 @; s; o: K - Try
$ V' E' ~1 o) |. y6 J* n - Dim nullNXObject As NXObject = Nothing6 v1 {% T- [8 B+ g" i0 S
- 2 s: R- k' G; B5 _2 ~
- Dim measureDistanceBuilder1 As MeasureDistanceBuilder& b, j) I1 w$ I4 w8 Y" l
- measureDistanceBuilder1 = theSession.Parts.Display.MeasureManager.CreateMeasureDistanceBuilder(nullNXObject)) \& p) b6 r) F
- 0 e! K# {) ?- |, f
- measureDistanceBuilder1.InfoWindow = False8 s2 P& l* y1 x' B+ X% o! c
- + Y& s( p7 b% p) l) p$ P
- measureDistanceBuilder1.Mtype = MeasureDistanceBuilder.MeasureType.Minimum
' _2 |' k* j8 [2 N3 O - 3 I. a8 n& q1 U% w m' \0 k
- Dim nullUnit As Unit = Nothing" W) S% V1 i3 e# H
- 8 R* r; S* \+ u/ m% i
- Dim measureDistance1 As MeasureDistance
6 [/ y4 @# ~- c - measureDistance1 = theSession.Parts.Display.MeasureManager.NewDistance(nullUnit, MeasureManager.MeasureType.Minimum, obj1, obj2)* K- z8 A5 ~2 Y5 e, F |
-
- P6 [9 s+ P/ _7 n9 _& C( r - result = measureDistance1.Value
/ G8 {4 ~7 V1 [1 s$ T. V E% l - & R, U5 h( Y0 i7 ^: A/ z# m
- 'measureDistance1.Information()
) A6 @4 K4 ~) j- m+ c -
1 b% K$ r% b: E% u2 v, T2 t. k" a - measureDistance1.Dispose()- J( |: a- ^9 U7 t5 V9 v1 g
-
) ^9 p% i$ h6 g( _- L - Catch ex As NXException
/ m! V: B" _# q. d9 M- e - MsgBox(ex.Message)
0 a5 W' s# `! K: r - Return Nothing) ~; D4 `9 E8 Q( R! A c
- * p ^* I3 \4 @4 y$ ?) Q" M5 }3 S
- End Try% D. ] S# B- g: s: b x) S8 s N
-
# r. x9 Z/ o3 p9 _ -
- O* |9 f# N" c6 X$ Q - Return result9 g6 W/ A7 K3 x- E6 y
-
% y2 _4 y( U3 y5 k' [ - End Function
! x" i I7 o( @. V& }$ { - % [7 d, ?/ ?1 e0 L' J4 K
- 8 W5 k v1 V; U2 M9 p3 g
- Public Function GetUnloadOption(ByVal dummy As String) As Integer
3 e. o( ~5 E' }5 r2 Z - 3 q' ~" [- f" ~- C; q/ q
- 'Unloads the image when the NX session terminates# s& e+ d" l+ D% a, C) G5 P
- GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination1 i8 k5 v3 y; A3 q# W9 S
-
5 h' Z1 a! O* g v1 A# k, g: ? - End Function" }+ m {7 m5 X9 G* Z# p ~/ ~
-
5 h$ J) ~% q# t5 E/ N! |( E: \" h - End Module
* @3 s. r! P: t% _" A3 X - </P>
复制代码 / c$ v, y2 H) e$ ]
|
|