UGOpen
- 格式:docx
- 大小:29.22 KB
- 文档页数:10
U G/O p e n A P I基础知识●U G/O p e n A P I介绍●U F程序的基本概念●U F的对象模型与常用函数●编写U F程序的基础知识●U F工程的编译链接●U I S t y l e r●U F程序示例U G/O p e n A P I介绍U G/O p e n A P I的概念U G/O p e n A P I(U G开放应用程序接口),也称作U s e r F u n c t i o n(用户函数)。
它是U G/O p e n二次开发软件包的一个重要组成部分。
其核心包括了约2000个C 函数,分别用来实现大部分的U G操作。
通过调用这些C函数,用户自编的程序能查询并修改U G对象模型,处理使用者和U G界面的交互,控制U G的行为等。
另外,工作站版的U G/O p e n A P I工具中还包含了工作站平台开发所需的编译和链接工具。
在以下的段落中,U G/O p e n A P I均简写为U F。
U F的常用功能能实现用户和U G对象模型(U n i g r a p h i c s O b j e c t M o d e l)之间的交互能创建和编辑用户自定义对象(U D O)处理各种U G对象之间的联系,并为它们的显示和更新提供了完整的手段借助U G菜单脚本(U G/O p e n M e n u S c r i p t)和用户接口设计师(U I S t y l e r),U F能让第三方开发者定制U G的用户界面,把用户开发的程序集成入U G的菜单和对话框之中U F能让用户程序自行构造P a r t文件,查询U G对象的参数,创建装配图或平面图等微机版U F开发包的组成U F作为U G/O p e n K i t的一部分提供,安装在U G主目录的U G O p e n子目录下U F的头文件(U F_*.h)静态库文件(u g*.l i b)大量的U F示例程序(*.c)U F程序的基本概念外部U F和内部U FU F程序的源代码并不能被U G直接执行,和C程序一样必须通过编译形成动态链接库或可执行文件后才能发挥作用。
UG二次开发之Open和NXOpenUG的二次开发有两套系统,一套叫Open,一套叫NXOpen。
Open主要是造型方面的功能,NXOpen比较全面。
Open原来支持的是C/C++,.net的NXOpen.UF命名空间支持。
NXOpen 支持C++和.net等。
Open系统,支持C的原来叫UFun,或者API,用的人最多。
后来出现了Open C++。
但是Open C++支持编辑等属性行为,不能创建。
所以,一般是通过API创建特征,比如实体,通过C++的类查询和修改。
NXOpen系统,是完全面向对象的,所以可以创建和修改特征。
当然,NXOpen几乎支持UG所有的功能。
所以,目前开来,如果使用C/C++方式,可以使用Open C和C++结合的方式,利用C来创建特征,使用C++来管理。
如果使用.net可以直接使用NXOpen。
对于不熟悉NXOpen的人可以按照Open C的知识上手NXOpen.UF。
下面将通过各个例子说明上述系统的使用,因为.net平台是通用的,我只举了C#的例子,VB等也是一样的的。
而java我不懂,见谅了。
一、Open C1、遍历的例子#include <uf_object_types.h>#include <uf_part.h>#include <uf_obj.h>#include <uf_modl.h>#include <string>#include <sstream>using std::string;using std::stringstream;//下面是程序片段UgSession session( true );try{/* TODO: Add your application code here */uf_list_p_t lpObj;UF_MODL_create_list(&lpObj);tag_t prt = UF_PART_ask_display_part();tag_t Next_tag=NULL_TAG;do{UF_OBJ_cycle_objs_in_part(prt,UF_solid_type,&Next_tag);if(Next_tag==NULL_TAG) break;int t,subtype;UF_OBJ_ask_type_and_subtype(Next_tag,&t,&subtype);if(subtype==UF_solid_body_subtype)UF_MODL_put_list_item(lpObj,Next_tag);} while(1);logical is_open;UF_UI_is_listing_window_open(&is_open);if(!is_open) UF_UI_open_listing_window();int sum;UF_MODL_ask_list_count(lpObj,&sum);for (int i=0;i<sum;i++){tag_t t;UF_MODL_ask_list_item(lpObj,i,&t);stringstream s;s<<(int)t;string str;str = s.str();UF_UI_write_listing_window(str.c_str());UF_UI_write_listing_window("\n");}// UF_UI_exit_listing_window();UF_MODL_delete_list(&lpObj);}/* Handle errors */catch ( const UgException &exception ){processException( exception );}2,创建block的例子#include <uf.h>#include <uf_ui.h>#include <uf_exit.h>#include <uf_modl.h>//下面是程序片段/* Initialize the API environment */if( UF_CALL(UF_initialize()) ){/* Failed to initialize */return;}/* TODO: Add your application code here */double corner[3] ={0,0,0};char* edge[3] = {"10","5","20"};tag_t tag;UF_MODL_create_block(UF_NULLSIGN,NULL_TAG,corner,edge,&tag);/* Terminate the API environment */UF_CALL(UF_terminate());二、Open C++1、遍历的例子#include <ug_typed.hxx>#include <ug_part.hxx>#include <ug_body.hxx>#include <ug_string.hxx>using std::string;//下面是程序片段UgSession session( true );try{/* TODO: Add your application code here */UgPart *pWorkPart = UgSession::getWorkPart();UgTypedObject *pObj;ostrstream buffer;for ( pObj = pWorkPart->iterateFirst ( );pObj;pObj = pWorkPart->iterateNext ( pObj ) ){std::string name = pObj->getName ( );UgBody *pBody = dynamic_cast<UgBody*>(pObj);if (pBody){buffer<<(int)pBody->getTag()<<"\n";}}UgInfoWindow::open();UgInfoWindow::write(string(buffer.str()));delete buffer.str();}/* Handle errors */catch ( const UgException &exception ){processException( exception );}2、通过模板搜索的例子#include <ug_body.hxx>#include <ug_iterator.hxx>#include <ug_string.hxx>//下面是程序片段UgSession session( true );try{/* TODO: Add your application code here */ostrstream buffer;// Construct an iterator for NX face objectsUgIterator < UgBody > pObj;//workpart 可以通过其他方式指定//UgIterator < UgFace *> curFace;//// Loop through all faces//while ( !curFace.isFinished ( ) )//{// // Get the name of the current face// std::string faceName = (*(*curFace))->getName ( );// curFace.findNext ( );//}// Loop through all faceswhile ( !pObj.isFinished ( ) ){// Get the name of the current facestd::string faceName = (*pObj)->getName ( );buffer<<(int)(*pObj)->getTag()<<endl;pObj.findNext ( );}UgInfoWindow::open();UgInfoWindow::write( std::string( buffer.str() ));delete buffer.str();}/* Handle errors */catch ( const UgException &exception ){processException( exception );}三、NXOpen C++1、创建block的例子#include <NXOpen/Session.hxx>#include <NXOpen/Part.hxx>#include <NXOpen/Features_BlockFeatureBuilder.hxx>#include <NXOpen/Features_Block.hxx>#include <NXOpen/PartCollection.hxx>#include <NXOpen/Features_FeatureCollection.hxx>#include <NXOpen/UI.hxx>#include <NXOpen/NXMessageBox.hxx>using namespace NXOpen;//下面是程序片段NXOpen::Session *theSession = NXOpen::Session::GetSession();try{/* TODO: Add your application code here */Part* thePart = theSession->Parts()->Work();NXOpen::Features::Feature* block = NULL;NXOpen::Features::BlockFeatureBuilder* theBuilder = thePart->Features()->CreateBlockFeatureBuilder(block);NXOpen::Point3d basePoint(100, 100, 100);theBuilder->SetOriginAndLengths(basePoint, "100", "200", "300");// NXOpen.Body theBody = null;//theBuilder.SetBooleanOperationAndTarget(NXOpen.Features.Feature.BooleanType.Create, theBody);theBuilder->Commit();//theBuilder->CommitFeature();NXOpen::UI::GetUI()->NXMessageBox()->Show("",NXMessageBox::DialogType::DialogTypeInformation, "OK!");// UI->GetUI()->NXMessageBox.Show("", rmation, "OK!");}/* Handle errors */catch ( const UgException &exception ){processException( exception );}2、遍历特征的例子#include <NXOpen/Session.hxx>#include <NXOpen/Part.hxx>#include <NXOpen/Features_BlockFeatureBuilder.hxx>#include <NXOpen/Features_Block.hxx>#include <NXOpen/PartCollection.hxx>#include <NXOpen/Features_FeatureCollection.hxx>#include <NXOpen/UI.hxx>#include <NXOpen/NXMessageBox.hxx>#include <NXOpen/ListingWindow.hxx>using namespace NXOpen;//下面是程序片段NXOpen::Session *theSession = NXOpen::Session::GetSession();try{/* TODO: Add your application code here */Part* thePart = theSession->Parts()->Work();theSession->ListingWindow()->Open();NXOpen::Features::FeatureCollection::iterator i;for (i=thePart->Features()->begin();i!=thePart->Features()->end();i++){theSession->ListingWindow()->WriteLine((*i)->Name()+"--"+(*i)->GetJournalIdentifier());}NXOpen::UI::GetUI()->NXMessageBox()->Show("",NXMessageBox::DialogType::DialogTypeInformation, "OK!");// UI->GetUI()->NXMessageBox.Show("", rmation, "OK!");}/* Handle errors */catch ( const UgException &exception ){processException( exception );}四、NXOpen C#1、创建blcok的例子using NXOpen;using NXOpen.Utilities;using NXOpen.UF;using NXOpenUI;//下面是程序片段Session theSession = Session.GetSession();try{Part thePart = theSession.Parts.Work;NXOpen.Features.Feature block = null;NXOpen.Features.BlockFeatureBuilder theBuilder = thePart.Features.CreateBlockFeatureBuilder(block);NXOpen.Point3d basePoint = new Point3d(100f, 100f, 100f);theBuilder.SetOriginAndLengths(basePoint, "100", "200", "300");mit();//mitFeature();UI.GetUI().NXMessageBox.Show("", rmation, "OK!");}catch(NXException ex){UI.GetUI().NXMessageBox.Show("error!", NXMessageBox.DialogType.Error, ex.Message);}2、遍历特征的例子using NXOpen;using NXOpen.Utilities;using NXOpen.UF;using NXOpenUI;//下面是程序片段Session theSession = Session.GetSession();theSession.ListingWindow.Open();try{Part thePart = theSession.Parts.Work;foreach (NXOpen.Features.Feature c in thePart.Features){//NXOpen.Features.Block t = c as NXOpen.Features.Block;//if(t!=null)//{// theSession.ListingWindow.WriteLine(t.ToString());//}theSession.ListingWindow.WriteLine(+"--"+c.ToString());}UI.GetUI().NXMessageBox.Show("", rmation, "OK!");}catch (NXException ex){UI.GetUI().NXMessageBox.Show("error!", NXMessageBox.DialogType.Error, ex.Message);}五、NXOpen.UF1、仿照Open C中的例1子实现using NXOpen;using NXOpen.Utilities;using NXOpen.UF;using NXOpenUI;NXOpen.UF.UFSession theUFSession = NXOpen.UF.UFSession.GetUFSession();try{double[] corner ={ 0, 0, 0 };string[] edge = { "10", "5", "20" };Tag tag;theUFSession.Modl.CreateBlock1(FeatureSigns.Nullsign, corner, edge, out tag);}catch (NXException ex){UI.GetUI().NXMessageBox.Show("error!", NXMessageBox.DialogType.Error, ex.Message);}2、仿照Open C中的例子2实现using NXOpen;using NXOpen.Utilities;using NXOpen.UF;using NXOpenUI;NXOpen.UF.UFSession theUFSession = NXOpen.UF.UFSession.GetUFSession();try{Tag[] list=null;Tag thePart = theUFSession.Part.AskDisplayPart();theUFSession.Modl.CreateList(out list);Tag Next_tag=Tag.Null;do{theUFSession.Obj.CycleObjsInPart(thePart,70/* UF_solid_type*/,ref Next_tag);if (Next_tag == Tag.Null) break;int t, subType;theUFSession.Obj.AskTypeAndSubtype(Next_tag,out t, out subType);if (subType == 0/*UF_solid_body_subtype*/)theUFSession.Modl.PutListItem(list, Next_tag);} while (true);bool isOpen;theUFSession.Ui.IsListingWindowOpen(out isOpen);if (!isOpen) theUFSession.Ui.OpenListingWindow();int sum;theUFSession.Modl.AskListCount(list,out sum);for (int i = 0; i < sum;i++ ){Tag t;theUFSession.Modl.AskListItem(list, i, out t);theUFSession.Ui.WriteListingWindow(t.ToString());}/*Treat all the arguments with the"Output to be freed " annotation as an output parameter.* The system takes care of freeing memory.*/}catch (NXException ex){UI.GetUI().NXMessageBox.Show("error!", NXMessageBox.DialogType.Error, ex.Message);。
UG/OPEN API简明教程User Functions培训简明教程第一章绪论1 User Function是什么定义:在UG中用C语言开发应用程序的一个工具 2 User Function的两种形式External λ菜单λ(执行程序)Internal (动态连接库)3 User Function的组成与相互关系User Function可以分为以下几个部分:C语言库函数(1) 创建与查询几何实体(2) 分析几何实体(3) 创建与编辑特征(4) 创建与编辑表达式(5)λ应用程序(回调函数)λ对话框数据管理这几部分的关系可以作如下的描述:User Functions的菜单和对话框是程序与用户交互的工具,从菜单可以起动应用程序,对话框等,在对话框激活控件时,将调用相应的回调函数,回调函数和控件的关系在UIStyler 中定义。
应用程序和回调函数用基本的C语言和User Functions的库函数编码。
4 User Functions的执行User User Functions◊Execute UG/OPEN◊Functions的执行包括四种形式:(1) File 选取该菜单将出现一个文件打开对话框,选取相应用应用程序即可。
(2) Menu ACTION (3) UIStyler 回调函数(2)和(3)将在后面的章节中作详细描述(4) 将应用程序COPY到UGII_USER_DIR\startup子目录下,应用程序将在UG启动时自动运行。
5 User Functions的开发步骤有关软件工程方面的内容,不是我们要介绍的内容,要讲的是User Functions有关的开发步骤。
在下面讲述的内容是以NT下的Visual C++ 5.0和UG15.0为支持环境。
具体的开发步骤如。
(1) 建立C源程序Win32◊project◊New ◊(2) 在Visual C++中建立一个project (a).Create new project Filesetting◊Dynamic-Link Library 此时还要输入project的名称。
OverviewOpen C API is designed to enable an easy interface between NX and the outside world. The Open C API consists of:∙ a large set of user callable functions/subroutines that access the NX Graphics Terminal, File Manager, and Database.∙command procedures to link and run user programs.∙an interactive interface in NX to run those programs.Open C API programs can run in 2 different environments, depending on how the program was linked. The two environments are:∙External - these Open C API programs are stand alone programs that can run from the operating system, outside of NX, or as a child process spawned from NX.∙Internal - these Open C API programs can only be run from inside of an NX session.These programs are loaded into main memory along side of NX and access routineswithin NX. One advantage to this is that the executables are much smaller and linkmuch faster. Once an Internal Open C API Program is loaded into memory, it can stay resident for the remainder of the NX session. If you call this program again, it executes without reloading (provided it was not unloaded). Internal Open C API programs work on the current part and automatically modify the part display.Most Open C API functions/subroutines can be used in either mode. There are only a few, mostly User Interface routines that are only supported in internal mode.The Open C API product is not intended to replace the Open C GRIP(GR aphics I nteractive P rogramming) product, but rather to make it easier to interface to NX from a high-level language such as C or C++. There are many tasks where a high-level language program is more appropriate.The Open C API product is explicitly defined in this manual. It is our intent to insulate the application programmer from changes in future NX software releases. Unfortunately, this is not always possible. Where this is not possible, every effort will be made to support existing routines for at least one release version of NX prior to obsolescence, and forewarn users of routines which will be changed in the future.When upgrading to a new release, programmers are expected to recompile and relink theirprograms. In addition, the release notes supplied with each release of NX describe changes that are important to Open C programmers.The release notes also describe what versions of the operating system and compiler were used to create the release of Open C API. Since operating systems, linkers, compilers,run-time libraries, etc., are usually updated by the hardware vendors more frequently than NX is released, there may be combinations that do not function correctly with Open C API. Additionally, compiling or linking may require different options other than those documented here. Refer to the Release Notes supplied with each release of NX for specific changes that may be necessary to use Open C API correctly.Example Source Code FilesMany of the routines that have example programs have the C source code files located inthe ugopen directory, which is a subdirectory of the directory pointed to by the variableUGII_ROOT_DIR. The source code files have a "ufd" prefix followed by a module name and a descriptive name. For example, ufd_curve_ask_spline_thru_pts.cis an example source code program that demonstrates the UF_CURVE_ask_spline_thru_pts function. The source code found in the ugopen directory should always be preferred over the example code documented in the Open C API Reference manual due to the possibility of any late changes to routines that may occur.Supported LanguagesOpen C API programs can be written in the C or C++ programming languages.Initialization and TerminationAll Open C API programs must be correctly initialized and terminated. You use the two C functions UF_initialize and UF_terminate to do this. After you have declared your variables the first Open C API function call must be UF_initialize. Your last function call mustbe UF_terminate. In external mode, you may only call UF_initializeonce.Once UF_terminate is called, there is no way to reconnect to the Open C environment. If you are using the Pre-NX4 Open C API license, UF_initialize andUF_terminate will allocateand deallocate the Open C API license. If you are using the new NX4 licensing scheme, the Open C API license is not required, but each function will require a specific modulelicense. For example, if you call UF_ASSEM_add_part_to_assembly you must have an Assemblies license. To view a current table of user functions and their associated licenses click here license_table.csvThere is a tool available to scan existing user function programs to determine which modulespecific licenses will be necessary to run the program with the new licensing system. Click here query_licenses to download this tool. Note that Perl is required to execute this tool from the command prompt. You can download the latest version of Perlfrom . Once you have Perl installed open a command prompt and navigate to the directory where you saved the query license tool. Type 'perl query_licenses.pl -h' to get started.Function RequirementsTo create geometry, cycle a model, or perform other elementary operations, you must first load an NX part file. Where routines operate on a particular type of tag, it is imperative that you pass the correct type of tag to the routine. For example, if you want to query the coordinates of a point, you must pass in a tag for a point - not the tag for a line or any other type of geometry. The above are error conditions in almost all routines. These error conditions are not repeated for each individual routine.Internal ProgramsMany Internal Open C API programs use the function ufusr as an entry point.The ufusr function acts as a main function.Internal Open C API programs can be thought of as a user written function to NX. To start execution of the program, NX loads the program into memory and then references the symbol ufusr. The user's program takes over execution at that point. At the end of execution, the program executes a return statement which returns control to NX. The Open C API Programmer's Guide describes how to build both internal and external programs and describes example files that are supplied in the Open C kit. See the "Basic Part File Query" chapter of the Open C API Programmer's Guide.The entry point into an Internal program is through a function/subroutine called ufusr./** internal C Open C API program** input* param - parameters passed into the Open C API program from* NX (Reserved for future enhancements)* parm_len - Length of param after implemented (may* not be needed on all platforms, see the* "Writing Open C API Programs" section)** output* retcod - User return code (future enhancement)*/#include <uf.h>/* Additional include files as required */void ufusr(char *param, int *retcod, int parm_len){/* statement declarations */UF_initialize();/* body */UF_terminate();}Once an executable is loaded into memory, it stays resident in memory with the NX session unless you use methods to unload the image (e.g. see the function ufusr_ask_unload inthe uf.h header file ).Automatic Part DisplayBecause internal Open C API programs are running in an NX environment, part display is automatically done. Object display can be suppressed and individual objects displayed with routines in the uf_disp.h header file suchas UF_DISP_set_display and UF_DISP_add_item_to_display.Under certain circumstances in Internal Open C API, a part must be active (e.g. geometry creation). The active part may be one that was previously opened interactively in NX or one retrieved in Open C API. UF_ASSEM_ask_work_part can be used to determine if a part is already active. Parts can be filed either from Open C API or in NX.External ProgramsExternal C programs use the standard C main function to call Open C API routines.See ext_uf_example.c in your installed Open C API directory for for an example external program.External Open C API programs are written, compiled, and linked like any normal program. Program statements for start up and termination should follow those normal for "C".External Model Terminal I/OAll terminal I/O should be done using the I/O statements supplied by the high-level language (e.g. C functions puts(), getchar(), printf(), etc.).If the External Open C API program is invoked from NX running on a terminal with windows, all high-level language I/O will appear on the window from which NX was started. This window may be hidden behind some of the other NX windows and must be "popped" to the top to be used. On Windows NT, there is not a terminal window associated with NX, so terminal I/O is not possible.No Part DisplayNo part display can or will be done in external mode. Any part created or modified by external Open C API programs will have to be retrieved in NX for display after the external Open C API has filed the part.Before any Database routines can be called, an existing part must be created or retrieved (UF_PART_new or UF_PART_open) to work on. Parts can be filedwithUF_PART_save, UF_PART_save_as, or UF_PART_save_all.Open C API ConventionsUnless otherwise noted, new Open C API functions are written in C and follow the ANSI C standard. Please refer to the Release Letter for information on new functionality and changes.Except where noted, all new Open C API functions follow a descriptive naming convention. The format is:UF_ABBR_descriptive_namewhere:UF_ denotes U nigraphics Open C API F unctionABBR_ is the abbreviation for the area the function representsdescriptive_name is a descriptive title giving a hint of the function's purposeAs an example:UF_PART_close_all A function that falls into the part manipulation application that closes all open parts.Database RoutinesThe Open C API has a large set of routines to create and modify NX objects. We assume that you are familiar enough with NX and the C language to prevent any serious mistakes. Some of the routines return an error code, others do not. The routines that create objects will return an Object Identifier = NULL_TAG to indicate an error.Variable DeclarationsOpen C API supports all C data types. Object Identifiers (EIDs) should be declared as tag_t to limit changes to your program.Character strings vary in length. The lengths documented in this manual are the maximum number of characters of data that are valid for either input or output by the routine.Data StructuresMany routines require data structures. In most cases the data structures are documented in the header file. However, there are some instances where a data structure is for internal use only or for proprietary usage and only a pointer to that structure is declared for the user.Include FilesThis documentation is organized by the header file that prototypes the functions. There are several include files provided for the users to add to their programs. The users should include uf_defs.h for general typedefs. The other include files should be used depending on the users application. These include files contain typedefdeclarations, ANSI prototypes of new routines and legacy code, and macros pertinent to the specified application.Error CodesUnless otherwise documented, every routine returns an int, which is the error code. A return code of 0 indicates success, and any other number indicates failure. The message associated with an error code can be retrieved by calling UF_get_fail_message.HandlesIn Unigraphics V9, when an object had a known object Identifier (EID), that EID was saved with the part and would be the same the next time the part was loaded. In V10 and beyond,because multiple parts can be loaded at once, the Tag (i.e. EID) of an object cannot be guaranteed between sessions. For this reason, "handles" were created to identify entities between sessions. To aid applications where the EID was saved in some data file between sessions, UF_ask_new_tag_of_object was created to return the post-V10 tag corresponding to the EID of an object in a V9 part that was just loaded. That tag can then be converted to a post-V10 handle using UF_TAG_ask_handle_of_tag.Legacy RoutinesSome Open C routines have been targeted to be removed from the released Open C libraries. Most of these routines are older routines that were originally used to support FORTRAN code. The legacy Removal Document lists these routines, and has information required to let almost all existing programs work without source code changes.How to Execute ProgramsYou execute Open C API programs by selecting the file name. After you have successfully compiled and linked your Open C API program perform the following steps:From within NX select File-->Execute-->NX Open. A list box displays the executable that you have previously successfully compiled and linked. If you execute externally written programs from within an NX session you cannot pass a command line argument. Additionally, you cannot perform operations on your current interactive part. You may wish to execute your external programs from the command line for these reasons.Compiling and Linking on Linux/Macos SystemsUfmenu is a utility script/command file that provides you with the ability to edit, compile, link and run your Open C API programs. ufcomp is a script that gives you the ability to compile programs, and uflink is a script that gives you the ability to link programs. These scripts are only supported on Linux and Macos workstations.See ufmenu details, ufcomp details and uflink details for more information.Compiling and Linking with a Linux MakefileOn on system that are not windows based systems, you can copy atemplate makefile (ufun_make_template.ksh) located in the${UGII_BASE_DIR}/ugopen directory, to compile and link your programs.The template makefile can be customized to compile and link: both internal and external, internal only, or external only Open C API programs. Instructions on how to use the template file are fully explained in the commented section of the file.After you have customized the template file, you should copy or move the file so that it is named either "Makefile" or "makefile", which are the standard names the make command expects. Alternatively, you could use the "-f" switch with the make command to specifythe makefile name.The template makefile was designed to be used with the make command supplied by the platform's vendor. For further information on make and file dependencies use "man make".Setting up your systemThis section describes the machine dependent information on how to setup and use Open C on your system. To use the Open C API, you must have the C or C++ environment setup on your workstation. If this environment is not set up, your system administrator must install it. For further details see:Windows Operating System SetupLinux SetupCompiler CertificationThe table listing the compilers for each supported platform can be found in the Product Notes under Automation. NX does not certify any other compilers for use with Open C programs. In general, the platform vendors must address any problems with a compiler newer than that which built NX. (See the Release Notes for OS levels that NX does certify.)Occasionally vendors obsolete compilers or create new compilers that are incompatible with the version that built NX. NX has no control over such developments, although the vendors usually have a vested interest in ensuring that newer compilers are compatible with the older versions.。
UG/OPEN API简明教程User Functions培训简明教程第一章绪论 1 User Func tion是什么定义:在UG中用C语言开发应用程序的一个工具 2 User Function的两种形式External λ菜单λ(执行程序)Internal (动态连接库)3 User Function的组成与相互关系User Function可以分为以下几个部分:C语言库函数(1) 创建与查询几何实体(2) 分析几何实体(3) 创建与编辑特征(4) 创建与编辑表达式(5)λ应用程序(回调函数)λ对话框数据管理这几部分的关系可以作如下的描述:User Functions的菜单和对话框是程序与用户交互的工具,从菜单可以起动应用程序,对话框等,在对话框激活控件时,将调用相应的回调函数,回调函数和控件的关系在UIStyler 中定义。
应用程序和回调函数用基本的C语言和User Functions的库函数编码。
4 User Func tions的执行User User Func tions◊Exec ute UG/OPEN◊Functions的执行包括四种形式:(1) File 选取该菜单将出现一个文件打开对话框,选取相应用应用程序即可。
(2) Menu ACTION (3) UIStyler 回调函数(2)和(3)将在后面的章节中作详细描述(4) 将应用程序COPY到UGII_USER_DIR\startup子目录下,应用程序将在UG启动时自动运行。
5 User Functions的开发步骤有关软件工程方面的内容,不是我们要介绍的内容,要讲的是User Func tions有关的开发步骤。
在下面讲述的内容是以NT下的Visual C++ 5.0和UG15.0为支持环境。
具体的开发步骤如。
(1) 建立C源程序Win32◊project◊New ◊(2) 在Visual C++中建立一个projec t (a).Create new project Filesetting◊Dynamic-Link Library 此时还要输入project的名称。
小白学UG二次开发 UGOpen UIStlyer 对话框设计本例参考《UG/Open API、MFC和COM 开发实例精解》黄勇,本例基本参照书中内容操作,没有做太大修改,能正常运行。
第一步,准备工作在UGII_USER_DIR目录里新建startup,application两个文件夹。
书中是这么说的,但是我只用到了application,startup我没有用到。
怎么设置环境变量我就不说了。
第二步,设计UI.UG 开始-》所有应用模块-》NX 6 之前版本UI样式编辑器选之前的版本主要为了降低开发难度。
进入UIStyler 对话框设计环境,新建文件。
里面有很多控件,自己试着点点看,探索下。
里面有对象浏览器,对话框和资源编辑器,对话框的标题和提示如下图所示,前缀名比较重要,直接关系到后续程序生成后的一些参数名称,我们这边设置为DIALOG_ACCESS。
设置如图所示的整数、实数、字符串和按钮控件,导航按键中按钮样式选项里选择的不同项会影响到后续的回调函数。
这里选择关闭。
整数,实数,字符串修改下标签和标识符。
这个会在对象浏览器里反应出来。
目前我还不会修改类型,就放着没管,如果有知道的,请帮忙解释下类型。
另外,我对回调函数的名称生成机制也不是很清楚,只是知道Back_cb应该是关闭对话框时触发的回调函数,action_3_act_cb是按钮空间触发的回调函数,名字和书上不太一样,但是能正常实现功能。
完成后,另存为对话框到application,语言选C,对话框名称为access_dialog,在目录下会生成access_dialog.dlg,access_dialog.h,access_dialog_template.c 三个文件,进入文件夹,将最后一个文件改成access_dialog.cpp并保存。
按之前帖子的方法建立一个DDL工程,注意目录放在UGII_USER_DIR下,名称也为Dialog_Access.将access_dailog.h和access_dialog.cpp复制到工程中,添加到头文件和源文件中。
基于UG/OPEN API的齿轮模块开发Ξ宋晓华,周明安(浙江工业大学浙机电系,浙江衢州 324004)摘 要:介绍使用U G/OPEN API开发U G环境下的齿轮自动生成模块。
以渐开线圆柱齿轮为例,在U G中建立基于表达式的部件模板,使用Visual C++编程,控制和改变表达式中的参数,调用U G/OPEN API函数,自动生成指定模数和齿数的齿轮。
关键词:U G;二次开发;参数化设计;齿轮中图分类号TP391.72 文献标识码A 文章编号:1007-4414(2004)06-0111-031 引言Unigraphics软件是目前应用最为广泛的大型CAD/CAE/ CAM集成化软件之一,其内容涵盖设计、分析、加工、管理等各个领域,它除了为用户提供零件建模、装配、有限元分析、运动分析、制图、数控加工编程等通用模块,还提供了各种专用模块,如工业设计、模具设计加工、钣金设计加工、管路设计等。
U G同样支持用户进行二次开发,根据特定的需求,创建出用户定制的、专用的U G功能模块,给用户的使用带来极大的方便,满足用户个性化的需要。
U G/OPEN API是U G用户最常用的二次开发工具,作为U G与外部应用程序之间的接口,U G/OPEN API是一系列函数的集合。
通过U G/OPEN API编程,用户几乎能够实现所有的Unigraphics功能,开发者可以通过用Visual C++编程来调用这些函数,从而达到实现用户化的需要。
2 齿轮模块开发概述在机械设备的传动系统中,由于齿轮传动平稳、适用范围广、寿命长等特点,因而被广泛使用。
利用U G/OPEN API开发U G环境下齿轮自动生成模块,用户只要通过接口界面输入齿轮的关键参数,如模数m及齿数z等,即可生成精确的齿轮模型。
这是在现代CAPP/DFA/DFM系统中对齿轮机构进行后续开发及研究,如虚拟装配、运动仿真、有限元分析及数控加工编程的基础。
齿轮模块的开发包括2部分:齿轮模板的建立及应用程序的设计。
编程基础[UGOpenAPI函数]1.1函数名称的约定UG/Open API 共有两类名称约定。
一个是标准的UG/Open API 的函数名称约定;另一个是以前版本原有的名称约定。
1、标准名称约定格式:UF_<area>_<name>说明:l UF_,user funciton的简写,表示该函数为UG/O pen API函数;l <area>,应用或模块的名称缩写。
例如modl和disp分别是Modeling模块和Display功能的名称缩写;l <name>,表示其实现功能的语言描述,一般由下划线分开的动词和名词(或词组)组成。
常用的动词有:ask(查询)、create (创建)、edit(编辑)、set(设置)、delete(删除)等。
例如:UF_MODL_create_block1()为创建立方体的函数;UF_DISP_set_highlight()是高亮显示对象的函数;(2)非标准名称约定格式:uc<xxxx> 和uf<xxxx>说明:代表UG/Open API C程序,<xxxx>通常是四位数或三位数接一个字母。
例如:uc1601是一个提示信息函数。
1.2 函数参数的约定UG/Open API提供的函数遵守ANSI/ISO C的标准,并以下列格式在头文件中提供函数原型:<返回数据类型><函数名>(变量列表);返回数据类型通常是C数据类型或UG/Open API自定义数据类型。
参数的输入输出方式有3种:I(Input)、O(Output)或OF (Output Free),说明见表3-1。
表3-1 参数输入方式说明例如:函数UF_PART_open()名称:UF_PART_open使用环境: internal & external语法格式:int UF_PART_open(char *part_name,tag_t *part,UF_PART_load_status_t *error_status);描述:加载一个UG部件文件到UG的界面环境中,并把它设为工作和当前显示部件,该函数的描述见表3-2。
【转载】利用UGOPEN开发定制CAM1 CAM用户界面操作流程叙述。
使用UGOPEN开展对CAM加工过程进行定制和开发,熟悉加工操作的一般过程和若干细节显得很有必要。
比如给个立方体,能把它上表面平面铣的刀轨生成,后置处理到G代码。
这样才好对其进行深入的研究。
UG加工的教程training说的很清楚了,我就不现眼了,见下图:看了NX的帮助,要是把加工模块的模板用好比做程序方便和实用多了,搞的我都不想做和写了。
一直排斥在CAM模块这搞什么二次开发,有时间多摸索用户界面的使用岂不是更好,把它玩熟练了,还怕什么。
要是达到L老师的境界就好了,我们娱乐是游戏啊逛街啊,他是玩NX看对应文档(就doc和cast),结合实际要做的东西细致的试验、验证和改造。
2 UGOPEN的CAM相关模块说明。
uf_setup:该模块允许开发人员配置与part文件关联的UF_SETUP对象。
它包括四个操纵组:UF_NCGEOM, UF_NCPROG, UF_NCMCT and UF_NCMTHD。
在UF_SETUP对象中设置的任何参数都会被与该UF_SETUP对象关联的part文件中的所有组和操作继承。
uf_ncgroup:该模块允许操作加工中的CAM UF_NCGROUPs,也就是加工相关对象的集合,即程序组(Program)、刀具(Tool)、几何体(Geometry)和工艺(Method)。
每个对象都是UF_OPER对象或者UF_NCGROUP对象。
完成的操作包括在UF_NCGROUP中对象查询、添加和是否已添加等操作。
UF_SETUP中包括的四个内建UF_NCGROUPs: UF_NCGEOM, UF_NCMCT, UF_NCPROG,and UF_NCMTHD都可以由UF_NCGROUP相关函数操纵。
uf_oper:该模块允许用户在加工操作作为UF_PARAM对象的时候,执行与在加工操作中执行的函数相比特别的函数。
UF_OPER条目存在于模板,特别是在Setup的Groups中。
UG-Open,GRIP——鲜为人知的二次开发编程随着科学技术的飞速发展,产品功能要求的日益增多,复杂性增加,寿命期缩短,更新换代速度加快。
然而,产品的设计,尤其是机械产品的设计,由于方案设计陈旧,更显得力不从心,跟不上新时代发展的步伐。
在NX设计过程中,以计算机作为重要工具,帮助工程师的一切实用技术的总和称为计算机辅助设计(CAD,ComputerAidedDesign)。
计算机辅助设计包括的内容很多,如:概念设计、优化设计、有限元分析、计算机仿真、计算机辅助绘图、计算机辅助设计过程管理等。
近年来CAD技术广泛应用于各个行业。
CAD 功能实现了目前制造行业中常规的工程技术、设计和绘画功能的自动化。
已从二维绘图普及到完全三维设计模型,从静态设计到运动仿真。
从传统制造应用到快速制造技术应用等方面发展。
而CAM功能却为使用Unigraphics设计模型描绘完成部分的现代机器工具提供了NC 编程技术。
在当今的科学时代,Unigraphics NX软件使用成为制造业、航天工业、汽车行业等多种行业的主流,凭借强大的混合式模型建立功能,已成为CAD/CAM最重要的组合性软件。
同时UG/Open GRIP语言逐渐受到UG NX(UnigraphicsNX4.0)使用者和NX编程工程师的欢迎,也成为Unigraphics NX软件必不可少的一部分。
1 Unigraphics NX(简称UG NX)软件介绍Unigraphics NX(简称UG NX)是当前世界上最先进和紧密集成的,面向制造行业的CAID/CAD/CAM/CAE高端软件,它为制造行业产品开发的全过程提供解决方案,功能包括:概念设计、工业设计、性能分析和制造。
Unigraphics NX是一个全三维,双精度系统,可以用它来精确地描绘几乎任何几何形状,将这些形状结合起来,就可以设计,分析产品以及绘图。
学机械专业、模具设计专业的朋友都知道,在大学学习计算机辅助设计软件是Auto*****和AutoCAD 2007,AutoCAD软件是大学最基础的软件,中级别的软件,现在仍然有些单位使用,AutoCAD画2D 特别方便,我们通常是配合起来使用的,但是Auto CAD就只有CAD 一个模块;而UG是高级别的软件,是专门画3D的,AutoCAD能画3D但是没有UG强,甚至还差的很远很很远。
Open C、Open C++和NXOpen C++混合开发作者:白途思ID:begtostudy三者的关系我在以前的文章中讲过了。
但是他们都不是孤立的,互相可以使用。
下面举了个不同部分用不同的代码,函数形式的是Open C,也就是API了类形式不带NXOpen的是Open C++,否则是NXOpen C++了。
Tag是所有之间的桥梁。
//NXOpen header files#include <NXOpen/Session.hxx>#include <NXOpen/Part.hxx>#include <NXOpen/PartCollection.hxx>//#include <NXOpen/Point.hxx>#include <NXOpen/Line.hxx>#include <NXOpen/CurveCollection.hxx>#include <NXOpen/Arc.hxx>#include <NXOpen/NXObjectManager.hxx>//#include <NXOpen/NXString.hxx>//UFunc Headers#include <uf_curve.h>#include <uf.h>#include <uf_csys.h>#include <uf_part.h>// UGOpen headers#include <ug_session.hxx>#include <ug_part.hxx>#include <ug_line.hxx>#include <ug_arc.hxx>#include <ug_coord_sys.hxx>#include <coord_sys.hxx>int main(int argc, char* argv[])...{int errorCode;/**//* Here, we can initialize session using :1. Open C API environment2. Open C++ API environment3. NX Open C++ APIs.User has to initialize, UG Session using Open C++ as well as NX Open C++, session also.*//**//* Using Open C API, we can initialize UGSession as follows *//**//*errorCode = UF_initialize();if ( 0 != errorCode ){return errorCode;}*/NXOpen::Part *part1;/**//* Using Open C++ API, we can initialize UGSession as follows */ UgSession::initialize();/**//* Using NX Open C++ API, we can initialize UGSession as follows */ NXOpen::Session *theSession = NXOpen::Session::GetSession();/**//* Create a new part.To create new part one can use :1. Open C API environment2. Open C++ API environment3. NX Open C++ APIs.*/char* partName = "InteropWithOpenCOpenCPPAndNXOpenCPP.prt";/**//* Using Open C API, we can create new part as follows *//**//*tag_t UF_partTag;UF_PART_new(partName,2,&UF_partTag);*//**//* Using Open C++ API, we can create new part as follows */UgPart *UGPart = UgPart::create(partName, Inches );/**//* Using NX Open C++ API, we can create new part as follows *//**//*NXOpen::NXString partName = "InteropWithOpenCOpenCPPAndNXOpenCPP.prt"; part1 = theSession->GetParts()->NewDisplay(partName, NXOpen::Part::UnitsInches); *///--------------------------------------------------------------------------// Interop between NX Open C++ APIs and Open C/**//* Create a line using NX Open C++ APIs*/NXOpen::Point3d point3d1(-2.17019791346668, 1.13935390457001, 0);NXOpen::Point3d point3d2(-0.714356813182783, 1.13935390457001, 0);NXOpen::Line *line1;line1 = theSession->GetParts()->GetWork()->GetCurves()->CreateLine(point3d1, point3d2);/**//* Retrieve line coordinates using Open C API */tag_t line_tag=line1->GetTag();UF_CURVE_line_t line_coords;UF_CURVE_ask_line_data(line_tag, &line_coords);//--------------------------------------------------------------------------// Interop between Open C++ and NX Open C++ APIsPoint3 UGPt1(line_coords.start_point[0]+5,line_coords.start_point[1]+5, line_coords.start_point[2]+5);Point3 UGPt2(line_coords.end_point[0]+5,line_coords.end_point[1], line_coords.end_point[2]);UgLine* UGLine;UGLine = UgLine::create(UGPt1, UGPt2);UgCoordSys *UGCoordsys;UGCoordsys = UgSession::getWCS();CoordSys Sys = UGCoordsys->getCoordSys();// Creating ArcUgArc* OpenCPPArc = UgArc::create(5.0, 0.25, 3.14, Sys);tag_t arc_tag = OpenCPPArc->getTag();NXOpen::Arc *nxArc = (NXOpen::Arc*)NXOpen::NXObjectManager::Get(arc_tag);double nxArc_radius = nxArc->GetRadius();double nxArc_start_angle = nxArc->GetStartAngle();double nxArc_end_angle = nxArc->GetEndAngle();//------------------------------------------------------------------------------------/**//* Save this work part.To save this work part one can use :1. Open C API environment2. Open C++ API environment3. NX Open C++ APIs.*//**//* Using Open C API, we can save this part as follows *//**//*UF_PART_save();*//**//* Using Open C++ API, we can save this part as follows *//**//*UGPart->save();*//**//* Using NX Open C++ API, we can save this part as follows *//**//* To get the part from the Part tag */part1 = (NXOpen::Part*)NXOpen::NXObjectManager::Get(UGPart->getT ag());/**//* To save work part using NXOpen automation APIs */NXOpen::PartSaveStatus *partSaveStatus;part1->Save(NXOpen::Part::SaveComponentsTrue, NXOpen::Part::CloseAfterSaveTrue, &partSaveStatus);/**//* To close all parts using NXOpen automation APIs */theSession->GetParts()->CloseAll(NXOpen::Part::CloseModifiedCloseModified, NULL);/**//* Terminate the session using Open C API */errorCode = UF_terminate();return 0;}。
OverviewOpen C API is designed to enable an easy interface between NX and the outside world. The Open C API consists of:∙ a large set of user callable functions/subroutines that access the NX Graphics Terminal, File Manager, and Database.∙command procedures to link and run user programs.∙an interactive interface in NX to run those programs.Open C API programs can run in 2 different environments, depending on how the program was linked. The two environments are:∙External - these Open C API programs are stand alone programs that can run from the operating system, outside of NX, or as a child process spawned from NX.∙Internal - these Open C API programs can only be run from inside of an NX session.These programs are loaded into main memory along side of NX and access routineswithin NX. One advantage to this is that the executables are much smaller and linkmuch faster. Once an Internal Open C API Program is loaded into memory, it can stay resident for the remainder of the NX session. If you call this program again, it executes without reloading (provided it was not unloaded). Internal Open C API programs work on the current part and automatically modify the part display.Most Open C API functions/subroutines can be used in either mode. There are only a few, mostly User Interface routines that are only supported in internal mode.The Open C API product is not intended to replace the Open C GRIP(GR aphics I nteractive P rogramming) product, but rather to make it easier to interface to NX from a high-level language such as C or C++. There are many tasks where a high-level language program is more appropriate.The Open C API product is explicitly defined in this manual. It is our intent to insulate the application programmer from changes in future NX software releases. Unfortunately, this is not always possible. Where this is not possible, every effort will be made to support existing routines for at least one release version of NX prior to obsolescence, and forewarn users of routines which will be changed in the future.When upgrading to a new release, programmers are expected to recompile and relink theirprograms. In addition, the release notes supplied with each release of NX describe changes that are important to Open C programmers.The release notes also describe what versions of the operating system and compiler were used to create the release of Open C API. Since operating systems, linkers, compilers,run-time libraries, etc., are usually updated by the hardware vendors more frequently than NX is released, there may be combinations that do not function correctly with Open C API. Additionally, compiling or linking may require different options other than those documented here. Refer to the Release Notes supplied with each release of NX for specific changes that may be necessary to use Open C API correctly.Example Source Code FilesMany of the routines that have example programs have the C source code files located inthe ugopen directory, which is a subdirectory of the directory pointed to by the variableUGII_ROOT_DIR. The source code files have a "ufd" prefix followed by a module name and a descriptive name. For example, ufd_curve_ask_spline_thru_pts.cis an example source code program that demonstrates the UF_CURVE_ask_spline_thru_pts function. The source code found in the ugopen directory should always be preferred over the example code documented in the Open C API Reference manual due to the possibility of any late changes to routines that may occur.Supported LanguagesOpen C API programs can be written in the C or C++ programming languages.Initialization and TerminationAll Open C API programs must be correctly initialized and terminated. You use the two C functions UF_initialize and UF_terminate to do this. After you have declared your variables the first Open C API function call must be UF_initialize. Your last function call mustbe UF_terminate. In external mode, you may only call UF_initializeonce.Once UF_terminate is called, there is no way to reconnect to the Open C environment. If you are using the Pre-NX4 Open C API license, UF_initialize andUF_terminate will allocateand deallocate the Open C API license. If you are using the new NX4 licensing scheme, the Open C API license is not required, but each function will require a specific modulelicense. For example, if you call UF_ASSEM_add_part_to_assembly you must have an Assemblies license. To view a current table of user functions and their associated licenses click here license_table.csvThere is a tool available to scan existing user function programs to determine which modulespecific licenses will be necessary to run the program with the new licensing system. Click here query_licenses to download this tool. Note that Perl is required to execute this tool from the command prompt. You can download the latest version of Perlfrom . Once you have Perl installed open a command prompt and navigate to the directory where you saved the query license tool. Type 'perl query_licenses.pl -h' to get started.Function RequirementsTo create geometry, cycle a model, or perform other elementary operations, you must first load an NX part file. Where routines operate on a particular type of tag, it is imperative that you pass the correct type of tag to the routine. For example, if you want to query the coordinates of a point, you must pass in a tag for a point - not the tag for a line or any other type of geometry. The above are error conditions in almost all routines. These error conditions are not repeated for each individual routine.Internal ProgramsMany Internal Open C API programs use the function ufusr as an entry point.The ufusr function acts as a main function.Internal Open C API programs can be thought of as a user written function to NX. To start execution of the program, NX loads the program into memory and then references the symbol ufusr. The user's program takes over execution at that point. At the end of execution, the program executes a return statement which returns control to NX. The Open C API Programmer's Guide describes how to build both internal and external programs and describes example files that are supplied in the Open C kit. See the "Basic Part File Query" chapter of the Open C API Programmer's Guide.The entry point into an Internal program is through a function/subroutine called ufusr./** internal C Open C API program** input* param - parameters passed into the Open C API program from* NX (Reserved for future enhancements)* parm_len - Length of param after implemented (may* not be needed on all platforms, see the* "Writing Open C API Programs" section)** output* retcod - User return code (future enhancement)*/#include <uf.h>/* Additional include files as required */void ufusr(char *param, int *retcod, int parm_len){/* statement declarations */UF_initialize();/* body */UF_terminate();}Once an executable is loaded into memory, it stays resident in memory with the NX session unless you use methods to unload the image (e.g. see the function ufusr_ask_unload inthe uf.h header file ).Automatic Part DisplayBecause internal Open C API programs are running in an NX environment, part display is automatically done. Object display can be suppressed and individual objects displayed with routines in the uf_disp.h header file suchas UF_DISP_set_display and UF_DISP_add_item_to_display.Under certain circumstances in Internal Open C API, a part must be active (e.g. geometry creation). The active part may be one that was previously opened interactively in NX or one retrieved in Open C API. UF_ASSEM_ask_work_part can be used to determine if a part is already active. Parts can be filed either from Open C API or in NX.External ProgramsExternal C programs use the standard C main function to call Open C API routines.See ext_uf_example.c in your installed Open C API directory for for an example external program.External Open C API programs are written, compiled, and linked like any normal program. Program statements for start up and termination should follow those normal for "C".External Model Terminal I/OAll terminal I/O should be done using the I/O statements supplied by the high-level language (e.g. C functions puts(), getchar(), printf(), etc.).If the External Open C API program is invoked from NX running on a terminal with windows, all high-level language I/O will appear on the window from which NX was started. This window may be hidden behind some of the other NX windows and must be "popped" to the top to be used. On Windows NT, there is not a terminal window associated with NX, so terminal I/O is not possible.No Part DisplayNo part display can or will be done in external mode. Any part created or modified by external Open C API programs will have to be retrieved in NX for display after the external Open C API has filed the part.Before any Database routines can be called, an existing part must be created or retrieved (UF_PART_new or UF_PART_open) to work on. Parts can be filedwithUF_PART_save, UF_PART_save_as, or UF_PART_save_all.Open C API ConventionsUnless otherwise noted, new Open C API functions are written in C and follow the ANSI C standard. Please refer to the Release Letter for information on new functionality and changes.Except where noted, all new Open C API functions follow a descriptive naming convention. The format is:UF_ABBR_descriptive_namewhere:UF_ denotes U nigraphics Open C API F unctionABBR_ is the abbreviation for the area the function representsdescriptive_name is a descriptive title giving a hint of the function's purposeAs an example:UF_PART_close_all A function that falls into the part manipulation application that closes all open parts.Database RoutinesThe Open C API has a large set of routines to create and modify NX objects. We assume that you are familiar enough with NX and the C language to prevent any serious mistakes. Some of the routines return an error code, others do not. The routines that create objects will return an Object Identifier = NULL_TAG to indicate an error.Variable DeclarationsOpen C API supports all C data types. Object Identifiers (EIDs) should be declared as tag_t to limit changes to your program.Character strings vary in length. The lengths documented in this manual are the maximum number of characters of data that are valid for either input or output by the routine.Data StructuresMany routines require data structures. In most cases the data structures are documented in the header file. However, there are some instances where a data structure is for internal use only or for proprietary usage and only a pointer to that structure is declared for the user.Include FilesThis documentation is organized by the header file that prototypes the functions. There are several include files provided for the users to add to their programs. The users should include uf_defs.h for general typedefs. The other include files should be used depending on the users application. These include files contain typedefdeclarations, ANSI prototypes of new routines and legacy code, and macros pertinent to the specified application.Error CodesUnless otherwise documented, every routine returns an int, which is the error code. A return code of 0 indicates success, and any other number indicates failure. The message associated with an error code can be retrieved by calling UF_get_fail_message.HandlesIn Unigraphics V9, when an object had a known object Identifier (EID), that EID was saved with the part and would be the same the next time the part was loaded. In V10 and beyond,because multiple parts can be loaded at once, the Tag (i.e. EID) of an object cannot be guaranteed between sessions. For this reason, "handles" were created to identify entities between sessions. To aid applications where the EID was saved in some data file between sessions, UF_ask_new_tag_of_object was created to return the post-V10 tag corresponding to the EID of an object in a V9 part that was just loaded. That tag can then be converted to a post-V10 handle using UF_TAG_ask_handle_of_tag.Legacy RoutinesSome Open C routines have been targeted to be removed from the released Open C libraries. Most of these routines are older routines that were originally used to support FORTRAN code. The legacy Removal Document lists these routines, and has information required to let almost all existing programs work without source code changes.How to Execute ProgramsYou execute Open C API programs by selecting the file name. After you have successfully compiled and linked your Open C API program perform the following steps:From within NX select File-->Execute-->NX Open. A list box displays the executable that you have previously successfully compiled and linked. If you execute externally written programs from within an NX session you cannot pass a command line argument. Additionally, you cannot perform operations on your current interactive part. You may wish to execute your external programs from the command line for these reasons.Compiling and Linking on Linux/Macos SystemsUfmenu is a utility script/command file that provides you with the ability to edit, compile, link and run your Open C API programs. ufcomp is a script that gives you the ability to compile programs, and uflink is a script that gives you the ability to link programs. These scripts are only supported on Linux and Macos workstations.See ufmenu details, ufcomp details and uflink details for more information.Compiling and Linking with a Linux MakefileOn on system that are not windows based systems, you can copy atemplate makefile (ufun_make_template.ksh) located in the${UGII_BASE_DIR}/ugopen directory, to compile and link your programs.The template makefile can be customized to compile and link: both internal and external, internal only, or external only Open C API programs. Instructions on how to use the template file are fully explained in the commented section of the file.After you have customized the template file, you should copy or move the file so that it is named either "Makefile" or "makefile", which are the standard names the make command expects. Alternatively, you could use the "-f" switch with the make command to specifythe makefile name.The template makefile was designed to be used with the make command supplied by the platform's vendor. For further information on make and file dependencies use "man make".Setting up your systemThis section describes the machine dependent information on how to setup and use Open C on your system. To use the Open C API, you must have the C or C++ environment setup on your workstation. If this environment is not set up, your system administrator must install it. For further details see:Windows Operating System SetupLinux SetupCompiler CertificationThe table listing the compilers for each supported platform can be found in the Product Notes under Automation. NX does not certify any other compilers for use with Open C programs. In general, the platform vendors must address any problems with a compiler newer than that which built NX. (See the Release Notes for OS levels that NX does certify.)Occasionally vendors obsolete compilers or create new compilers that are incompatible with the version that built NX. NX has no control over such developments, although the vendors usually have a vested interest in ensuring that newer compilers are compatible with the older versions.。
1.创建目录并配置环境变量(1)自定义创建。
创建一个文件夹如D:\UG_OPEN, 在此文件夹下创建二级文件夹D:\UG_OPEN\APPLICATION和D:\UG_OPEN\STARTUP。
打开UG安装目录下的UGII中ugii_env.dat文件,修改UGII_USER_DIR下的路径,如UGII_USER_DIR =D:\UG_OPEN,并去掉前面的“#”。
(2)第三方创建。
找到UG安装目录下的UGALLIANCE下的VENDOR文件夹,查看其下是否存在Application和Startup 文件夹,如果不存在则创建它们。
打开UG安装目录下的UGII中ugii_env.dat文件,将UGII_VENDOR_DIR前面的“#”去掉。
(3)系统自己创建。
找到UG安装目录下的UGALLIANCE下的SITE文件夹,查看其下是否存在Application和Startup文件夹,如果不存在则创建它们。
打开UG安装目录下的UGII中ugii_env.dat文件,将UGII_SITE_DIR前面的“#”去掉。
这三种方法的区别在于系统启动时加载的顺序不同,依次为site,vendor和用户自己定义的。
本文采用第一种方法。
2。
UIStyler设计(1)打开UG,进入UIStyler(主菜单Application下)。
(2)界面设计。
(3)保存至刚才建立的application文件夹下,此时会出现三个文件,如下图。
3。
建立VC项目(1)将刚才生成在application目录下的头文件和源程序移到VC工程所在的目录下,如D:\SOURCE。
(2)新建一个工程,选择Win32 DLL,选择创建空的DLL。
(3)将头文件和源程序加入工程。
4。
设置VC环境(1)选择菜单栏上的Project->Setting->C/C++,按下图进行设置,主要试讲头文件引入工程。
(2)选择菜单栏上的Project->Setting->LINK,按下图进行设置,将两个LIB库引入工程(UG 18以上适用)。
⼩⽩学UG⼆次开发_UGOpenUIStlyer对话框设计⼩⽩学UG⼆次开发 UGOpen UIStlyer 对话框设计本例参考《UG/Open API、MFC和COM 开发实例精解》黄勇,本例基本参照书中内容操作,没有做太⼤修改,能正常运⾏。
第⼀步,准备⼯作在UGII_USER_DIR⽬录⾥新建startup,application两个⽂件夹。
书中是这么说的,但是我只⽤到了application,startup我没有⽤到。
怎么设置环境变量我就不说了。
第⼆步,设计UI.UG 开始-》所有应⽤模块-》NX 6 之前版本UI样式编辑器选之前的版本主要为了降低开发难度。
进⼊UIStyler 对话框设计环境,新建⽂件。
⾥⾯有很多控件,⾃⼰试着点点看,探索下。
⾥⾯有对象浏览器,对话框和资源编辑器,对话框的标题和提⽰如下图所⽰,前缀名⽐较重要,直接关系到后续程序⽣成后的⼀些参数名称,我们这边设置为DIALOG_ACCESS。
设置如图所⽰的整数、实数、字符串和按钮控件,导航按键中按钮样式选项⾥选择的不同项会影响到后续的回调函数。
这⾥选择关闭。
整数,实数,字符串修改下标签和标识符。
这个会在对象浏览器⾥反应出来。
⽬前我还不会修改类型,就放着没管,如果有知道的,请帮忙解释下类型。
另外,我对回调函数的名称⽣成机制也不是很清楚,只是知道Back_cb应该是关闭对话框时触发的回调函数,action_3_act_cb 是按钮空间触发的回调函数,名字和书上不太⼀样,但是能正常实现功能。
完成后,另存为对话框到application,语⾔选C,对话框名称为access_dialog,在⽬录下会⽣成access_dialog.dlg,access_dialog.h,access_dialog_template.c 三个⽂件,进⼊⽂件夹,将最后⼀个⽂件改成access_dialog.cpp并保存。
按之前帖⼦的⽅法建⽴⼀个DDL⼯程,注意⽬录放在UGII_USER_DIR下,名称也为Dialog_Access.将access_dailog.h和access_dialog.cpp复制到⼯程中,添加到头⽂件和源⽂件中。
存档‘开发之路’分类的存档UG/ OPEN++类库2013年9月16日admin没有评论概述UG/Open++有五种不同的类:应用程序类,对象类,模板类,辅助类,和数学类。
1,应用程序类:控制UG应用程序的运行。
包括:UgSession,UgInfoWindow,和 UgException。
2,对象类:定义可以作用于UG零件文件中包含对象的属性和操作。
例如,UgArc,UgFace,和UgExpression等。
表示UG零件的UgPart类,也属此类。
3,模板类:提供平台无关的标准模板库(STL)类,主要用于数组和字符串。
还有一个遍历UG/Open++对象的模板类。
4,辅助类:定义用于其它类定义中的临时对象。
例如:ThruPoint和Evaluator类等。
5,数学类:包括通用数学对象。
与UG对象类结合使用,非常有帮助。
数学类包括点,向量,矩阵,坐标系等类。
通常情况下,每个类都定义在一个独立的头文件中,文件名是该类的名字。
例如UgArc类定义在ug_arc.hxx文件中。
有时一个头文件也包含诸如辅助类等的一些其它类定义。
在UG/Open++中,你可以任意调用一个类的公用方法,但不能调用其私有方法。
保护方法只能在导出类中调用。
●应用程序类对话期类(Session)UgSession类的一个主要作用是进行UG/Open的初始化。
这个初始化是在其它任何UG/Open++方法被调用之前必须进行的。
对话期的初始化和终止由两个静态方法完成,它们是UgSession::initialize ( )和 UgSession::terminate ( ):UgSession::initalize();// 你的 UG/Open++ 代码UgSession::terminate();另外一种方法是创建一个UgSession对象:UgSession mySession ( true );// 你的UG/Open++ 代码关于UgSession,有两个地方需要注意:1. UgSession析构方法将会自动结束UG/Open。
这在超出UgSession对象的作用范围之外时,将会自动发生。
2,当你用以下语法进行创建UgSession对象时,UG/Open的初始化将被阻止,并且析构方法也不能终止这个对话期:UgSession mySession;从功能上讲,上面提到的两种对话期初始化方法与传统的UF_initialize()方法是完全一样的,在程序的开始,可以使用任何一种方法,但不能同时使用两种不同方法。
这样在下面的程序中,UG/Open++和传统的UG/Open方法就可以被调用。
UgSession也可以用于控制当前UG对话期的状态和行为。
例如,一些UgSession的方法可以改变当前工作零件,修改层状态,以及关闭所有的零件等。
●对象类:对象类主要定义可以作用于UG零件文件中包含对象的属性和操作。
例如,UgArc,UgFace,和UgExpression等。
表示UG零件的UgPart类,也属此类。
大多数的UG/Open++应用程序都涉及对UG对象的操作。
对象类分为两种:基类和叶类。
基类定义作用于一组相关对象的通用操作,而且它们没有CREATE()方法。
叶类定义的是作用于某一特定类型物体的操作,而且大多数都定义了CREATE()方法。
基类表示一组类似的UG对象,而叶类表示一种具体的UG对象。
类的体系关系提供了充分的UG功能性的层次划分,用基类定义这类对象的公用的操作。
另外,在某些时候它利用多重继承来定义没有关系的对象的通用接口。
所有UG对象最顶层的基类叫做UgObject。
它定义了一些所有UG对象都可以使用的通用方法。
例如UgObject::askOwningPart ( )返回一个UG对象所在的零件。
其它基类都来自UgObject类的派生,包括UgTypedObject和UgDisplayableObject(注意绝大多数在UG/Open++中的基类都是以关键字`Object’结束命名的)。
UgTypedObject提供为UG物体命名或删除物体的方法,而UgDisplayableObject提供诸如更改颜色、图层等方法。
创建对象UG/Open++层次结构树的叶子,是真正代表具体UG对象的C++类,例如UgArc表示弧线,UgExpression代表表达式。
这些类叫做可实例类,因为可以创建这些类的C++对象,而且每个创建的对象都对应一个UG零件文件包含的UG对象。
要创建一个UG对象,只需调用创建对象的静态方法CREATE(),如下所示:UgPart *pWorkPart = UgSession::getWorkPart ( );UgExpression *pExpr;pExpr = UgExpression::create ( “diameter”, 4.25 , pWorkPart );double diaValue = pExpr->evaluate ( );UG对象都是用指针的方式被引用,而不是用对象名称,如上例中的pExpr。
事实上,C++的构造函数是一个保护方法,这样可以避免在不适当的地方错误调用该构造函数。
用指针引用减少了内存的使用,并且保证写出的C++代码与UG模型在任何时候都保持同步。
UgAssemblyNode类是一个没有CREATE()方法的叶类。
此类的对象创建是用UgPart::addPart ( ): UgPart *pWorkPart = UgSession::getWorkPart ( );UgAssemblyNode *pNode;pNode = pWorkPart->addPart ( “component.prt”, “”, “”,CoordSys ( ), -1 );一些类覆盖了静态的CREATE()方法,而用其它方法创建UG物体。
下面介绍三种创建表达式的方法:UgPart *pWorkPart = UgSession::getWorkPart ( );UgExpression *pExpr1, *pExpr2, *pExpr3;UgString strName ( “diameter1″ );pExpr1 = UgExpression::create ( “radius”, 4.25, pWorkPart );pExpr2 = UgExpression::create ( “diameter=2*radius”, pExpr1 );pExpr3 = UgExpressio n::create ( strName, “2*radius” );所有的create函数的最后一个参数都是一个选项参数,来指定零件上下文,也就是说新创建对象的宿主零件。
如果没有指定该参数,则属于当前工作零件。
这个参数既可以是一个指向零件对象的指针,也可以是一个指向属于该零件对象的其它对象的指针。
例如:UgPart *pOtherPart;// 初始化 pOtherPart 来指向一个可用的UG零件对象UgExpression *pExprNew;pExprNew = UgExpression::create(“length=3.0″, pOtherPart);权限控制当一个指向UG物体的指针被定义后,就可以用它来调用该类及其父类定义的所以方法。
例如,如果pArc 是一个指向UgArc的指针,那么就可以调用pArc的方法对该UG弧线对象进行查询或修改,代码如下所示:pArc->setRadius ( 2.5 );double len = pArc->computeArcLength ( );int layer = pArc->getLayer ( );上例中调用的三个方法都可以被UgArc对象调用。
但只有setRadius()方法在UgArc类中被定义,其它两个方法都是在其父类中定义的。
标志与指针转换UG/Open++允许开发代码中包含传统的UG/Open代码,并且进行相关的数据传递。
这就需要进行在UG/Open++的指针和UG/Open的标志之间进行转换。
UgObject::find ( ) 和 UgObject::getTag()两个方法可以完成此类转换。
UgObject::find ( )返回一个指向UgObject对象的指针,因此还需要进行类型的强制转换(请参考动态类型转换一节)。
例如:int color;tag_t tag1, tag2;// Call the traditional UG/Open function to select a line.// Note: this returns the tag of the selected line as `tag1′UF_UI_select_single ( …, &tag1, … );// Use the `find’ method to get the pointer of the Unigraphics// object corresponding to `tag1′UgObject *pObj = UgObject::find ( tag1 );if ( pObj ){UgLine *pLine = dynamic_cast <UgLine *> pObj;if ( pLine ){// Invoke a UG/Open++ method using that pointerpLine->setColor ( Red );// Now convert the pointer back to a tag (`tag2′).// Note that `tag1′ and `tag2′ should be identical.tag2 = pLine->getTag ( );// Call a traditional UG/Open function to get the color// using `tag2′ – it should be Red.UF_OBJ_ask_color ( tag2 , &color );}}从以上的例子可以看出,如果一个UG对象没有创建方法的话,UgObject::find ( )方法有可能返回0。
所以,一般来讲,对UgObject::find ( )返回的指针进行检查并进行强制类型转换很有必要。
这样可以确保无误。
零件UgPart类定义了UG零件的方法,包括创建新零件,打开已存在零件,零件存盘,关闭打开的零件等。
要注意的是关闭一个零件的方法属于UgPart类,而关闭所有零件的方法属于UgSession类。