Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

unigraphics file path 2

Status
Not open for further replies.

mgoble

Mechanical
Apr 14, 2014
9
I was wondering if there is any way wo bring the full file path of the location of a ug part file into expressions. I know you can bring the file name into expressions. We have a very defined file structure that has the customer and the project description in our folder system. I am trying to completely automate out title blocks.

I currently have the file, the drawing number, the assembly file, the part description, the creation date, the drawing scale, and the sheet number.

I would like to get the customer and the project description, and possibly the person that designed the part. I know if I can get the file path I can extract the customer and the description from that. Is there any way of doing this?

Also is there any way of bringing in the person that designed the part. I know Unigraphics stores this in the part history.

Any suggestions?

thank you,

Mike
 
Replies continue below

Recommended for you

I suspect that the only way to do that would be with some sort of NX Open program.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
GRIP has a routine to return the full path name.


"Wildfires are dangerous, hard to control, and economically catastrophic."

Ben Loosli
 
Yes, GRIP can extract the full path name, but the only way to put that information into a Expression would be if it were a 'String' Expression. Unfortunately, 'String' Expressions are not supported by GRIP (they came along only recently, long after GRIP went into 'maintenance only' status). Now it might be possible to create a dummy 'string' expression ahead of time and GRIP might be able to replace the current value with a new value but I've never tried it. This is why I recommended NX Open as it would be able to handle 'string' expressions.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.
 
To my memory, you should search this site, i remember similar threads over time , where some nice person posted some code.
( No i am not that person, i am a noob on programming :)

Regards,
Tomas
 
Is this what you are trying to do?

Code:
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen 
Imports NXOpen.UF  
 

 

Module NXJurnal

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Sub Main

workPart.SetAttribute("File_Path", GetFilePath())

workPart.SetAttribute("File_Name", GetFileName())

End Sub
	
	
	
'***********************************************************************

Function GetFileName()
	Dim strPath as String
	Dim strPart as String
	Dim pos as Integer
	
	'get the full file path
	strPath = displayPart.fullpath
	'get the part file name
	pos = InStrRev(strPath, "\")
	strPart = Mid(strPath, pos + 1)
	
	strPath = Left(strPath, pos)
	'strip off the ".prt" extension
	strPart = Left(strPart, Len(strPart) - 4)
	
	GetFileName = strPart
End Function
'***********************************************************************

Function GetFilePath()
	Dim strPath as String
	Dim strPart as String
	Dim pos as Integer
	
	'get the full file path
	strPath = displayPart.fullpath
	'get the part file name
	pos = InStrRev(strPath, "\")
	strPart = Mid(strPath, pos + 1)
	
	strPath = Left(strPath, pos)
	'strip off the ".prt" extension
	strPart = Left(strPart, Len(strPart) - 4)
	
	GetFilePath = strPath
End Function


	
	
End Module
 
Ok I have not done anything with grip or ugopen to this point. Do you need a special lizcens in order to do the ugopen programing? it does look like this is what I was looking for though. Will this update when I import this into another file? or open it with a template?

Thank you,
 
The above is a "Journal" in "Visual basic". Journals can be run as is. No need for extra licenses.
copy the text from the white box and paste in notepad. Save the text file and replace the extension of the file from ".txt" to ".vb"
Journals are not "intelligent", - you need to run the journal again as soon as there is change in the filename / path etc.

Regards,
Tomas
 
Ok that makes a file attribute of the path how do you get it from there to an expression so I can break it up for the pieces I need.

Thank you,

Mike
 
If you are trying to fill out a title block I think using attributes might be a better option. At least that is how we do it where I work.

To make sure that the files are always up to date you can modify your save and save as to always run the journal when files are saved.
 
Also in that journal is it possible to get the user on the computer?
 
UG PERSON

The problem is I need to break out part of the file path using the split string and list in expressions. we have our customer and part description in our file path so I was going to use the path to fill in those fields.
 
How do I make the save and save as run the journal as well.
 
cowski

I used that same method to get the drawing name and number but the part is in a folder that has the description of the part it makes and that is in a folder that has the customer name in it that is what I needed the file path for so I do the same split string to pull that information into those fields on the drawing.

Thank you
 
What dose the file path look like that you have, and what info do you need from it?


 
drive:\jobs\The_costomer_name\Class_size_xxx-xxxx\tooling-type\xxx-xxx-xxx-_part-discription.prt

I need:

1. Customer
2. Class and size
3. drawn by - This could be the user on the comp when drawing is started
4. part number - I used ug_askcurrentworkpart() and substring
5. part description - I used ug_askcurrentworkpart and split string and list
6. date drawn - I used StringUpper(dateTimeString("localTime?", True)) and substring
7. file name - I used <W@$SH_PART_NAME>
8. sheet number - I used <W@$SH_SHEET_NUMBER> of <W@$SH_NUMBER_OF_SHEETS>
9. drawing scale - I used <W@$SH_SHEET_SCALE_NUMERATOR>:<W@$SH_SHEET_SCALE_DENOMINATOR>
10. sheet size - I used <W@$SH_SHEET_SIZE><C>

 
If you need to get the current username you can add the line below to a journal and it will get the windows username from the windows environment.

Dim user_name As String = System.Environment.ExpandEnvironmentVariables("%username%")

you can parse the string "user_name" to format it as you want and then send it to an attribute.

Mark Benson
Aerodynamic Model Designer

To a Designer, the glass was right on CAD.
 
Try this journal.



Code:
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen 
Imports NXOpen.UF  
 

 

Module NXJurnal

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Sub Main

workPart.SetAttribute("File_Path", GetFilePath())

workPart.SetAttribute("File_Name", GetFileName())

workPart.SetAttribute("Part_Number", GetFileNumber())

workPart.SetAttribute("Part_Decsription", GetFileDescription())

workPart.SetAttribute("Tooling_type", GetFileToolingType())


workPart.SetAttribute("Class_size", GetFileClassSize())

workPart.SetAttribute("Customer_Name", GetFileCustomerName())


Dim user_name As String = System.Environment.ExpandEnvironmentVariables("%username%")
 
workPart.SetAttribute("Name", user_name)


End Sub
	
	
	
'***********************************************************************

Function GetFileName()
	Dim strPath as String
	Dim strPart as String
	Dim pos as Integer
	
	'get the full file path
	strPath = displayPart.fullpath
	'get the part file name
	pos = InStrRev(strPath, "\")
	strPart = Mid(strPath, pos + 1)
	
	strPath = Left(strPath, pos)
	'strip off the ".prt" extension
	strPart = Left(strPart, Len(strPart) - 4)
	
	GetFileName = strPart
End Function
'***********************************************************************

Function GetFilePath()
	Dim strPath as String
	Dim strPart as String
	Dim pos as Integer

	'get the full file path
	strPath = displayPart.fullpath

	
	GetFilePath = strPath
End Function


'***********************************************************************


Function GetFileNumber()
	Dim strPath as String
	Dim strPart as String
	Dim pos as Integer
	Dim e as Integer
	Dim l as Integer

	
	'get the full file path
	strPath = displayPart.fullpath
	'get the part file name
	pos = InStrRev(strPath, "\")
	strPart = Mid(strPath, pos + 1)
	
	strPath = Right(strPath, pos)
	e = Len(strPart)
	l =(e-11)
	strPart = Left(strPart, Len(strPart) - l)

	
	GetFileNumber = strPart

End Function

'***********************************************************************


Function GetFileDescription()
	Dim strPath as String
	Dim strPart as String
	Dim pos as Integer
	Dim e as Integer
	Dim L as Integer

	
	'get the full file path
	strPath = displayPart.fullpath
	'get the part file name
	pos = InStrRev(strPath, "\")
	strPart = Mid(strPath, pos + 1)
	strPath = Right(strPath, pos)
       'strip off the "xxx-xxx-xxx-_"
	strPart = Right(strPart, Len(strPart) - 13)
	'strip off the ".prt" extension
	strPart = Left(strPart, Len(strPart) - 4)
	
	GetFileDescription = strPart

End Function





'***********************************************************************


Function GetFileToolingType()

	Dim strPath as String
	Dim strPart as String
	Dim strPart2 as String
	Dim pos as Integer
       Dim pos2 as Integer

	'get the full file path
	strPath = displayPart.fullpath

	pos = InStrRev(strPath, "\")
	strPart = Left(strPath, pos - 1)
       pos2 = InStrRev(strPart, "\")
	strPart2 = Mid(strPart, pos2 + 1)

	
	GetFileToolingType = strPart2
End Function
	
'***********************************************************************


Function GetFileClassSize()

	Dim strPath as String
	Dim strPart as String
	Dim strPart2 as String
	Dim strPart3 as String
	Dim pos as Integer
       Dim pos2 as Integer
       Dim pos3 as Integer

	'get the full file path
	strPath = displayPart.fullpath

	pos = InStrRev(strPath, "\")
	strPart = Left(strPath, pos - 1)
       pos2 = InStrRev(strPart, "\")
	strPart2 = Left(strPart, pos2 - 1)
       pos3 = InStrRev(strPart2, "\")
	strPart3 = Mid(strPart2, pos3 + 1)
	
	GetFileClassSize = strPart3

End Function
	
'***********************************************************************


Function GetFileCustomerName()

	Dim strPath as String
	Dim strPart as String
	Dim strPart2 as String
	Dim strPart3 as String
	Dim strPart4 as String
	Dim pos as Integer
       Dim pos2 as Integer
       Dim pos3 as Integer
       Dim pos4 as Integer

	'get the full file path
	strPath = displayPart.fullpath

	pos = InStrRev(strPath, "\")
	strPart = Left(strPath, pos - 1)
       pos2 = InStrRev(strPart, "\")
	strPart2 = Left(strPart, pos2 - 1)
       pos3 = InStrRev(strPart2, "\")
	strPart3 = Left(strPart2, pos3 - 1)
       pos4 = InStrRev(strPart3, "\")
	strPart4 = Mid(strPart3, pos4 + 1)
	
	GetFileCustomerName = strPart4

End Function


	
End Module
 
Ok have a few questions here how do I make a string appear in all caps. Also is there a way for the strings to not have the underscores and dashes?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor