/***************************************************************************** Exports the specified objects to the specified part. The objects are copied into the destination part. Any other transferable objects upon which the given objects depend are also exported. Note that the export operation fails if there is no display part. NOTE: Object occurrences and part occurrences are not exportable. If an object depends on another object which is not exportable, then that object is not exported and a warning value of UF_PART_warn_objects_not_copied is returned. However, the operation continues, and other requested exportable objects are still exported. This situation can arise in two circumstances. 1. A drafting object is not exported if its associated geometry is not exported. 2. Datums cannot be exported if feature parameters are removed. If any other error occurs, the operation does not succeed and the appropriate error code is returned. Environment: Internal and External See Also: UF_PART_export History: For V14.0, the behavior of this function was modified as follows: If you are exporting geometry to a part which is loaded (or partially loaded) in a session, then that part is no longer saved and closed as a consequence of calling this routine. The destination part is only saved and closed as part of this operation if it was not loaded beforehand. This makes the Open API behavior consistent with the interactive behavior. For V14.0.1, the behavior of this function was modified as follows: When exporting geometry using this function, the geometry would not be oriented properly in the destination part if the WCS of the source part was away from the origin. This is now fixed so that the geometry is transformed from the WCS of the source part to the WCS of the destination part. The Open API behavior is now the same as the interactive behavior. For V15.0, this function was modified as follows: The UF_PART_maintain_all_params enumerated constant was added to UF_PART_export_params_mode_t. ****************************************************************************/ extern UFUNEXPORT int UF_PART_export_with_options( const char * part_name ,/* <I> Name of part to export objects to. */ int num_objects ,/* <I> Number of objects in object_array to be exported. */ tag_t object_array[] ,/* <I,len:num_objects> Objects to be exported. */ UF_PART_export_options_p_t options /* <I> Pointer to struct containing options to control how the objects are exported. */ ); 说一说这个函数怎么用
时间: 2025-04-12 17:17:39 浏览: 72
<think>嗯,用户问的是关于UF_PART_export_with_options函数的使用方法。首先,我需要理解这个函数的功能。根据文档,这个函数用于将指定对象导出到目标部件,并且会复制这些对象。同时,如果这些对象依赖其他可转移的对象,那些依赖项也会被导出。不过需要注意,对象实例和部件实例是不能导出的。
接下来,用户可能想知道如何正确调用这个函数,以及有哪些参数需要设置。我要分步骤解释函数的参数和用法。首先,函数需要目标部件的名称,然后是对象数组及其数量,还有选项结构体。
选项结构体UF_PART_export_options_p_t是关键部分,需要详细说明每个字段的作用。比如params_mode控制参数处理方式,layer_mgmt处理图层管理,还有是否允许提升特征等。同时,必须提醒用户注意导出前的环境检查,比如目标部件是否已加载,以及如何处理依赖项的问题。
历史记录部分提到不同版本的变化,比如V14.0之后对已加载部件的处理,V14.0.1修复了坐标系的变换问题,V15.0新增了参数模式。这些版本差异可能会影响用户的使用,特别是如果他们使用的NX版本较旧的话,需要注意兼容性。
用户可能在实际使用中遇到哪些常见错误呢?例如,导出失败可能是因为没有显示部件,或者尝试导出不支持的对象类型。需要给出错误处理的建议,比如检查返回值和警告代码,处理依赖对象不可导出的情况。
另外,示例代码对用户理解会有很大帮助。应该展示如何初始化选项结构体,填充参数,调用函数,并处理可能的错误。同时,提醒用户需要包含必要的头文件和链接库,确保编译环境正确。
最后,注意事项部分需要强调坐标系转换、依赖对象处理、版本兼容性等,帮助用户避免常见陷阱。可能需要解释WCS变换的具体影响,以及如何处理不可导出的对象导致的警告。</think>以下是对`UF_PART_export_with_options`函数的详细使用说明:
---
### **功能概述**
此函数用于将指定对象导出到目标部件,并自动复制其依赖的可转移对象。**注意**:对象实例(Object occurrences)和部件实例(Part occurrences)不可导出,且依赖项若不可导出会触发警告。
---
### **函数参数解析**
```c
int UF_PART_export_with_options(
const char *part_name, // 目标部件文件名(需包含完整路径)
int num_objects, // 待导出对象的数量
tag_t object_array[], // 待导出对象的tag数组
UF_PART_export_options_p_t options // 导出选项控制结构体
);
```
---
### **关键参数详解**
#### 1. `options` 结构体 (`UF_PART_export_options_p_t`)
控制导出行为,需初始化以下字段:
```c
typedef struct UF_PART_export_options_s
{
UF_PART_export_params_mode_t params_mode; // 参数处理模式
UF_PART_export_layer_mgmt_t layer_mgmt; // 图层管理策略
logical allow_promotion; // 是否允许提升特征(TRUE/FALSE)
} UF_PART_export_options_t;
```
- **`params_mode`**:参数处理方式(枚举值)
- `UF_PART_remove_all_params`:移除所有参数(生成非参数化几何)
- `UF_PART_maintain_all_params`:保留所有参数(需目标部件支持)
- **`layer_mgmt`**:图层策略(枚举值)
- `UF_PART_original_layers`:保持原始图层
- `UF_PART_work_layer`:放置到目标部件的工作图层
- **`allow_promotion`**:是否允许提升特征(如基准面)
---
### **使用步骤**
1. **环境检查**
- 确保当前会话存在显示部件(否则操作失败)
- 目标部件若未加载,函数会自动保存并关闭;若已加载,需手动管理
2. **准备参数**
- 初始化`options`结构体,按需求配置参数模式、图层策略等
- 收集待导出对象的`tag_t`数组(需过滤掉不可导出类型)
3. **调用函数**
```c
int status = UF_PART_export_with_options(
"/path/to/target_part.prt",
num_objs,
obj_tags,
&options
);
```
4. **错误处理**
- 检查返回值:
- `0` = 成功
- `UF_PART_warn_objects_not_copied` = 部分对象未导出(依赖项问题)
- 其他值需通过`UF_get_fail_message()`获取详细错误
---
### **示例代码片段**
```c
#include <uf_part.h>
void export_objects_example()
{
// 初始化选项
UF_PART_export_options_t options;
options.params_mode = UF_PART_remove_all_params;
options.layer_mgmt = UF_PART_work_layer;
options.allow_promotion = TRUE;
// 假设已获取待导出对象tags
tag_t obj_tags[] = {tag1, tag2};
int num_objs = 2;
// 调用导出函数
int status = UF_PART_export_with_options(
"C:/parts/target.prt",
num_objs,
obj_tags,
&options
);
// 处理结果
if (status == UF_PART_warn_objects_not_copied) {
// 警告:部分对象未导出(检查依赖项)
} else if (status != 0) {
// 处理其他错误
}
}
```
---
### **注意事项**
1. **坐标系转换**
V14.0.1后,几何体会从源部件的WCS自动转换到目标部件的WCS(与交互操作一致)
2. **依赖项限制**
- 若草图的关联几何未导出,则草图本身不会被导出
- 若特征参数被移除,基准(Datums)可能无法导出
3. **版本兼容性**
- V15.0+ 支持`UF_PART_maintain_all_params`模式
- V14.0+ 已优化对已加载部件的处理逻辑
---
如需进一步调试,建议结合`UF_PART_ask_export_errors()`获取详细错误列表。
阅读全文