Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim theComponent As Assemblies.Component
If SelectComponent("Select a component", theComponent) = Selection.Response.Cancel Then
Exit Sub
End If
Const dumbPointName As String = "DUMB_POINT"
Const featurePointName As String = "FEATURE_POINT"
Dim thePart As Part = theComponent.Prototype.OwningPart
For Each temp As Point In thePart.Points
If temp.Name = dumbPointName Then
lw.WriteLine(dumbPointName & " found, location in part: " & temp.Coordinates.ToString)
Dim pointLoc() As Double = {temp.Coordinates.X, temp.Coordinates.Y, temp.Coordinates.Z}
'make component the work part
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")
Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(theComponent, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus1)
workPart = theSession.Parts.Work
partLoadStatus1.Dispose()
'map point from component to assembly
theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_WORK_COORDS, pointLoc, UFConstants.UF_CSYS_ROOT_COORDS, pointLoc)
lw.WriteLine("location in assembly ACS: " & pointLoc(0) & ", " & pointLoc(1) & ", " & pointLoc(2))
lw.WriteLine("")
'make assembly the work part
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")
Dim nullAssemblies_Component As Assemblies.Component = Nothing
Dim partLoadStatus2 As PartLoadStatus
theSession.Parts.SetWorkComponent(nullAssemblies_Component, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus2)
workPart = theSession.Parts.Work
partLoadStatus2.Dispose()
End If
Next
For Each temp As Features.Feature In thePart.Features
If temp.FeatureType = "POINT" Then
If temp.Name = featurePointName Then
Dim thePoint As Point = temp.GetEntities(0)
lw.WriteLine(featurePointName & " found, location: " & thePoint.Coordinates.ToString)
End If
End If
Next
lw.Close()
End Sub
Function SelectComponent(ByVal prompt As String, ByRef myComp As Assemblies.Component) As Selection.Response
Dim selObj As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a component"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_all_subtype
End With
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selobj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
myComp = selObj
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination
End Function
End Module