Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Collections.Generic
Imports System.Windows.Forms
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim theUFSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Public lw As ListingWindow = theSession.ListingWindow
Public Unit_1 As Integer
Public Unit_2 As Integer
Public Sub Main(ByVal args As String())
Dim myForm1 As New Form1
'lw.open()
'lw.writeline("")
Unit_1 = theSession.Parts.Display.UnitCollection.GetDefaultDataEntryUnits()
Unit_2 = theSession.Parts.Display.UnitCollection.GetDefaultObjectInformationUnits()
myform1.Unit_1 = Unit_1
myform1.Unit_2 = Unit_2
myForm1.ShowDialog()
If myForm1.Canceled Then
'Exit sub
Return
Else
End If
Unit_1 = myform1.Unit_1
Unit_2 = myform1.Unit_2
theSession.Parts.Display.UnitCollection.SetDefaultDataEntryUnits(Unit_1)
theSession.Parts.Display.UnitCollection.SetDefaultObjectInformationUnits(Unit_2)
'lw.close()
End Sub
Public Function GetUnloadOption(ByVal arg As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
End Module
'----------------------------------------------------------------------------------------------------------------
' FORM1
'----------------------------------------------------------------------------------------------------------------
Public Class Form1
Public Unit_1 As Integer
Public Unit_2 As Integer
Public Units as String
Public X as integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each c As Control In Controls
AddHandler c.MouseClick, AddressOf ClickHandler
Next
if unit_2 = 0 then
Units = "lbm/in/lbf/deg/F"
elseif Unit_2 = 1 then
Units = "lbm/ft/lbf/deg/F"
elseif Unit_2 = 2 then
Units = "g/mm/N/deg/C"
elseif Unit_2 = 3 then
Units = "g/cm/N/deg/C"
elseif Unit_2 = 4 then
Units = "kg/m/N/rad/K"
elseif Unit_2 = 5 then
Units = "kg/mm/N/deg/C"
end if
'LbmInLbfDegF Usual choice for inch parts. - 0
'LbmFtLbfDegF Not supported for data entry units - 1
'GMmNDegC Not supported for data entry units - 2
'GCmNDegC Not supported for data entry units - 3
'KgMNRadK SI compatibility - 4
'KgMmNDegC Usual choice for mm parts - 5
Label4.Text = Units
ComboBox3.Visible = false
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.Text = vbNullString Then
_canceled = True
Me.Close()
End If
If ComboBox2.Text = vbNullString Then
_canceled = True
Me.Close()
End If
if x = 1 then
Units = ComboBox2.text
elseif x = 2 then
Units = ComboBox3.text
End if
if Units = "lbm/in/lbf/deg/F" then
Unit_1 = 0
Unit_2 = 0
elseif Units = "lbm/ft/lbf/deg/F" then
Unit_1 = 0
Unit_2 = 1
elseif Units = "g/mm/N/deg/C" then
Unit_1 = 5
Unit_2 = 2
elseif Units = "g/cm/N/deg/C" then
Unit_1 = 5
Unit_2 = 3
elseif Units = "kg/m/N/rad/K" then
Unit_1 = 5
Unit_2 = 4
elseif Units = "kg/mm/N/deg/C" then
Unit_1 = 5
Unit_2 = 5
end if
Me.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim intSelectedIndex As Integer
intSelectedIndex = ComboBox1.SelectedIndex
Dim objSelectedItem As Object
objSelectedItem = ComboBox1.SelectedItem
if intSelectedIndex = 0 then
ComboBox2.Visible = true
ComboBox3.Visible = false
x = 1
else
ComboBox2.Visible = false
ComboBox3.Visible = true
x = 2
end if
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Dim intSelectedIndex2 As Integer
intSelectedIndex2 = ComboBox2.SelectedIndex
Dim objSelectedItem2 As Object
objSelectedItem2 = ComboBox2.SelectedItem
End Sub
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
Dim intSelectedIndex3 As Integer
intSelectedIndex3 = ComboBox2.SelectedIndex
Dim objSelectedItem3 As Object
objSelectedItem3 = ComboBox3.SelectedItem
End Sub
Private _canceled As Boolean = False
Public ReadOnly Property Canceled() As Boolean
Get
Return _canceled
End Get
End Property
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
_canceled = True
Me.Close()
End Sub
' Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
' _canceled = True
' me.close()
' End Sub
Private Sub ClickHandler(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
'Label1.Text = String.Format("{0}", e.Button.ToString.ToLower)
if e.Button = MouseButtons.Middle then
'Label2.Text = "Middle"
SendKeys.Send("{ENTER}")
end if
End Sub
End Class
'----------------------------------------------------------------------------------------------------------------
' FORM1 - IKONY
'----------------------------------------------------------------------------------------------------------------
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim param As System.Windows.Forms.CreateParams = MyBase.CreateParams
param.ClassStyle = param.ClassStyle Or &H200
Return param
End Get
End Property
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.ComboBox1 = New System.Windows.Forms.ComboBox()
Me.ComboBox2 = New System.Windows.Forms.ComboBox()
Me.ComboBox3 = New System.Windows.Forms.ComboBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(16, 13)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(78, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Units in part:"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(16, 45)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(65, 16)
Me.Label2.TabIndex = 0
Me.Label2.Text = "Choose template:"
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(16, 77)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(61, 16)
Me.Label3.TabIndex = 0
Me.Label3.Text = "Choose units:"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(130, 13)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(86, 16)
Me.Label4.TabIndex = 0
Me.Label4.Text = ""
'
'ComboBox1
'
Me.ComboBox1.FormattingEnabled = True
Me.ComboBox1.Items.AddRange(New Object() {"Metric", "Imperial"})
Me.ComboBox1.Location = New System.Drawing.Point(134, 38)
Me.ComboBox1.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(231, 24)
Me.ComboBox1.TabIndex = 1
Me.ComboBox1.Text = "Metric"
'
'ComboBox2
'
Me.ComboBox2.FormattingEnabled = True
Me.ComboBox2.Items.AddRange(New Object() {"g/mm/N/deg/C", "g/cm/N/deg/C", "kg/m/N/rad/K", "kg/mm/N/deg/C"})
Me.ComboBox2.Location = New System.Drawing.Point(134, 69)
Me.ComboBox2.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.ComboBox2.Name = "ComboBox2"
Me.ComboBox2.Size = New System.Drawing.Size(231, 24)
Me.ComboBox2.TabIndex = 2
Me.ComboBox2.Text = "g/mm/N/deg/C"
'
'ComboBox3
'
Me.ComboBox3.FormattingEnabled = True
Me.ComboBox3.Items.AddRange(New Object() {"lbm/in/lbf/deg/F", "lbm/ft/lbf/deg/F"})
Me.ComboBox3.Location = New System.Drawing.Point(134, 69)
Me.ComboBox3.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.ComboBox3.Name = "ComboBox3"
Me.ComboBox3.Size = New System.Drawing.Size(231, 24)
Me.ComboBox3.TabIndex = 2
Me.ComboBox3.Text = "lbm/in/lbf/deg/F"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(54, 110)
Me.Button1.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(103, 32)
Me.Button1.TabIndex = 3
Me.Button1.Text = "Ok"
Me.Button1.UseVisualStyleBackColor = True
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(222, 110)
Me.Button2.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(103, 32)
Me.Button2.TabIndex = 4
Me.Button2.Text = "Cancel"
Me.Button2.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(377, 280)
'Me.ControlBox = False
Me.ControlBox = True
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.ComboBox3)
Me.Controls.Add(Me.ComboBox2)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.AcceptButton = Button1
Me.CancelButton = Button2
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(238, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable
Me.MaximumSize = New System.Drawing.Size(393, 200)
Me.MinimumSize = New System.Drawing.Size(393, 200)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Part units change"
me.KeyPreview = true
me.cancelbutton = Button2
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
Friend WithEvents ComboBox3 As System.Windows.Forms.ComboBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip
End Class