To create forms for use in UG it's easier if you have Visual Studio .Net.
Otherwise you are going to have to try and figure out how to create the form in text from examples in a text editor. I started it off this way and it's not easy and to make it worse it's really slow to write.
I have an example that has an input box for each stage of inputing text into attributes. It's not as slick but it is far simpler to understand. It has at least the correct commands for calling and setting attributes in a journal.
-----START-----
Option Strict Off
Imports System
Imports NXOpen
Imports System.Windows.Forms
Imports NXOpenUI
Module NXJournal
Sub Main
Dim PartNo As string
Dim stringlen As integer
Dim DrgNo As String
Dim PrevNo As string
Dim PrevPartNo As String
Dim Check As String
Dim Cur_Desc As String
Dim theSession As Session = Session.GetSession()
Dim Attrer As Integer
Dim cur_Prev_No As String
Dim cur_Part_Desc As String
Dim cur_Created As String
Dim cur_Owner As String
Dim Part_Name As String
Dim Part_Desc As String
Dim Owner As String
Dim Created As String
Dim DWG_No As String
Dim Prev_No As String
' ----------------------------------------------
' Check Attributes exist and get Strings
' ----------------------------------------------
Try
PrevNo = thesession.Parts.Work.GetStringAttribute("DB_DWG_NO")
Catch exc As NXException
PrevNo = "XXXXX-XX"
Attrer = 1
End Try
Try
PrevPartNo = thesession.Parts.Work.GetStringAttribute("DB_PART_NAME")
Catch exc As NXException
PrevPartNo = "XXXXX-XX"
Attrer = 1
End Try
' ----------------------------------------------
' Save As... Dialog to enter new part name/number
' ----------------------------------------------
Dim part1 As Part
Dim partSaveStatus1 As PartSaveStatus
Dim saveDialog As New SaveFileDialog
saveDialog.Filter = "NX part files (*.prt)|*.prt|All files (*.*)|*.*"
saveDialog.FilterIndex = 1
saveDialog.RestoreDirectory = True
If saveDialog.ShowDialog() = DialogResult.OK Then
Try
part1 = theSession.Parts.Work.SaveAs(saveDialog.FileName,partSaveStatus1)
Catch exc As NXException
goto Part_Exists
End Try
partSaveStatus1.Dispose()
goto partent
End If
'MessageBox.Show("User Cancelled Operation")
goto end_prog
' ----------------------------------------------
' Manipulate saveDialog.FileName to extract Drg Number and Part Number
' ----------------------------------------------
partent:
Dim i As integer= saveDialog.FileName.LastIndexOf("\") ' position of the last "\"
Dim filename As String = saveDialog.FileName.Substring(i+1)
filename = filename.ToUpper()
'msgbox(filename)
If filename.IndexOf("PD") >= 0 Then
stringlen = filename.Length()
DrgNo = filename.Substring(0,stringlen-4)
'msgbox("PD"& drgno)
PartNo = DrgNo.Substring(0,8)
'msgbox("PD"& partno)
goto PDend
End If
stringlen = filename.Length()
DrgNo = filename.Substring(0,stringlen-4)
'msgbox("No PD"& drgno)
PartNo =DrgNo.Substring(0,5)
'msgbox("No PD"& partno)
PDend:
' ----------------------------------------------
' Copy Drg Number to Prev Number
' ----------------------------------------------
'MsgBox(prevpartno)
If Partno = PrevPartNo Then
If PrevNo.IndexOf("PD") >= 0 Then
theSession.Parts.Work.SetAttribute("DB_PREV_NO", PrevNo)
Goto stepover
End If
If DrgNo.IndexOf("A") >= 1 Then
theSession.Parts.Work.SetAttribute("DB_PREV_NO", PrevNo)
Goto stepover
End If
Goto stepover
End If
theSession.Parts.Work.SetAttribute("DB_PREV_NO", PrevNo)
stepover:
' ----------------------------------------------
' New Description prompt
' ----------------------------------------------
Try
Cur_Desc = thesession.Parts.Work.GetStringAttribute("DB_PART_DESC")
Catch exc As NXException
Cur_Desc = ""
Attrer = 1
End Try
dim Desc = NXInputBox.GetInputString("Enter part Description", "Description",Cur_Desc)
Desc = desc.ToUpper()
' ----------------------------------------------
' Update Attributes
' ----------------------------------------------
Dim session_UndoMarkId1 As Session.UndoMarkId
session_UndoMarkId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Assign Attributes")
theSession.Parts.Work.SetAttribute("DB_PART_NAME", PartNo)
theSession.Parts.Work.SetAttribute("DB_DWG_NO", DrgNo)
theSession.Parts.Work.SetAttribute("DB_PART_DESC", Desc)
' ----------------------------------------------
' Check for missing Attributes and set nulls
' ----------------------------------------------
if attrer = 1 then
MessageBox.Show("Overall 'Save As' Operation Succesfull"& Environment.NewLine() & "1 or More Attributes Not Found!" & Environment.NewLine() & "This is likely to be an old part that needs updating.")
Part_Name = NXInputBox.GetInputString("Enter Part Number", "DRAWING NUMBER",PartNo)
Part_Name = Part_Name.ToUpper()
theSession.Parts.Work.SetAttribute("DB_PART_NAME", Part_Name)
DWG_No = NXInputBox.GetInputString("Enter CAD Drawing Number", "CAD DRG No",DrgNo)
DWG_No = DWG_No.ToUpper()
theSession.Parts.Work.SetAttribute("DB_DWG_No", DWG_No)
Try
cur_Prev_No = thesession.Parts.Work.GetStringAttribute("DB_PREV_NO")
Catch exc As NXException
Prev_No = NXInputBox.GetInputString("Enter Previous Drawing Number", "PREVIOUS DRG No","XXXXX_XX")
Prev_No = Prev_No.ToUpper()
theSession.Parts.Work.SetAttribute("DB_PREV_NO", Prev_No)
goto PART_DESC
End Try
Prev_No = NXInputBox.GetInputString("Enter Previous Drawing Number", "PREVIOUS DRG No","cur_Prev_No")
Prev_No = Prev_No.ToUpper()
theSession.Parts.Work.SetAttribute("DB_PREV_NO", Prev_No)
PART_DESC:
Try
cur_Part_Desc = thesession.Parts.Work.GetStringAttribute("DB_PART_DESC")
Catch exc As NXException
Part_Desc = NXInputBox.GetInputString("Enter Part Description", "TITLE","Enter Title Here")
Part_Desc = Part_Desc.ToUpper()
theSession.Parts.Work.SetAttribute("DB_PART_DESC", Part_Desc)
goto CREATED
End Try
Part_Desc = NXInputBox.GetInputString("Enter Part Description", "TITLE",cur_Part_Desc)
Part_Desc = Part_Desc.ToUpper()
theSession.Parts.Work.SetAttribute("DB_PART_DESC", Part_Desc)
CREATED:
Try
cur_Created = thesession.Parts.Work.GetStringAttribute("CREATED")
Catch exc As NXException
Created = NXInputBox.GetInputString("Enter Creation Date", "Date Of 1st ISSUE","Enter Date Here dd/mm/yy")
Created = Created.ToUpper()
theSession.Parts.Work.SetAttribute("CREATED", Created)
goto OWNER
End Try
Created = NXInputBox.GetInputString("Enter Creation Date", "Date Of 1st ISSUE",cur_Created)
Created = Created.ToUpper()
theSession.Parts.Work.SetAttribute("CREATED", Created)
OWNER:
Try
cur_Owner = thesession.Parts.Work.GetStringAttribute("OWNER")
Catch exc As NXException
Owner = NXInputBox.GetInputString("Enter Drawn By", "DRAWN","Enter Drawn By Here")
Owner = Owner.ToUpper()
theSession.Parts.Work.SetAttribute("OWNER", Owner)
goto LAYERS
End Try
Owner = NXInputBox.GetInputString("Enter Drawn By", "DRAWN",cur_Owner)
Owner = Owner.ToUpper()
theSession.Parts.Work.SetAttribute("OWNER", Owner)
end if
' ----------------------------------------------
' Save the part to catch attribute/Layer mods
' ----------------------------------------------
theSession.Parts.Work.Save(Part.SaveComponents.True, Part.CloseAfterSave.False, partSaveStatus1)
partSaveStatus1.Dispose()
goto end_prog
' ----------------------------------------------
' Errors
' ----------------------------------------------
No_Attr:
MessageBox.Show("1 or More Attributes Not Found!")
goto end_prog:
Part_Exists:
MessageBox.Show("Error Saving Part!")
goto end_prog:
' ----------------------------------------------
' End
' ----------------------------------------------
end_prog:
End Sub
End Module
----END----
Mark Benson
Aerodynamic Model Designer