Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding attributes to a file using journaling?

Status
Not open for further replies.

DieMan44

Mechanical
Sep 16, 2004
183
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.
 
Replies continue below

Recommended for you

Thanks John, however it is not quite what I was looking for.
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.
 
I created my own start part ( or you could edit a default one) i added all the attributes i wanted into it, so every part has them ready to be filled in.
I altered the .pax file to include it and even have our company logo as a display preview for the template part
 
What I was trying to create was a GUI that asked for the detail information from the designer that could be activated by a custom button. Maybe even activating when saving, so the file could not be saved unless the fields where filled in. Or maybe something similar to G.M.'s file checker program. Then when the detailer opens the model, activates a drawing templete, all the fields get filled out. Moog2's method would work fine, I guess I want something more fancy.
 
Here's a thought. You can copy all the attributes from one file and paste them into another. So to address your question with the final result in mind I find that it is not very hard to edit attributes, and I find that most of the changes to the attributes that I make from one file to the next are repetitive and minor. So the way I go is to copy and paste from the most similar other file that I have open and then edit by exception. I get what you want to do and I'm kind of guessing why here. So from my experience we haven't bothered customizing any further, because if you know that copying the bulk of the information can be used as a shortcut then you can get 90% of it done just using NX out of the box, so to speak.

Best Regards

Hudson
 
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
 
Marc, when I cut/paste this into my journal editor it cmoes back with Line 193: Label 'LAYERS' is not defined.

What are your intentions with Layer?

Justin Ackley
Designer
 
Sorry,

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
 
I think its a great start for me. I do appreciate it.

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
 
If you put the attribute name in the area of the title block that you want to have filled, it should work fine. I still have more changes to make to the original program, I'll let you know how it goes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor