Auto title block from file path
Auto title block from file path
(OP)
Hi!
I would like to extract information from file path into my drawings using title blocks. It seems to me in an other thread (http://www.eng-tips.com/viewthread.cfm?qid=364026) this problem was already discussed, and even two journals were written to solve it. I did run both journals but for some reason I could not find the attributes that these journals was supposed to create.
What am I doing worng? Could you please help me out? I even tried to create the same directory tree to make the journals work.
Thanks in advance! :)
P.s.: sorry for creating a new thread but I was not able to post in the old one.
I would like to extract information from file path into my drawings using title blocks. It seems to me in an other thread (http://www.eng-tips.com/viewthread.cfm?qid=364026) this problem was already discussed, and even two journals were written to solve it. I did run both journals but for some reason I could not find the attributes that these journals was supposed to create.
What am I doing worng? Could you please help me out? I even tried to create the same directory tree to make the journals work.
Thanks in advance! :)
P.s.: sorry for creating a new thread but I was not able to post in the old one.





RE: Auto title block from file path
Can you give an example of the file path and what information you want to pull out of it? It does not have to be a real file path, it can be "fabricated" to keep your information private, as long as the overall structure is representative of the real deal. Also, what version of NX are you using?
www.nxjournaling.com
RE: Auto title block from file path
Yes, I can. We have a dedicated drive for our projects which looks like this:
d:\3452.ProjectDescription\techno\45321.PartDescription\45321_PartRevision_PartDescription.prt
In the example above 3452 is the project ID and 45321 is the part ID. I was able to get the part ID using the ug_askCurrentWorkPart() and substring() functions. Now I would like to make an automatic title block for the project ID too, but I was not able to figure it out.
We use NX6.
RE: Auto title block from file path
Rather than using a hard coded string value, you would be working with the part.FullPath property.
CODE
Option Strict Off Imports System Imports NXOpen Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() If IsNothing(theSession.Parts.BaseWork) Then 'active part required Return End If Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim filePath As String = "D:\3452.ProjectDescription\techno\45321.PartDescription\45321_PartRevision_PartDescription.prt" 'split the file path into parts Dim pathParts() As String = filePath.Split("\") 'split the project directory name Dim projectParts() As String = pathParts(1).Split(".") 'lw.WriteLine("filePath: " & filePath) 'For Each temp As String In pathParts ' lw.WriteLine(temp) 'Next lw.WriteLine("project number: " & projectParts(0)) lw.WriteLine("project description: " & projectParts(1)) lw.Close() End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End Modulewww.nxjournaling.com
RE: Auto title block from file path
I was able to use the FullPath property and I also realized we use underscore instead of dot to separate project ID from project description, so I modified the code to split at underscores. But I still could not find a way to create an attribute from the project ID or the filepath. I tried to record my own expression creation to work it out but I got stuck there.
Could you please give me some advice how to do it?
CODE --> VB
Option Strict Off Imports System Imports NXOpen Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() If IsNothing(theSession.Parts.BaseWork) Then 'active part required Return End If Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim filePath As String = theSession.Parts.Work.FullPath 'split the file path into parts Dim pathParts() As String = filePath.Split("\") 'split the project directory name Dim projectParts() As String = pathParts(1).Split("_") Dim expression999 As Expression expression999 = workPart.Expressions.CreateExpression("String", "filepath999=filePath") lw.WriteLine("filePath: " & filePath) 'For Each temp As String In pathParts ' lw.WriteLine(temp) 'Next lw.WriteLine("project number: " & projectParts(0)) lw.WriteLine("project description: " & projectParts(1)) lw.Close() End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleRE: Auto title block from file path
www.nxjournaling.com
RE: Auto title block from file path
CODE --> VB
Option Strict Off Imports System Imports NXOpen Module NXJournal Sub Main Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display ' ---------------------------------------------- ' Menu: Tools->Expression... ' ---------------------------------------------- ' ---------------------------------------------- ' Dialog Begin Insert Function ' ---------------------------------------------- ' ---------------------------------------------- ' Dialog Begin Function Arguments ' ---------------------------------------------- Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression") Dim expression1 As Expression expression1 = workPart.Expressions.CreateExpression("String", "test=dateTimeString()") Dim markId2 As Session.UndoMarkId markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Update Expression Data") Dim nErrs1 As Integer nErrs1 = theSession.UpdateManager.DoUpdate(markId2) theSession.DeleteUndoMark(markId2, "Update Expression Data") ' ---------------------------------------------- ' Menu: Tools->Journal->Stop Recording ' ---------------------------------------------- End Sub End ModuleThen I copied the relevant lines, modified them a little bit to point to projectPart() and inserted to the "main" journal.
CODE --> VB
Option Strict Off Imports System Imports NXOpen Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() If IsNothing(theSession.Parts.BaseWork) Then 'active part required Return End If Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim filePath As String = theSession.Parts.Work.FullPath 'split the file path into parts Dim pathParts() As String = filePath.Split("\") 'split the project directory name Dim projectParts() As String = pathParts(1).Split("_") Dim expression1 As Expression expression1 = workPart.Expressions.CreateExpression("String", "test2=projectParts(0)") lw.WriteLine("filePath: " & filePath) 'For Each temp As String In pathParts ' lw.WriteLine(temp) 'Next lw.WriteLine("project number: " & projectParts(0)) lw.WriteLine("project description: " & projectParts(1)) lw.Close() End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleI ran the journal, and I came up with a syntax error. I don't know what I am doing wrong and sorry if I'm testing your patience with my thick head. (:
RE: Auto title block from file path
www.nxjournaling.com
RE: Auto title block from file path
I found a great article about creating expressions here:
http://www.nxjournaling.com/content/expressions-cr...
I had to modify the syntax a little bit. Now here is the working code:
CODE --> VB
Option Strict Off Imports System Imports NXOpen Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() If IsNothing(theSession.Parts.BaseWork) Then 'active part required Return End If Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim filePath As String = theSession.Parts.Work.FullPath 'split the file path into parts Dim pathParts() As String = filePath.Split("\") 'split the project directory name Dim projectParts() As String = pathParts(1).Split("_") Dim ProjectNumber As Expression = Nothing Dim ProjectNumberValue As String = projectParts(0) ProjectNumber = workPart.Expressions.CreateExpression("String","ProjectNumber=" & """" & ProjectNumberValue & """") lw.WriteLine("filePath: " & filePath) 'For Each temp As String In pathParts ' lw.WriteLine(temp) 'Next lw.WriteLine("project number: " & projectParts(0)) lw.WriteLine("project description: " & projectParts(1)) lw.Close() End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image immediately after execution within NX GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End ModuleAnd it works! This is amazing! Thank you for your help. :)
The next thing is going be the error handling and autorun.
RE: Auto title block from file path
Glad that you got it working.
www.nxjournaling.com