Adding attributes to a file using journaling?
Adding attributes to a file using journaling?
(OP)
I have figured out how to get the filename and date to automaticly fill in on a title block. I even created a button to run the journal file to to this. However, the next challange I am trying to attempt is creating a user interface activated by a self created button to add all the atributes to a part file. Basicly what I want is to click the button, have a gui pop up where I can input things like detail number, material type, stock size, etc. This would be the last step before completing the modlel of the detail. Then, when I use the master model method to create the detail drawing, which would be already formated, these atributes would get filled into the title block. May have to make another button to get it to update, but that's no big deal. Any suggestions on how to write this? FYI, I have no real experence in doing things like this other than what I have done above, which was a file I edited.





RE: Adding attributes to a file using journaling?
John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA
http://www.siemens.com/plm
http://www.plmworld.org/museum/
RE: Adding attributes to a file using journaling?
John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA
http://www.siemens.com/plm
http://www.plmworld.org/museum/
RE: Adding attributes to a file using journaling?
I don't have the licence to compile grip programs, and I would like something customized to our needs. Plus that looks like it is more for drawings, and I want the atributes to be part of the model since we have one person designing and another detailing. I'm going to try to work on the VB journal program, I got it part way there, just need to figure out what is causing the errors. Thanks again.
RE: Adding attributes to a file using journaling?
John R. Baker, P.E.
Product 'Evangelist'
NX Design
Siemens PLM Software Inc.
Cypress, CA
http://www.siemens.com/plm
http://www.plmworld.org/museum/
RE: Adding attributes to a file using journaling?
I altered the .pax file to include it and even have our company logo as a display preview for the template part
RE: Adding attributes to a file using journaling?
RE: Adding attributes to a file using journaling?
Best Regards
Hudson
RE: Adding attributes to a file using journaling?
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
RE: Adding attributes to a file using journaling?
What are your intentions with Layer?
Justin Ackley
Designer
RE: Adding attributes to a file using journaling?
This is a cut and paste job of a much larger journal.
Copy this line without the quotes
"Layers:"
just before
' ----------------------------------------------
' Save the part to catch attribute/Layer mods
' ----------------------------------------------
I think that should sort it.
It's not the most elegant but it gives you an idea of manipulating attributes and using the custom input box.
Mark Benson
Aerodynamic Model Designer
RE: Adding attributes to a file using journaling?
The problem I see is associating these attributes back to the drawing.
Did you have any training on this or are you teaching yourself by trial and error?
Justin Ackley
Designer
RE: Adding attributes to a file using journaling?