有人问我UG的external模式.
这是UG二次开发不需要UG界面时使用的一种模式。UG Open只开放了部分的API提供支持。
internal模式是UG的插件方式调用。
所以,即使是external模式也不能够脱离UG运行。
以前,使用C/C++开发时,internal的程序是dll,而external的程序是exe。
采用.net语言,internal也可以写成exe。
internal使用的是UG规定的入口函数,比如Main、Starup
external只有一个入口函数Main
虽然UG两种开发模式都使用同一套API,但是支持与否要看说明。
比如
UF_PART_open (view source)
Defined in: uf_part.h
Overview
Retrieves an existing NX part or Solid Edge part into the session and
makes it the work and display part. Solid Edge parts (.par, .psm, .pwd or .asm
file extension) are opened by extracting the Parasolids data from the Solid
Edge part and then importing this data into a new NX part
with a .prt extension. The file name of the new NX part has the Solid
Edge part name and a ".prt" file extension. If there is an existing NX
part with the same name as the Solid Edge part, then this function
returns an error.
The NX part file that you create by opening a Solid Edge part
file contains one or more unparameterized solid bodies.
Other files can be opened with this call. The following
extensions are valid - .udf, .bkm, .xpk and .jt. Foreign files with the
following extensions can also be opened with UF_PART_open - .igs, .stp,
.dxf, .dwg and .model.
If a part is a read-only part, and the part retrieval modifies the part,
you will receive the error code UF_PART_err_read_only_modified, for that
part when you call UF_PART_open. In this case UF_PART_open will not
return a zero status.
Environment
Internal and External
==========================
UF_DISP_create_image (view source)
Defined in: uf_disp_ugopenint.h
Overview
Export a PNG/JPEG/TIFF/GIF/XWD/BMP full window area image
Creates an image file with the file type you specify using the image
currently displayed in the graphics window.
Return
Return code:
= 0 No error
= not 0 Error code, including:
UF_DISP_err_failed_to_create_image_file
Standard UF error codes
Environment
Internal
UF_DISP_create_image (view source)
Defined in: uf_disp_ugopenint.h
Overview
Export a PNG/JPEG/TIFF/GIF/XWD/BMP full window area image
Creates an image file with the file type you specify using the image
currently displayed in the graphics window.
Return
Return code:
= 0 No error
= not 0 Error code, including:
UF_DISP_err_failed_to_create_image_file
Standard UF error codes
Environment
Internal
另外,如果要运行external模式,需要把UGII目录加入到Windows的Path路径下,否则运行时找不到dll
这是用.net做的external程序示例
view plaincopy to clipboardprint?
- try
- {
- Session theSession = Session.GetSession();
- Console.WriteLine("OK");
- Part thePart = theSession.Parts.NewDisplay(@"E:\UGNX6\test.prt", Part.Units.Millimeters);
- PartSaveStatus ps = thePart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.True);
- Console.WriteLine(ps.ToString());
- }
- catch (NXOpen.NXException ex)
- {
- Console.WriteLine(ex.ToString());
- }
try { Session theSession = Session.GetSession(); Console.WriteLine("OK"); Part thePart = theSession.Parts.NewDisplay(@"E:\UGNX6\test.prt", Part.Units.Millimeters); PartSaveStatus ps = thePart.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.True); Console.WriteLine(ps.ToString()); } catch (NXOpen.NXException ex) { Console.WriteLine(ex.ToString()); }
原帖:http://blog.csdn.net/begtostudy/archive/2009/01/25/3852773.aspx