'==============================================================================
' WARNING!! This file is overwritten by the Block UI Styler while generating
' the automation code. Any modifications to this file will be lost after
' generating the code again.
'
' Filename: check_Attributes.vb
'
' This file was generated by the NX Block UI Styler
' Original File Created by: vegetagaru
' Version: NX 9
' Date:
' Time:
' NOTE: This file has been altered from the original to include component selection!
'==============================================================================
'==============================================================================
' Purpose: This TEMPLATE file contains VB.NET source to guide you in the
' construction of your Block application dialog. The generation of your
' dialog file (.dlx extension) is the first step towards dialog construction
' within NX. You must now create a NX Open application that
' utilizes this file (.dlx).
'
' The information in this file provides you with the following:
'
' 1. Help on how to load and display your Block UI Styler dialog in NX
' using APIs provided in NXOpen.BlockStyler namespace
' 2. The empty callback methods (stubs) associated with your dialog items
' have also been placed in this file. These empty methods have been
' created simply to start you along with your coding requirements.
' The method name, argument list and possible return values have already
' been provided for you.
'==============================================================================
'------------------------------------------------------------------------------
'These imports are needed for the following template code
'------------------------------------------------------------------------------
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.BlockStyler
Imports System.Globalization
'------------------------------------------------------------------------------
'Represents Block Styler application class
'------------------------------------------------------------------------------
Public Class check_Attributes
'class members
Private Shared theSession As Session = Session.GetSession()
Private Shared theUFSession As UFSession = UFSession.GetUFSession()
Private Shared theUFSSession As UFSession = UFSession.GetUFSession()
Private Shared theUI As UI = UI.GetUI()
Private theDlxFileName As String
Private theDialog As NXOpen.BlockStyler.BlockDialog
Private groupAttr As NXOpen.BlockStyler.Group ' Block type: Group
Private SPOT_ID As NXOpen.BlockStyler.StringBlock ' Block type: String
Private ZONE_STA_ROBOT As NXOpen.BlockStyler.StringBlock ' Block type: String
Private BLANK4 As NXOpen.BlockStyler.StringBlock ' Block type: String
Private BLANK3 As NXOpen.BlockStyler.StringBlock ' Block type: String
Private BLANK2 As NXOpen.BlockStyler.StringBlock ' Block type: String
Private BLANK1 As NXOpen.BlockStyler.StringBlock ' Block type: String
Private workPart As Part = theSession.Parts.Work
Private displayPart As Part = theSession.Parts.Display
Private lw As ListingWindow = theSession.ListingWindow
' Private bodyPart As Part = theSession.Parts.Display
' Private theComponent As Part = theSession.Parts.Display
Dim theComponent As Assemblies.Component = Nothing
#Region "Block Styler Dialog Designer generator code"
'------------------------------------------------------------------------------
'Constructor for NX Styler class
'------------------------------------------------------------------------------
Public Sub New()
'**************************************************************************************
'********************************This code added to original*********************************************
lw.Open()
' Dim theComponent As Assemblies.Component = Nothing
If SelectComponent("select a component", theComponent) = Selection.Response.Cancel Then
Return
End If
' lw.WriteLine("component display name: " & theComponent.DisplayName)
' lw.WriteLine("component part path: " & theComponent.Prototype.OwningPart.FullPath)
' Const testAttribute As String = "thickness"
'Dim thicknessAtt As NXObject.AttributeInformation = Nothing
'If theComponent.HasUserAttribute(testAttribute, NXObject.AttributeType.Any, -1) Then
' thicknessAtt = theComponent.GetUserAttribute(testAttribute, NXObject.AttributeType.Any, -1)
' lw.WriteLine("""" & testAttribute & """" & " attribute found")
' lw.WriteLine(" attribute value: " & thicknessAtt.StringValue)
'Else
' lw.WriteLine("component does NOT have an attribute named: " & testAttribute)
'End If
' lw.Close()
'**************************************************************************************
'**************************************************************************************
Try
theDlxFileName = "R:\hms_tools\NX11\Tooling\Journals\TAG-attributes\check-Attributes.dlx"
theDialog = theUI.CreateDialog(theDlxFileName)
theDialog.AddApplyHandler(AddressOf apply_cb)
theDialog.AddOkHandler(AddressOf ok_cb)
theDialog.AddUpdateHandler(AddressOf update_cb)
theDialog.AddInitializeHandler(AddressOf initialize_cb)
theDialog.AddDialogShownHandler(AddressOf dialogShown_cb)
Catch ex As Exception
'---- Enter your exception handling code here -----
Throw ex
End Try
End Sub
#End Region
'------------------------------- DIALOG LAUNCHING ---------------------------------
'
' Before invoking this application one needs to open any part/empty part in NX
' because of the behavior of the blocks.
'
' Make sure the dlx file is in one of the following locations:
' 1.) From where NX session is launched
' 2.) $UGII_USER_DIR/application
' 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
' recommended. This variable is set to a full directory path to a file
' containing a list of root directories for all custom applications.
' e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_ROOT_DIR\menus\custom_dirs.dat
'
' You can create the dialog using one of the following way:
'
' 1. Journal Replay
'
' 1) Replay this file through Tool->Journal->Play Menu.
'
' 2. USER EXIT
'
' 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
' 2) Invoke the Shared Library through File->Execute->NX Open menu.
'
'------------------------------------------------------------------------------
Public Shared Sub Main()
Dim thecheckAttributes As check_Attributes = Nothing
Try
If check_for_missing_display_part() = 0 Then
thecheckAttributes = New check_Attributes()
' The following method shows the dialog immediately
thecheckAttributes.Show()
End If
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
Finally
If thecheckAttributes IsNot Nothing Then
thecheckAttributes.Dispose()
thecheckAttributes = Nothing
End If
End Try
End Sub
'**************************************************************************************
'**************************************************************************************
Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
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_component_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
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
'------------------------------------------------------------------------------
' This method specifies how a shared image is unloaded from memory
' within NX. This method gives you the capability to unload an
' internal NX Open application or user exit from NX. Specify any
' one of the three constants as a return value to determine the type
' of unload to perform:
'
'
' Immediately : unload the library as soon as the automation program has completed
' Explicitly : unload the library from the "Unload Shared Image" dialog
' AtTermination : unload the library when the NX session terminates
'
'
' NOTE: A program which associates NX Open applications with the menubar
' MUST NOT use this option since it will UNLOAD your NX Open application image
' from the menubar.
'------------------------------------------------------------------------------
Public Shared Function GetUnloadOption(ByVal arg As String) As Integer
'Return CType(Session.LibraryUnloadOption.Explicitly, Integer)
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
' Return CType(Session.LibraryUnloadOption.AtTermination, Integer)
End Function
'------------------------------------------------------------------------------
' Following method cleanup any housekeeping chores that may be needed.
' This method is automatically called by NX.
'------------------------------------------------------------------------------
Public Shared Sub UnloadLibrary(ByVal arg As String)
Try
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'This method shows the dialog on the screen
'------------------------------------------------------------------------------
Public Sub Show()
Try
theDialog.Show()
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'Method Name: Dispose
'------------------------------------------------------------------------------
Public Sub Dispose()
If theDialog IsNot Nothing Then
theDialog.Dispose()
theDialog = Nothing
displayPart.Views.Refresh()
theSession.Parts.SetWork(workPart)
End If
End Sub
'------------------------------------------------------------------------------
'---------------------Block UI Styler Callback Functions--------------------------
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'Callback Name: initialize_cb
'------------------------------------------------------------------------------
Public Sub initialize_cb()
Try
groupAttr = CType(theDialog.TopBlock.FindBlock("groupAttr"), NXOpen.BlockStyler.Group)
SPOT_ID = CType(theDialog.TopBlock.FindBlock("SPOT_ID"), NXOpen.BlockStyler.StringBlock)
ZONE_STA_ROBOT = CType(theDialog.TopBlock.FindBlock("ZONE_STA_ROBOT"), NXOpen.BlockStyler.StringBlock)
BLANK4 = CType(theDialog.TopBlock.FindBlock("BLANK4"), NXOpen.BlockStyler.StringBlock)
BLANK3 = CType(theDialog.TopBlock.FindBlock("BLANK3"), NXOpen.BlockStyler.StringBlock)
BLANK2 = CType(theDialog.TopBlock.FindBlock("BLANK2"), NXOpen.BlockStyler.StringBlock)
BLANK1 = CType(theDialog.TopBlock.FindBlock("BLANK1"), NXOpen.BlockStyler.StringBlock)
theSession.Parts.SetWork(displayPart)
displayPart.Views.Refresh()
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'Callback Name: dialogShown_cb
'This callback is executed just before the dialog launch. Thus any value set
'here will take precedence and dialog will be launched showing that value.
'------------------------------------------------------------------------------
Public Sub dialogShown_cb()
Try
'---- Enter your callback code here -----
SPOT_ID.Value = readAttribute(workPart, "SPOT_ID")
If SPOT_ID.Value = "" Then SPOT_ID.Value = "---"
ZONE_STA_ROBOT.Value = readAttribute(workPart, "ZONE_STA_ROBOT")
If ZONE_STA_ROBOT.Value = "" Then ZONE_STA_ROBOT.Value = "---"
BLANK4.Value = readAttribute(workPart, "BLANK4")
If BLANK4.Value = "" Then BLANK4.Value = "---"
BLANK3.Value = readAttribute(workPart, "BLANK3")
If BLANK3.Value = "" Then BLANK3.Value = "---"
BLANK2.Value = readAttribute(workPart, "BLANK2")
If BLANK2.Value = "" Then BLANK2.Value = "---"
BLANK1.Value = readAttribute(workPart, "BLANK1")
If BLANK1.Value = "" Then BLANK1.Value = "---"
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
'------------------------------------------------------------------------------
'Callback Name: apply_cb
'------------------------------------------------------------------------------
Public Function apply_cb() As Integer
Dim errorCode As Integer = 0
Try
'---- Enter your callback code here -----
If SPOT_ID.Value.ToUpper = "---" Then SPOT_ID.Value = ""
If ZONE_STA_ROBOT.Value.ToUpper = "---" Then ZONE_STA_ROBOT.Value = ""
If BLANK4.Value.ToUpper = "---" Then BLANK4.Value = ""
If BLANK3.Value.ToUpper = "---" Then BLANK3.Value = ""
If BLANK2.Value.ToUpper = "---" Then BLANK2.Value = ""
If BLANK1.Value.ToUpper = "---" Then BLANK1.Value = ""
Dim theObjects(0) As NXObject
theObjects(0) = theComponent
createAttribute(workPart, theObjects, "SPOT_ID", SPOT_ID.Value)
createAttribute(workPart, theObjects, "ZONE_STA_ROBOT", ZONE_STA_ROBOT.Value)
createAttribute(workPart, theObjects, "BLANK4", BLANK4.Value)
createAttribute(workPart, theObjects, "BLANK3", BLANK3.Value)
createAttribute(workPart, theObjects, "BLANK2", BLANK2.Value)
createAttribute(workPart, theObjects, "BLANK1", BLANK1.Value)
Catch ex As Exception
'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = errorCode
End Function
'------------------------------------------------------------------------------
'Callback Name: update_cb
'------------------------------------------------------------------------------
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try
If block Is SPOT_ID Then
'---- Enter your code here -----
ElseIf block Is ZONE_STA_ROBOT Then
ElseIf block Is BLANK4 Then
'---- Enter your code here -----
ElseIf block Is BLANK3 Then
'---- Enter your code here -----
ElseIf block Is BLANK2 Then
'---- Enter your code here -----
ElseIf block Is BLANK1 Then
'---- Enter your code here -----
End If
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
update_cb = 0
End Function
'------------------------------------------------------------------------------
'Callback Name: ok_cb
'------------------------------------------------------------------------------
Public Function ok_cb() As Integer
Dim errorCode As Integer = 0
Try
'---- Enter your callback code here -----
errorCode = apply_cb()
Catch ex As Exception
'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
ok_cb = errorCode
End Function
'------------------------------------------------------------------------------
'Function Name: GetBlockProperties
'Returns the propertylist of the specified BlockID
'------------------------------------------------------------------------------
Public Function GetBlockProperties(ByVal blockID As String) As PropertyList
GetBlockProperties = Nothing
Try
GetBlockProperties = theDialog.GetBlockProperties(blockID)
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Check Attributes", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Function
Public Shared Function check_for_missing_display_part() As Integer
Dim dispPart As Part = Nothing
dispPart = Session.GetSession().Parts.Display
If dispPart Is Nothing Then
Dim style As MsgBoxStyle
Dim title As String = "Check for Displayed part"
style = MsgBoxStyle.Information
MsgBox("There is no displayed part ", style, title)
Return 1
Else
Return 0
End If
End Function
Private Function readAttribute(ByVal selPart As Part, ByVal attrName As String) As String
Dim attrValue As String = Nothing
Dim iRes As Integer
Dim attrInfor As NXOpen.NXObject.AttributeInformation = Nothing
Dim attrtype As NXOpen.NXObject.AttributeType = NXObject.AttributeType.String
theUFSession.Attr.FindAttribute(selPart.Tag, 5, attrName, iRes)
If iRes <> 0 Then
attrInfor = selPart.GetUserAttribute(attrName, attrtype, 2)
attrValue = attrInfor.StringValue
Else
attrValue = "---"
End If
Return attrValue
End Function
'------------------------------------------------------------------------------
'User Functions
'------------------------------------------------------------------------------
Private Sub createAttribute(ByVal thisPart As Part, ByVal theObjects() As NXObject, ByVal attrTitle As String, ByVal attrValue As String, Optional attrCategory As String = "")
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder = theSession.AttributeManager.CreateAttributePropertiesBuilder(thisPart, theObjects, AttributePropertiesBuilder.OperationType.Create)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.Category = attrCategory
attributePropertiesBuilder1.Title = attrTitle
attributePropertiesBuilder1.StringValue = attrValue
attributePropertiesBuilder1.Commit()
attributePropertiesBuilder1.Destroy()
End Sub
End Class