×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Journals and Part Templates

Journals and Part Templates

Journals and Part Templates

(OP)
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

RE: Journals and Part Templates

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

RE: Journals and Part Templates

(OP)
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()

RE: Journals and Part Templates

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
    MessageBox.Show("File already exists, Exiting")
    MessageBox.Show(ex.message)
    Exit Sub
End Try 

www.nxjournaling.com

RE: Journals and Part Templates

(OP)
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

RE: Journals and Part Templates

(OP)
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

RE: Journals and Part Templates

(OP)
All set!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources