UGOpen
UG的二次开发工具

5、UG/OPEN UIStyler模块
UlStyler是开发UG对话框的可视化编辑器,生成的对话框能与UG集成,让 用户更方便、更高效地与UG进行交互操作。利用这个工具可以避免复杂的图形用 户接口GUI的编程,直接进行对话框控件的选择和布局,从而创建能满足不同功 能需求的UG风格对话框。 当对话框创建完成后,会在存放的目录下自动生成3个文件.dlg文件, template文件和.h文件。其中:dlg文件是对话框资源文件,定义了对话框样式 及控件事件的响应函数名称,存放在用户创建的二次开发目录下面的 application文件夹内,供用户菜单调用;template文件是C语言源文件模板,它 包含了对话框所有回调函数的定义,提供了一个对话框应用的程序框架,该程序 框架通过调用UG/OPEN API函数,实现最初的对话框界面功能,在程序标明的位 置添加程序代码,编写回调函数就可以实现预先设定的功能;.h文件是对话框头 文件,它包含了对话框控件标识的定义以及控件事件响应函数原型的声明,供 VC++编写应用程序时使用。
UG/OPEN API函数采用标准的名称约定,其一般格式为:UF_<area>一 <name>,其中UF表示User Function;<area>表示函数的应用范围,通常是应 用范围名称的英文单词缩写。例如:MODL和ASSEM分别是Modeling建模模块和 Assembly装配模块的名称缩写,DISP则是DispIay功能的名称缩写:<name>表 示其实现功能的语言描述,一般由下划线分开的动词和名词组成。例: UF_MODL create—block0表示在modeling模块中创建立方体函数UF_DISP set highlight()是高亮显示对象的函数UF_PART_ask_part_name0是获取部件文件 名的函数,其他常用的动词还有edit(编辑)、delete(删除)。所有的API函数 及其相应的参数可以在UG的帮助文档里找到。
UG_OPEN_API

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和NXOpen

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);。
UGOPEN API教程

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的名称。
NX UGOPEN函数参考手册

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.。
ugopenapi教程

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二次开发 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 的齿轮模块开发

基于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部分:齿轮模板的建立及应用程序的设计。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
存档‘开发之路’分类的存档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类。