blockstyler_dll

help....i want to prepare dll file from .dlx or how to run blockstyler from vb.

thanks.

==============================================================================
' WARNING!! This file is overwritten by the Block Styler while generating
' the automation code. Any modifications to this file will be lost after
' generating the code again.
'
' Filename: C:\Users\santosh\Desktop\blockstyler.vb
'
' This file was generated by the NX Block Styler
' Created by: santosh
' Version: NX 6
' Date: 05-04-2013 (Format: mm-dd-yyyy)
' Time: 22:20 (Format: hh-mm)
'
'==============================================================================

'==============================================================================
' 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 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.BlockStyler

'------------------------------------------------------------------------------
'Represents Block Styler application class
'------------------------------------------------------------------------------
Public Class blockstyler
'class members
Private Shared theSession As Session
Private Shared theUI As UI
Public Shared theblockstyler As blockstyler
Private theDialogName As String
Private theDialog As NXOpen.BlockStyler.BlockDialog
Private group0 As NXOpen.BlockStyler.UIBlock' Block type: Group
Private nativeFileBrowser0 As NXOpen.BlockStyler.UIBlock' Block type: NativeFileBrowser

#Region "Block Styler Dialog Designer generator code"
'------------------------------------------------------------------------------
'Constructor for NX Styler class
'------------------------------------------------------------------------------
Public Sub New()
Try

theSession = Session.GetSession()
theUI = UI.GetUI()
theDialogName = "blockstyler.dlx"
theDialog = theUI.CreateDialog(theDialogName)
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\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 Styler programmer's guide"
' 2) Invoke the Shared Library through File->Execute->NX Open menu.
'
'------------------------------------------------------------------------------
Public Shared Sub Main()
Try

theblockstyler = New blockstyler()
' The following method shows the dialog immediately
theblockstyler.Show()

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
Finally
theblockstyler.Dispose()
End Try
End Sub
'------------------------------------------------------------------------------
' 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 Function UnloadLibrary(ByVal arg As String) As Integer
Try

Return 0

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Function

'------------------------------------------------------------------------------
'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("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'------------------------------------------------------------------------------
'Method Name: Dispose
'------------------------------------------------------------------------------
Public Sub Dispose()
If theDialog IsNot Nothing Then
theDialog.Dispose()
theDialog = Nothing
End If
End Sub

'------------------------------------------------------------------------------
'---------------------Block Styler Callback Functions--------------------------
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'Callback Name: initialize_cb
'------------------------------------------------------------------------------
Public Sub initialize_cb()
Try

group0 = theDialog.TopBlock.FindBlock("group0")
nativeFileBrowser0 = theDialog.TopBlock.FindBlock("nativeFileBrowser0")

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", 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 -----

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'------------------------------------------------------------------------------
'Callback Name: apply_cb
'------------------------------------------------------------------------------
Public Function apply_cb() As Integer
Try

'---- Enter your callback code here -----

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = 0
End Function

'------------------------------------------------------------------------------
'Callback Name: update_cb
'------------------------------------------------------------------------------
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try

If block Is nativeFileBrowser0 Then
'---- Enter your code here -----

End If

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
update_cb = 0
End Function

'------------------------------------------------------------------------------
'Callback Name: ok_cb
'------------------------------------------------------------------------------
Public Function ok_cb() As Integer
Try

'---- Enter your callback code here -----
apply_cb()

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
ok_cb = 0
End Function

End Class

I do not have a blockstyler license to play with, so unfortunately, I cannot answer your question. I'd suggest asking at the GTAC support forum (specifically, the NX Languages subforum).

https://bbs.industrysoftware.automation.siemens.com/vbulletin/forumdispl...

Hi,

In this line
theDialogName = "blockstyler.dlx"
You need to replace "blockstyler.dlx" with the full file path to your .dlx file. You can then run the vb code as a jorunal like normal.

Cheers,

David

Hi all,

I am trying to use the block styler button to execute a .dll file (run a program that changes color randomly). All the other buttons are used for assigning specific color to the body using the codes withing the function. Only with the button named 'randomcolor', I was trying to run an external .dll file located under 'fullpath. but it is showing me error saying:

"Exception whle invoking method in managed code
File name: \\ .... \randomcolor.dll
Function name: Main "

Same .dll file is working with other .vb journal but not from a button click of block styler.
Can anyone help me with the situation please.


Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim theUI As UI = UI.GetUI()

Dim displayModification1 As DisplayModification
Dim objects1(0) As DisplayableObject

Dim MatColor As Integer

Dim fullpath As String = "C:\mv_design\MV_Design_Eng\CAD_Backup\5_NX_Files\TOOLBARS\Dlls\randomcolor.dll"
Dim inObject() As Object = {}
Dim dllname As String
theSession.Execute(fullpath, dllname, "Main", inObject)

Try

If block Is randomcolor Then
' MatColor = 40
' dllname = "randomcolor"

ElseIf block Is coverplate Then
MatColor = 41

ElseIf block Is sidesheetlh Then
MatColor = 140

ElseIf block Is sidesheetrh Then
MatColor = 60

ElseIf block Is toppan Then
MatColor = 165

ElseIf block Is bottompan Then
MatColor = 114

ElseIf block Is mtgbrkt Then
MatColor = 146

ElseIf block Is epoxysil Then
MatColor = 1

ElseIf block Is epoxytin Then
MatColor = 1

ElseIf block Is hssil Then
MatColor = 1

ElseIf block Is hstin Then
MatColor = 1

End If

For Each tempBody As Body In workPart.Bodies
displayModification1 = theSession.DisplayManager.NewDisplayModification()
displayModification1.ApplyToAllFaces = True
displayModification1.ApplyToOwningParts = False
displayModification1.NewColor = MatColor
objects1(0) = tempBody
displayModification1.Apply(objects1)
displayModification1.Dispose()
Next

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try

update_cb = 0
End Function

Regards,
MFJ

I haven't tried running a dll from bstyler myself, but could it be something to do with the fact that when you call theSession.Execute, you haven't yet initialised dllame and inObject is an empty array?