Cancel
Showing results for 
Search instead for 
Did you mean: 

How to Create New Part or Invoke "File => New" menu from NX plug-in

Hi , We are writing a plug-in in NX. I wanted to invoke "File => New" menu item from my plug-in if no Part Workspace is available i.e. workpart returned is NULL in following line "NXOpen.Part workPart = Session.GetSession().Parts.Work;" How to invoke "File => New" menu item from Dialog if no Part is present? Thanking you in advance for your help.
7 REPLIES

Re: How to Create New Part or Invoke "File => New" menu from NX plug-in

Siemens Phenom Siemens Phenom
Siemens Phenom

If you open a new NX session in Gateway, start recording a journal, then create a new part, the recorded journal will contain everything you need.

 

(Hint: Session.Parts.FileNew() )

 

Note that this is the best way to figure out what part of the API you need for any future inquiries like this.

 

Regards,

Jim

 

Re: How to Create New Part or Invoke "File => New" menu from NX plug-in

Siemens Phenom Siemens Phenom
Siemens Phenom

 

I think Session.Parts.FileNew() will allow you to create a new part, but it will not actually present the dialog.

 

For that you can use the wrapped equivalent of the Open C function:

 

UF_UI_ask_create_part_filename ()
 

Defined in: uf_ui.h
 
Overview
Displays the File-->New File Selection Dialog.
Environment
Internal
See Also
This will be something like theUFSession.UI.AskCreatePartFilename() in NXOpen .Net.
 
Regards,
 
Steve
 

Re: How to Create New Part or Invoke "File => New" menu from NX plug-in

Thank you Steve for your suggestion.

I am using your suggested code as follows,

    NXOpen.UF.UFSession theUFSession = NXOpen.UF.UFSession.GetUFSession();            
    theUFSession.Ui.AskCreatePartFilename(ref partFileName, ref units, out response);

Using above code I was able to invoke "New Part File" dialog, but once I click 'OK' button I get 2 error message dialogs and NX crashes (in debug/release).
Please refer attached JPEG "Error.jpg" for the sequences of dialogs when NX crashes.

Also I want default "File->New" dialog to get invoked and not the "New Part File" dialog.
I want to invoke "File->New" dialog as it will allow my users to use any user defined templates from local machines as well as default templates in the "UGII_ROOT_DIR\\templates" folder Viz. model-plain-1-mm-template.prt.

(Thanks Jim, Yes using "Session.Parts.FileNew()" I was able to create new Part but It doesn't invoke the "File->New" dialog.)

How to invoke "File->New" menu from NX plug-in?

Re: How to Create New Part or Invoke "File => New" menu from NX plug-in

Siemens Phenom Siemens Phenom
Siemens Phenom

 

You are correct, the dialog that this function presents is not the same dialog that you see when you use File -> New in NX.  Most of the dialogs that you see when running interactive NX are not available for use in custom programs - the few exceptions are things like class selection dialogs.

 

But the error that you got when using the wrapper function looks serious.  Please create an incidient report with your local GTAC office so that we can investigate this thoroughly.

 

Thanks!

 

Steve

 

Re: How to Create New Part or Invoke "File => New" menu from NX plug-in

Thank you Steve.

I was giving relative filepath to the variable ‘partFileName’ the ‘AskCreatePartFilename(…)’. Once I set complete path it stopped crashing.

 

But it doesn’t solve my issue as I am still not getting valid “NXOpen.Part workPart”.

Re: How to Create New Part or Invoke "File => New" menu from NX plug-in

Siemens Phenom Siemens Phenom
Siemens Phenom

 

You will need to use the filename returned from that call, as well as the units chosen to create a new part.  In VB, it looks like this:

 

...


        Dim partUnits As NXOpen.Part.Units

        ufs.Ui.AskCreatePartFilename(fileName, units, response)

        If units.Equals(2) Then
            partUnits = Part.Units.Inches
        Else
            partUnits = Part.Units.Millimeters
        End If

        Dim workPart As Part = theSession.Parts.NewDisplay(fileName, partUnits)

 

This may not be completely clear in the docs, but in the Open C docs for the original function, UF_UI_ask_create_part_filename, there is a link to a related function, UF_UI_ugmgr_ask_create_part_file_name , which has to following comments:

"This routine just brings up the part selection dialog to prompt
for the new part name. This routine does not actually create the part.
This routine was written to provide the routine that does the
same work which UF_UI_ask_create_part_filename does in native NX. In
NX Manager, UF_UI_ask_create_part_filename creates the specified
part, this routine can be used when you want to get the filename
but not yet create the part."
 
So since this "does the same work" as the call you are trying to use, and does not create the part, we can conclude that UF_UI_ask_create_part_filename also does not create the part.
 
We should probably add this explanation to the docs for UF_UI_ask_create_part_filename.
 
(I hope this helps to make this more clear!)
 
Steve
 

Re: How to Create New Part or Invoke "File => New" menu from NX plug-in

Hi Steve,

 

Thank you for your help. I was able to create new part using "theSession.Parts.NewDisplay" as you mentioned in your earlier post.

 

But it is created in Gateway ("File->Applications->Gateway" is selected).

Can I make it in 'File->Applications->Modeling' (Ctrl+M) using API? How?

 

Thank you.