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!

Journals and Part Templates

Status
Not open for further replies.

kr7530

Automotive
Aug 9, 2011
130
I have a journal that creates a basic assembly based on some user inputs. How do I point my journal to use a specific template file for creating the new components? And, where do I need to save my template file?

Change fileNew1.TemplateFileName = "assembly-mm-template.prt" to fileNew1.TemplateFileName = "My_Template.prt" ?

Is this the proper location to save new templates? NX 8.0\UGII\templates

Any information on this would be greatly appreciated!

Thanks,
Kevin
NX8
 
Replies continue below

Recommended for you

I'm pretty sure the template files can be saved anywhere you like as long as the .pax file points to the correct location.

The following code will show what files you currently have set up as templates.

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Dim templates() As String

        templates = theSession.Parts.FileNew.GetAvailableTemplates
        For Each temp As String In templates
            lw.WriteLine(temp)
        Next

        lw.Close()
    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

    End Function

End Module

www.nxjournaling.com
 
cowski,

Sorry for the delay. I ran your program and my template was in the list.
Below is a portion of the program, i can supply the rest if you need it to make sense of it.
The program errors out when I check to see if the file already exists before committing.
I get the "File already exists, Exiting" message, and I have double checked that the file does not exist.

Thanks,
Kevin



' -----------------------------------------------------------------------------------------------------------
' Menu: File->New...
' -----------------------------------------------------------------------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim fileNew1 As FileNew
fileNew1 = theSession.Parts.FileNew()
fileNew1.TemplateFileName = "Sim_Template.prt"
fileNew1.Application = FileNewApplication.Assemblies
fileNew1.Units = Part.Units.Millimeters
fileNew1.TemplateType = FileNewTemplateType.Item
fileNew1.NewFileName = FilePath+"\"+JobNumber+"_Sim_000.prt"
fileNew1.MasterFileName = ""
fileNew1.UseBlankTemplate = False
fileNew1.MakeDisplayedPart = True
Dim nXObject1 As NXObject
lw.Open
lw.WriteLine(fileNew1.NewFileName.ToString)
lw.WriteLine(fileNew1.TemplateFileName.ToString)
lw.Close
'---------------Checking to see if file exists before trying to commit--------------------------------------
Try
nXObject1 = fileNew1.Commit()
Catch ex As NXException
MessageBox.Show("File already exists, Exiting")
Exit Sub
End Try

Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
fileNew1.Destroy()
 
Try calling the .Validate method before .Commit to see if the new file has been sufficiently defined.

Also, for more information on your specific error, try printing the error message rather than the generic string "File already exists, exiting".

Code:
Try
    nXObject1 = fileNew1.Commit()
Catch ex As NXException
    [s]MessageBox.Show("File already exists, Exiting")[/s]
    MessageBox.Show(ex.message)
    Exit Sub
End Try

www.nxjournaling.com
 
cowski,

Thanks for the information, I will research the .Validate.
Right now I am trying to figure out where NX is pulling the template file from.

Kevin
 
I figured out which directory and .pax file. I added my template at the end of the .pax file. When I do a File New my template is in the list and does work. However, when I run my journal it still can't find the template.
Any ideas??

Thanks,
Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor