NX二次开发UF_MODL_export_udf 函数介绍

221 阅读7分钟

UF_MODL_export_udf

Defined in: uf_modl_udf.h 
int UF_MODL_export_udf(char * * ip_prompts, char * * ip_names, int number_of_elements, UF_FEATURE_SIGN sign )

overview 概述

Exports a user defined feature part. Note that you must use the UF_MODL_boolean_udf to actually perform the Boolean operation specified by the sign parameter.

User Defined Features (UDFs) allow you to define the shape and function of features. This gives you the ability to create a library of features tailored to your needs.

Four Open API routines provide support for the creation of User Defined Features. These routines generally reflect the interactive UDF functionality. Please see user-defined features in the Modeling User Manual for more information and examples. The Open API routines are UF_MODL_export_udf, UF_MODL_import_udf, UF_MODL_set_udf_parms and UF_MODL_boolean_udf. In addition, there is one inquiry routine UF_MODL_ask_udf_parms.

All UDFs must be predefined (created) and saved as a user-defined feature file. You use the UF_MODL_export_udf to create the file. You retrieve a UDF using UF_MODL_import_udf and use UF_MODL_set_udf_parms to change the predefined feature parameters and UF_MODL_boolean_udf to make the UDF part of your model. You can also use the relative position routines (see UF_MODL_register_rpo and UF_MODL_unregister_rpo) to position your UDF on your part.

To create a UDF file, you must first create a model using the existing functions (Open API, GRIP, or interactively). This entire model, including expressions, is the new UDF you wish to define. The UDF must be created in the absolute coordinate space. The origin (0,0,0) is considered the feature's origin.

After the geometry is defined, you use UF_MODL_export_udf to create a user feature output file. The UDF file contains the geometry as well as information on the input parameters (i.e. those parameters that you let other users change when the UDF is brought into their parts) and the attachment method.

The UDF file has the same name as the part name but with the ".udf" extension. For example, if your part name were "name_of_file.prt", then the udf file name would be "name_of_file.udf". Input parameters are those parameters you wish to be entered during the creation of a model as a feature. The input parameters are specified by the ip_prompts, ip_names, and number_of_elements arguments.

All variables not entered as input variables become constants or they can be controlled using expressions established before saving the UDF file. For example, let's say your UDF consists of a block where p0 represents the width, p1 represents the length, and p2 represents the height. You have determined that you wish the width and length to be specified when bringing in the UDF, but you wish the height to always be the width plus twice the length.

In your creation of the block, you would have predefined p2 = p0 + 2p1. But you need to specify to the UFD file that p0 and p1 are the input parameters. You specify the variables or expressions in the ip_names argument. You can alias these expressions using the ip_prompts arguments.

When specifying the input parameters when importing the UDF, you set the parameters using the alias prompt name. An error occurs if you specify variables that do not exist in the model and the UDF file is not created. In our preceding example, you would specify the inputs parameters as follows: int number2 = number_of_elements = 2; char ip_prompts[number2] = { "width", "length" }; char ip_names[number2] = { "p0", "p1" };

You specify the attachment method that the UDF is to perform when brought into your model. The options are create, add, subtract, and intersect (UF_NULLSIGN, UF_POSITIVE, UF_NEGATIVE, and UG_UNSIGNED respectively).

After the feature is saved, you need to specify data when bringing the UDF into your part. With UF_MODL_import_udf, you specify the udf part file name and the destination csys and point. The routine returns the tag of the UDF. The destination csys is the orientation in which the feature is brought into the part. The destination point is the location at which the system places the origin of the UDF.

UF_MODL_set_udf_parms sets the values for UDF predefined parameter names (prompts). An error results if you provide an incorrect parameter name. You can use UF_MODL_ask_udf_parms to inquire the names and current setting of the input parameters.

Finally, you use UF_MODL_boolean_udf to specify the planar face on the UDF (tool body) that is to be placed directly on the planar body (target body). You also need to determine what is the x-direction on the planar tool face to define the coordinate system for the relative positioning constraints. The normal to the planar tool face is the z-axis and is used with the x-direction to fully specify the relative positioning dimension coordinate system. Before applying the boolean, you may wish to register the relative position to allow you to specify the position of the udf. If the attachment method is "create," then you do not need to specify the planar faces. However, you must call UF_MODL_boolean_udf for every imported UDF regardless of the type of Boolean operation performed.

Note: This routine works only with old-style Pre-V15 UDFs


导出用户定义的特性部件。注意,您必须使用 UF _ MODL _ Boolean _ udf 来实际执行由 sign 参数指定的 Boolean 操作。用户定义特性(UDF)允许您定义特性的形状和功能。这使您能够创建适合您需要的特性库。四个开放 API 例程提供对创建用户定义特性的支持。这些例程通常反映交互式 UDF 功能。有关更多信息和示例,请参见建模用户手册中的用户定义特性。Open API 例程包括 UF _ MODL _ export _ udf、 UF _ MODL _ import _ udf、 UF _ MODL _ set _ udf _ parms 和 UF _ MODL _ boolean _ udf。此外,还有一个查询例程 UF _ MODL _ ask _ udf _ parms。所有 UDF 都必须预定义(创建)并保存为用户定义的特性文件。使用 UF _ MODL _ export _ udf 创建文件。使用 UF _ MODL _ import _ UDF 检索 UDF,使用 UF _ MODL _ set _ UDF _ parms 更改预定义的特征参数,使用 UF _ MODL _ boolean _ UDF 使 UDF 成为模型的一部分。您还可以使用相对位置例程(参见 UF _ MODL _ register _ rpo 和 UF _ MODL _ unregister _ rpo)来定位您的 UDF。要创建 UDF 文件,必须首先使用现有函数(Open API、 GRIP 或交互式)创建模型。包括表达式在内的整个模型就是您希望定义的新 UDF。UDF 必须在绝对坐标空间中创建。原点(0,0,0)被认为是特征的原点。定义几何图形之后,使用 UF _ MODL _ export _ udf 创建用户特性输出文件。UDF 文件包含几何图形以及关于输入参数的信息(例如,当 UDF 被引入到其他用户的部分时,您允许其他用户更改的那些参数)和附件方法。UDF 文件的名称与部件名称相同,但是具有“。扩展。例如,如果您的部件名是“ name _ of _ file。“ prt”,那么 udf 文件名就是“ name _ of _ file”。”。输入参数是您希望在创建模型时作为一个特性输入的参数。输入参数由 ip _ mpts、 ip _ name 和 number _ of _ element 参数指定。所有未作为输入变量输入的变量都成为常量,或者可以使用在保存 UDF 文件之前建立的表达式控制它们。例如,假设您的 UDF 由一个块组成,其中 p0表示宽度,p1表示长度,p2表示高度。您已经决定,希望在引入 UDF 时指定宽度和长度,但是希望高度始终是宽度加上长度的两倍。在创建块时,应该预定义 p2 = p0 + 2p1。但是您需要向 UFD 文件指定 p0和 p1是输入参数。可以在 ip _ Names 参数中指定变量或表达式。您可以使用 ip _ tips 参数为这些表达式起别名。在导入 UDF 时指定输入参数时,可以使用别名提示名设置参数。如果指定了模型中不存在的变量,并且没有创建 UDF 文件,则会发生错误。在我们前面的例子中,您可以指定如下输入参数: int number2 = number _ of _ element = 2; char ip _ mpts [ number2] = {“ width”,“ length”} ; char ip _ names [ number2] = {“ p0”,“ p1”} ; 您可以指定 UDF 在引入模型时要执行的附件方法。这些选项包括创建、添加、减少和交叉(分别为 UF _ NULLSIGN、 UF _ POSITIVE、 UF _ NEGATIVE 和 UG _ UNSIGNED)。保存特性之后,在将 UDF 引入到您的部分中时,需要指定数据。使用 UF _ MODL _ import _ udf,可以指定 udf 部件文件名以及目标 csys 和 point。该例程返回 UDF 的标记。目标 csys 是将特征引入到零件中的方向。目标点是系统放置 UDF 原点的位置。UF _ MODL _ set _ UDF _ parms 设置 UDF 预定义参数名称(提示)的值。如果提供不正确的参数名称,则会导致错误。可以使用 UF _ MODL _ ask _ udf _ parms 查询输入参数的名称和当前设置。最后,使用 UF _ MODL _ boolean _ UDF 指定将直接放置在平面主体(目标主体)上的 UDF (工具主体)上的平面面。你还需要确定平面工具面上的 x 方向是什么,以确定相对定位约束的坐标系。平面工具面的法线是 z 轴,与 x 轴一起用来完全指定相对定位尺寸坐标系。在应用布尔值之前,您可能希望注册相对位置,以允许您指定 udf 的位置。如果附件方法是“ create”,则不需要指定平面面。但是,对于每个导入的 UDF,必须调用 UF _ MODL _ Boolean _ UDF,而不管所执行的 Boolean 操作的类型如何。注意: 这个例程只适用于旧式的 Pre-V15 UDF

UFUN例子

获取源码例子请搜索 里海NX二次开发3000例专栏

parameters 参数

char * *ip_promptsInputPointer to array of pointers to ip prompts.
指向 ip 提示的指针数组的指针。
char * *ip_namesInputPointer to array of pointers to ip variable names.
指向指向 ip 变量名的指针数组的指针。
intnumber_of_elementsInputNumber of elements in array.
数组中的元素数。
UF_FEATURE_SIGNsignInputThe attachment method sign. Valid options: UF_NULLSIGN = 0, create new target solid UF_POSITIVE = 1, add to target solid UF_NEGATIVE = 2, subtract from target solid UF_UNSIGNED = 3 intersect with target solid
附件方法符号。有效选项: UF _ NULLSIGN = 0,创建新的目标固体 UF _ POSITIVE = 1,添加到目标固体 UF _ NEGATIVE = 2,减去目标固体 UF _ UNSIGNED = 3与目标固体相交