UG/NX二次开发实用入门教程(共3节)

(1)_PartsUG 对象类型及操作

所有的UG对象类型都通过它们唯一的标识tag来引用,这些UG对象分类如下:

 Parts  UF objects(uf_object_types.h中说明的)  Expressions(表达式) 对每一类对象,都有UG/OPEN API中明确的函数对它们进行操作。

Parts 对每一个加载到UG环境中的part文件,都有一个关联的part object代表它, 也为每一个part object分配一个tag(标记符)。 一个UG part 文件 (以 .prt扩展名的二进制文件 ) 是UF objects, expressions, and Parasolid objects永久保存之地。

另外UG part 文件还包含下列内容:

 创建part的计算机类型

 保存part的UG版本

 part的历史 (i.e. a log of when the part was saved, by what program, etc.)  状态、描述和用户区的可永久保存在part文件中的信息。

 在part中查询objects。

对Parts操作的函数

UF_OBJ_cycle_objs_in_part

  •  访问part的属性。

UF_ATTR_ask_part_attrs 

  • 关闭和再打开part。

UF_PART_close 和 UF_PART_reopen

  •  获取part的文件名。

UF_PART_ask_part_name

  •  查询其它信息。

UF_PART_ask_customer_area, UF_PART_ask_description, UF_PART_ask_status

  •  设置状态、描述等信息。

UF_PART_set_customer_area, UF_PART_set_description, UF_PART_set_status

  •  查询part的历史。

UF_PART_ask_part_history 等

  •  compressing parts。

UF_PART_ask_compression_flags 和 UF_PART_set_compression_flags

装配意义下的part对象

装配概念和术语

在装配环境中总保持只有一个part是当前活动的,它叫work part. 用户创建的所有UF对象、表达式等都是在work part中创建。

此外还有一个叫display part的概念. 在UG的某一应用(如Modeling)时display part 和 work part 可以不同。

一个装配件(assembly part)包含components(组件). Components 是其它的UG的parts 并且这些parts可以被装配在它们自己中。 Components 通过 instances 在 assembly 中存在。

instance 描述component在assembly中的方位(父子关系)。

例如: if we have a car that has two axle sub-assemblies (a front and a rear) and each axle sub-assembly has two wheels (a left and a right), then the car assembly has two instances of the axle sub-assembly, and the axle sub-assembly has two instances of wheel. The instances of the axle sub-assembly in the car describe how to position the axles in the car. The instances of the wheels in the axle sub-assembly describe how to position the wheels in the axle sub-assembly.

另外还有part occurrences。part occurrence 描述在全局的assembly中怎样定位一个单独的component。

For example: in the car assembly above, there would be four part occurrences for the wheels. The part occurrence in the car for the right front wheel would be created from the combination of the orientation of the front axle to the car and the orientation of the right wheel to the axle.

Instances 和 part occurrences 也是由tags标识。 特别地,它们是UG对象中UF object中的part类: instance 是 UF_occ_instance_type,part occurrence是UF_component_type,UF_part_occurrence_subtype.因此, instance和part occurrences 共享 适用于 UF objects的函数。

  •  查询display part 或 work part 。

UF_PART_ask_display_part 和 UF_ASSEM_ask_work_part

  •  设置 display part 或 work part 。

UF_PART_set_display_part 和UF_ASSEM_set_work_part

These routines set the display or work part. There is a side effect when the display part is set and restrictions on setting the work part:

  1. As a byproduct of setting the display part, Unigraphics resets the work part at the same time. There is one exception to this rule: if the new display part contains the old work part and the Retain Work Part assembly preference is set, the work part does not change as a result of this action.
  2. You are not allowed to set the work part in interactive Unigraphics while in certain application modules. If an application module does not support setting the work part in interactive Unigraphics, you cannot set the work part using UF_ASSEM_set_work_part.
  •  增加一个 part 到一个 assembly中。

UF_ASSEM_add_part_to_assembly [对存在的part] 或 UF_ASSEM_create_component_part [对新的 part]

  •  从一个 occurrence tag 得到part tag。

UF_ASSEM_ask_prototype_of_occ

  •  在一个part中查找 instances。

UF_ASSEM_cycle_inst_of_part

(2)_UF Objects对象类型及操作

UF Objects

UG中的大部分公共对象都是头文件uf_object_types.h中定义的对象. 所有这些对象都有明确的函数与它们对应,只有特定的对象子类和displayable UF objects有另外的函数与它们对应。

UF Objects的共性和对应函数

所有 UF objects 拥有下列的共有信息:

  •  a type — uf_object_types.h文件中列出了所有类。一个对象的类型可通过函数 UF_OBJ_ask_type_and_subtype查询出来。
  •  a subtype — uf_object_types.h文件中列出了所有子类。不是所有的对象都使用子类。
  •  a status – 通过使用函数 UF_OBJ_ask_status可查出对象的状态。对象共有下列几种状态: 
    •     UF_OBJ_DELETED 。
    •     UF_OBJ_TEMPORARY -例如临时坐标系由UF_CSYS_create_temp _csys函数创建,不会被保 存。
    •    UF_OBJ_CONDEMNED -一般由于对象被删除,但它是其他对象的参考,只有所有的这些参考 被删除后,该对象才从模型中删除。 该状态的对象永远不被显示。
    • UF_OBJ_ALIVE 。

对UF objects 可用的方法有:

  •  访问或指定单个对象的名称 (使用 UF_OBJ_set_name, UF_OBJ_ask_name, and UF_OBJ_delete_name)
  •  遍历 (使用 UF_OBJ_cycle_objs_in_part, UF_OBJ_cycle_all, 和 UF_OBJ_cycle_by_name)

注意: 因为UG中对象的存储方式的独特, 函数UF_OBJ_cycle_objs_in_part 比函数 UF_OBJ_cycle_all、UF_OBJ_cycle_by_name和UF_LAYER_cycle_by_layer更有效。因此建议使用UF_OBJ_cycle_objs_in_part而不是函数UF_OBJ_cycle_all、 UF_OBJ_cycle_by_name和UF_LAYER_cycle_by_layer

  •  分配和访问 attributes (头文件 uf_attr.h中的所有函数)

Attributes 两个不同的组成部分: a title and a value.

Title的长度要小于 UF_ATTR_MAX_TITLE_LEN

Attributes类型表:

1

UF_ATTR_time 属性由两个整数组成,第一个整数是日期表示从1970年1月1日到当前的天数,第二个整数表示时间,可用函数uc4583 (见头文件 uf_cfi.h) 计算这两个整数,用函数uc4582(见头文件 uf_cfi.h)从这两个整数得到代表时间及日期的字符串。

上表中的UF_ATTR_reference属性的value随着表达式P1的变化而变化。该属性的语法格式如下:

<(x|X)m(.|,)n@exp_name

“<(x|X)” – 大小写均可,格式的标识。

“m(.|,)n” –m标识域宽,n标识小数点后的精度,有点类似C语言中的real型数据格式。

@exp_name – 以@开始的部分是表达式名称。

“>”- 结束标志。

在上例中, if P1 = 13.579, DIAMETER = 13.58.

Displayable UF Objects

使用函数UF_OBJ_is_type_displayable 来检测UF Objects是否属于Displayable UF Objects。

  •  Displayable UF Objects的独特信息和函数

所有displayable UF objects 除了有UF objects的特性外,还包括下列信息:

层 – 对象所在的当前层(1-255)。

颜色 – 对象的当前颜色,可以是下列15种颜色之一:

1

blank状态: UF_OBJ_BLANKED 或 UF_OBJ_NOT_BLANKED。

线宽 – 对象当前被指定的线宽:UF_OBJ_WIDTH_NORMAL、UF_OBJ_WIDTH_THICK 和 UF_OBJ_WIDTH_THIN。

字形 — 对象当前被指定的字形: 1 - 7。

高亮状态 — 对象当前的高亮状态:一个逻辑变量。

所有以上信息可以在一单个的结构中:UF_OBJ_disp_props_t,得到该结构的函数是: UF_OBJ_ask_display_properties。

使用displayable UF objects的函数。

设置displayable UF objects信息的函数: UF_OBJ_set_layer, UF_OBJ_set_color, UF_OBJ_set_blank_status, UF_OBJ_set_line_width, UF_OBJ_set_font, UF_DISP_set_highlight

除了高亮状态外,其它信息都可以保存到part文件中。

显示对象 ,函数UF_DISP_add_item_to_display增加一个新的对象到UG的 显示窗。

附加的查询函数 UF_LAYER_cycle_by_layer。

选择对象,使用函数UF_UI_select_single、UF_UI_select_by_class、UF_UI_select_feature或UF_UI_select_sketch。

这些函数让用户在UG的交互环境中从UG的图形窗口选择对象UF_UI_select_by_class 显示类型选择对话框。

其它函数见头文件uf_obj.h。

  •  装配意义下的Displayable UF Objects

装配件是特殊类型的Part,装配件中的parts也叫 components(组件),component可以是装配件,也可以是普通part文件。 一个part在同一装配件中可以有多次出现,每次都有不同的位置和方位。装配件中不包含其组件的几何,而是包含occurrences(事件),occurrence表示了组件的几何是如何定位,定向的,occurrence指向的真实几何叫prototype(原型)。

Occurrences 的行为很象它指向的原型,它们可以被显示、被选择、被引用,甚至可以通过某种方式被修改(如:改变颜色、增加属性等),这一特性使用户可以改变一个occurrence的外观,而不影响它的原型及同一装配件中的其它occurrence。如果一个occurrence没有被编辑(例如:改变颜色等),也没有被引用,那么它不被保存到装配件文件中,它是暂时的,每次加载装配件时被重建。反之,它是永久被保存的。

(3)_表达式 对象类型及操作

UG/Open API 创建的表达式和画ug的交互界面产生的表达式同样在‘表达式编辑器’中可见。

我们知道表达式提供UG中的参数化建模的机制,表达式能控制特征,特征也随表达式的变化而改变。一个表达式可在多个特征中使用,这样它的变化将能改变多个特征。

表达式的形式一般是: “name=value”。

表达式名的首字符必须是字母,其它字符可以是数字、字母、下画线等。表达式名是大小写敏感的。一个part文件中的表达式名应唯一。下面是一些合法和不合法的表达式名:

length  Valid

3sides    Invalid (begins with a numeric)

three_sides Valid

表达式值可以是数字和条件等式,表达式名可以用于表达式值中。下列是一些表达式值的例子: “Length = 0.5 + 2 * cos (angle)”

“position = if(width <= 2) (0.5 * width) else (2)”

表达式的使用

一般说来表达式的使用函数都在头文件 uf_modl.h中定义。

如果你表达式串中,仅仅提供表达式值

ug会自动给它一个名字。如你的表达式串定义如下: “diameter / 2” UG会赋给它一个类似 “p0″的名字。当然我们建议按下列形式赋值:”radius = diameter / 2”

你可以用函数 UF_MODL_create_exp 创建表达式。

其它的使用表达式的函数:

  •  UF_MODL_dissect_exp_string. 分解名字和值返回名字、值和表达式的标签。 
  • UF_MODL_ask_exp. Return a name-value pair for an expression from its name. 
  • UF_MODL_eval_exp. Evaluate an expression’s name and return its value.
  •  UF_MODL_edit_exp. 用新的值替换表达式中原有的值。 使用后应用函数 UF_MODL_update来更新模型。
  •  UF_MODL_rename_exp. Give an existing expression a new name.
  • UF_MODL_ask_exps_of_feature. Returns the tags of all the expressions that control a feature. 
  • UF_MODL_ask_exps_of_part. Returns the tags of all the expressions in a part.
  • UF_MODL_ask_exp_tag_string.

为您推荐

返回顶部
首页
电子图书
视频教程
搜索
会员