MicroStationCONNECT Edition 帮助

比较关键字

以下关键字描述包括关键字函数的简要介绍、受关键字影响的元素类型(如果适用)、有效数据类型(如果适用)以及有关如何使用关键字的示例。

注释: “赋值关键字”部分中的 Characters 关键字可用于比较语句。有关 Characters 关键字的详细信息,请参见“赋值关键字”部分。

angle

angle 关键字指定单元、文本节点、椭圆、弧和文本等元素类型的角度。对于其他元素类型,角度值为 0.0。

数据类型:0.0 到 360.0 范围内的实数

示例:

!
! Change the color of text
! elements rotated 90 degrees.
!
if ((type == text) and (angle == 90.0)) then
	 color = 2
endif

area_fill

area_fill 关键字检查当前元素是否被填充。

数据类型:常量(true 或 false)

示例:

!
! Change the fill color of all filled elements.
! Do not alter elements that are not filled.
!
if (area_fill == true) then
	 fill_color = 10
endif

cellname

如果当前元素是单元头或单元的组件,则 cellname 关键字指定单元的名称。对于嵌套在一个或多个单元中的组件,cellname 关键字指定最外层单元的名称,除非组件是嵌套的单元头。在这种情况下,cellname 关键字是嵌套单元的名称。如果当前元素不是单元头或不是单元的组件,则 cellname 的值为“NO_CELL”。可以使用通配符比较字符串是否相等。

注释: 要查找最深层单元的名称,请使用 nested_cellname 关键字。

数据类型:字符串

示例:

!
! Change the color of all components of the cell
! named "border."
!
if (cellname == "border") then
	 color = (200,200,200)
endif

characters

如果当前元素是文本元素,则 characters 关键字指定元素中包含的字符串。可以使用通配符比较字符串是否相等。

数据类型:字符串

示例 1:

!
!Highlight any text strings that contain the string
!'School' or 'Hospital'.
!
if ((type == text) and (characters =='*School*')) then
	color = (0,0,255)
else if ((type == text) and (characters =='*Hospital*')) then
	color = (255,0,0)
endif

示例 2:

!
!Removes the text "preliminary" if it appears in
!"border" file.
!
if ((lname=="border") and (characters=="preliminary")) then
	 ignore_element=true
endif

class

class 关键字指定当前元素的类类型。例如,当前元素的类可用于设计脚本中以确定当前元素是否是尺寸标注或图案的一部分。

数据类型:0 到 6 范围内的整数,或以下常量之一:

0 primary
1 pattern_component
2 construction
3 dimension
4 primary_rule
5 linear_pattern
6 construction_rule

示例:

!
!Do not plot pattern and dimension class elements.
if ((class == pattern_component) or (class == dimension)) then
	 ignore_element = true
endif

cls_end_width

cls_end_width 关键字测试与当前元素相关联的自定义线型的结尾宽度(采用主设计文件单位)。如果当前元素没有关联的自定义线型,则 cls_end_width 为 0.0。

数据类型:实数

示例:

!
! Change the color of all elements with
! a custom line style whose ending
! width is greater than 2 master design units.
!
if (cls_end_width > 2.0) then
	 color = 5
endif

cls_name

cls_name 关键字测试与当前元素相关联的自定义线型的名称。对于没有关联的自定义线型的元素,cls_name为“NONE”。

数据类型:字符串

示例:

!
! Change the color of all elements using the style.
! Assign the "origin" custom line style to all
! other elements.
!
if (cls_name == '{ Diamond }') then
	 color = 2
else
	 cls_name = "origin"
endif

cls_origin_width

cls_origin_width 关键字测试与当前元素相关联的自定义线型的起始宽度(采用主设计文件单位)。如果当前元素没有关联的自定义线型,则 cls_origin_width 为 0.0。

数据类型:实数

示例:

!
! Change the color of all elements with a
! custom line style whose starting
! width is greater than 2 master design units.
!
if (cls_origin_width > 2.0) then
	 color = 5
endif

cls_scale

cls_scale 关键字测试应用于与当前元素相关联的自定义线型的比例因子。如果当前元素没有关联的自定义线型,则 cls_scale 为 1.0。

数据类型:实数

示例:

!
! Change the color of all elements with a
! custom line style whose scale is 2.
!
if (cls_scale == 2.0) then
	 color = 5
endif

cls_shift_distance

cls_shift_distance 关键字测试应用于与当前元素相关联的自定义线型的移位距离(采用主设计文件单位)。如果当前元素没有关联的自定义线型,则 cls_shift_distance 为 0.0。

数据类型:实数

示例:

!
! Change the color of all elements with a
! custom line style whose shift
! distance is 0.5 master design units.
!
if (cls_shift_distance == 0.5) then
	 color = 5
endif

cls_shift_fraction

cls_shift_fraction 关键字测试应用于与当前元素相关联的自定义线型的移位分数。如果当前元素没有关联的自定义线型,则 cls_shift_fraction 为 0.0。

数据类型:实数

示例:

!
! Change the color of all elements with a
! custom line style whose shift
! fraction is 0.25.
!
if (cls_shift_fraction == 0.25) then
	 color = 5
endif

color

color 关键字指示当前元素的颜色索引。

数据类型:0 到 255 范围内的整数

示例:

!
! Area fill shapes with a color index of 1.
!
if ((color == 1) and (type == shape)) then
	 area_fill = true
endif

envr_value

envr_value 关键字用于对通过设置 envr_variable 赋值关键字选择的打印定义环境变量的值进行比较。如果变量尚未设置或不是有效变量,则 envr_value 将设置为零长度字符串。

数据类型:字符串

示例:

!
!Get the value of the print definition environment variable
!ARCHITECT. Find text element with characters
!equal to "$Architect$" and change the text value
!to "Designed by <name>" if ARCHITECT is equal to 
!"Owner1" or "Owner2." Otherwise, change the text
!value to a blank string.
!
envr_variable = "ARCHITECT"
if((type ==text) and (characters == "$ARCHITECT$")) then
 if (envr_value .IN. "Owner1", "Owner2") then
		 characters = "Designed by " + envr_value
	else
		 characters = "" 
	endif
endif

envr_value_num

envr_value_num 关键字用于对通过设置 envr_variable 赋值关键字选择的打印定义环境变量的值进行比较。如果 envr_variable 尚未设置或不是有效变量,则 envr_value_num 将返回实数零。

数据类型:实型

示例:

!
!Get the value of the print definition environment variable
!MYCOLOR. If the value of “MYCOLOR” is greater than
!5, set the weight to 2.
!
envr_variable = "MYCOLOR" 
if(envr_value_num gt 5) then
		 weight = 2
endif

file

file 关键字指定正在处理的文件的文件连接编号。通常,主文件是编号 0 的连接。从命令行生成图元文件将打印每个参考文件的文件名及其连接编号。

数据类型:整型

示例:

! If the current element is in the master file
! (index of 0), change its color to 2.
!
if (file == 0) then
	 color = 2
endif

fill_color

fill_color 关键字指示当前元素的 fill_color 索引。在元素未填充的情况下,fill_color 返回值 -1。

数据类型:-1 到 255 范围内的整数

(其中 -1 指示元素没有 fill_color)

示例:

!
! Shapes with a fill color index of 1
! will be plotted red.
!
if ((fill_color == 1) and (type == shape)) then
	 fill_color = 'red'
endif

示例:

!
! Do not plot shapes that are
! not filled.
!
if ((fill_color == –1) and (type == shape)) then
	 ignore_element = true
endif

first_time

first_time 比较关键字让您执行某段设计脚本一次。在第一次调用设计脚本时,此关键字(标志)为 TRUE,然后该值设置为 FALSE。该值无法重置。当您指定书签模板时此关键字会很有用。请参见本部分结尾处的示例。

注释: 当系统处理设计脚本时,将以自上而下的顺序处理设计文件中的每个元素,直到各个元素处理完毕。如果设计文件中的第一个元素执行 first_time 代码片段,系统将处理剩余的元素,但这些元素将跳过 first_time 代码片段。

font

对于文本和文本节点,font 关键字包含当前元素的字体编号。对于文本和文本节点以外的元素,字体编号为零。

数据类型:0 到 255 范围内的整数

示例:

!
! Do not plot text elements that use font 10.
if ((type == text) and (font == 10)) then
	 ignore_element = true
endif

font_name

对于文本和文本节点,font_name 包含当前元素的字体名称。对于文本和文本节点以外的元素,字体名称为“NO_FONT_NAME”。

数据类型:字符串

示例:

!
! Change the color of all text elements
! using the "architectural" font.
if ((type == text) and (font_name == 'architectural')) then
	 color = 'gray'
endif

header_level

header_level 比较关键字返回属于复杂元素组件的元素的顶级父层。例如,假设您在设计文件中有一个共享单元的两个实例:一个实例放在层 2,另一个实例放在层 3。共享单元定义包含层 1 上的单个形状元素。在两个几何图形之间进行区分的唯一方法是父层。您可以在设计脚本中使用 header_level 关键字将命名颜色“red”应用于层 2 上的共享单元。

数据类型:整型

示例:

!
! Change the color of a shared cell on level 2.
!
if ((header_type == shared_cell) and (header_level == 2)) then
	color = 'red'
endif

header_level_name

header_level_name 比较关键字返回属于复杂元素组件的元素的顶级父层。例如,假设您在设计文件中有一个共享单元的两个实例:一个实例放在层 A,另一个实例放在层 B。共享单元定义包含层 C 上的单个形状元素。在两个几何图形之间进行区分的唯一方法是父层。您可以在设计脚本中使用 header_level_name 关键字将命名颜色“red”应用于层 A 上的共享单元。

数据类型:字符串

示例:

!
! Change the color of a shared cell on Level A.
!
if ((header_type == shared_cell) and (header_level_name == 'Level A')) then
	 color = 'red'
endif

header_type

header_type 关键字确定作为单元或共享单元组件的元素的最外层复杂头类型。如果当前元素不是单元或共享单元的一部分,则 header_type 关键字的值与元素的类型相同。

数据类型:对应于有效头元素类型的整数或以下常量之一:cell 或 shared cell

示例 1:

!
! If the current element is a component of a cell,
! change its weight to 2.
!
if (header_type == cell) then
	 weight = 2
endif

ip_scale_num

ip_scale_num 关键字获取数字形式的打印定义比例。无论 MS_PLT_SCALE_METHOD 如何设置,该数字始终以主单位/打印单位的形式返回。例如,如果“打印”对话框中显示的缩放比率是主单位:打印单位,并且您的比例设置为 2:1,则单值数字比例因子将为 2.0/1.0 或 2.0。

数据类型:实数

示例:

!
! Plot line thickness based on the print definition scale.
!
if (ip_scale_num ==2) then
!large drawing use thick lines
	thickness = (weight +1) * .02
else
!small drawing use thinner lines
	 thickness = (weight +1) * .01
endif

ip_xsize_num

ip_xsize_num 关键字获取数字形式的打印定义 x 大小。

数据类型:实数

示例:

!
! Plot line thickness based on the print definition xsize.
!
if (ip_xsize_num > 17) then
	 !large drawing use thick lines
	 thickness = (weight +1) * .02
else
	 !small drawing use thinner lines
	 thickness = (weight +1) * .01
endif

ip_ysize_num

ip_ysize_num 关键字获取数字形式的打印定义 y 大小。

数据类型:实数

示例:

!
! Plot line thickness based on the print definition ysize.
!
if (ip_ysize_num > 17) then
	 !large drawing use thick lines
	 thickness = (weight +1) * .02
else
	 !small drawing use thinner lines 
	 thickness = (weight +1) * .01
endif

level

level 关键字包含当前元素的层号。

数据类型:大于或等于零的整数

示例:

!
! Set the color of the element based on its level.
!
if (level == 1) then
	color = 1
else if (level == 2) then
	 color = 2
endif

level_name

level_name 关键字包含当前元素的层名称。可以使用通配符比较字符串是否相等。

数据类型:字符串

示例:

!
! Set the color of the element based on its level.
!
if (level_name == "floor1") then
	 color = 1
else if (level_name == "floor2") then
	 color = 2
endif

lname

如果当前元素位于参考文件中,则 lname 关键字包含参考文件的逻辑名称。如果当前元素位于主文件中,则 lname 关键字将求值为空字符串 ("")。可以使用通配符比较字符串是否相等。

数据类型:字符串

示例:

!
! Change the weight of all elements in the
! reference file with the logical name of
! "border" to be a weight of 2. Elements in
! the master file and other reference
! files will not be changed.
!
if (lname == 'border') then
	 weight = 2
endif

model_format

model_format 关键字允许您对以下模型格式中的元素进行操作:DGN7、DGN8、DWG 或 DWF。

数据类型:常量(DGN7、DGN8、DWG 或 DXF)

示例:

!
! Apply a different screening percentage for
! each model format.
!
if (model_format == DGN7) then
	 screening = 20
else if (model_format == DGN8) then
	 screening = 30
else if (model_format == DWG) then
	 screening = 40
else if (model_format == DXF) then
	 screening = 50
endif

nested_cellname

如果当前元素是单元头或单元的组件,则 nested_cellname 关键字指定单元的名称。对于嵌套在一个或多个单元中的组件,nested_cellname 关键字指定最深层单元的名称。如果当前元素不是单元头或不是单元的组件,则 nested_cellname 关键字的值为“NO_CELL”。可以使用通配符比较字符串是否相等。

注释: 要查找最外层单元的名称,请使用 cellname 关键字。

数据类型:字符串

示例:

!
! Change the weight of all components of the nested
! cell named "FRAME."
!
if (nested_cellname == 'FRAME') then
	 weight = 3
endif

properties

properties 关键字提供了两种方法来确定是否设置了元素的属性字中的位。例如,以下两个关系表达式是等效的:

if(hole == true) then if(properties == hole) then
. .
. .
. .
endif endif

数据类型:以下常量之一:

attributes
hole
locked
modified
new_element
nonplanar
nonsnappable
screen_relative

示例:

!
! Do not plot any element with the screen_relative
! bit set in the properties word.
!
if (properties == screen_relative) then
	 ignore_element=true
endif

size

对于文本元素,size 关键字是文本字符串的高度。对于所有其他元素,size 关键字是元素的 X、Y 或 Z 范围中的最大值。

数据类型:工作单位

示例:

!
! Change the color of text elements whose height is 
! greater than 4 subunits.
!
if ((type == text) and (size > 0:4:0)) then
	 color = 3
endif

style

style 关键字包含当前元素线型的值。如果线型早在设计脚本中通过 style 关键字设置,则线型将求值为新线型,而不是元素的原始线型。此外,如果已使用命名线型或过渡来设置元素的线型,则 style 比较关键字将不会反映这一点。它将求值为当前线型索引。

数据类型:0 到 7 范围内的整数

示例:

!
! Change the color of any element not on level 1 
! that has a line style of 7.
!
if ((level<>1) and (style == 7)) then
	 color = 2
endif

tag 关键字

tag 关键字检查连接到当前元素的标记数据。如果标记数据未连接到当前元素,则 TAG_CHARACTER 关键字求值为“NO_TAG_CHARACTER”,而 TAG_INTEGER 和 TAG_REAL 求值为 NO_TAG_NUM。

以下是 tag 关键字的简要描述、数据类型和示例。

Tag_display 检查是否显示特定类型的标记。
Tag_character 测试实际标记的值。
Tag_integer 测试实际标记的值。
Tag_real 测试实际标记的值。
注释: tag_character、tag_integer 和 tag_real 比较关键字必须与 tag_set 和 tag_name 赋值关键字一起使用。

数据类型:

tag_character 字符串
tag_display 常量(true 或 false)
tag_integer 整型
tag_real 实数

示例:

!
! Assuming the design file uses two tag sets,
! "Home address" and "Work address," each
! containing a character tag named "City,"
! change the color of all elements whose tags
! specify a home address of "Huntsville" or a
! work address of "Madison."
!
! Start by looking for "City" tags belonging to
! the "Home address" tag set.
!
tag_set = 'Home address'
tag_name = 'City'
if (tag_char == 'Huntsville') then
	 color = 4
endif
! Now look for tags in the "Work address"
! tag set.  Note that the tag name is still "City".
tag_set = 'Work address'
if (tag_char == 'Madison') then
	 color = 4 
endif

text_node_number

text_node_number 比较关键字可以用于测试文本节点复杂元素的文本节点编号。

数据类型:整型

示例 1:

!
! Change the color of text associated with a specific
! text node number.
!
if (text_node_number eq 46) then
	 color = 3
endif

示例 2:

!
! This design script sets a plot sheet attribute
! based on the characters stored in a text node element
! in the design file. This sheet attribute can be used
! as attribute date in a digital archive.
if (text_node_number eq 10) then
	 envr_variable = "Author"
	 envr_value = envr_value + " " + characters
else if (text_node_number eq 11) then
	 envr_variable = "Title"
	 envr_value = envr_value + " " + characters
endif

type

type 关键字确定当前元素的元素类型。

数据类型:对应于有效元素类型的整数或以下常量之一:

arc (type 16) line_string (type 4)
assoc_dim (type 33) mesh (type 105)
bspline_curve (type 27) multiline (type 36)
bsplne_surface (type 24) shape (type 6)
cell (type 2) shared_cell (type 35)
complex_shape (type 14) solid (type 19)
connected_string (type 12) surface (type 18)
curve (type 11) text (type 17)
ellipse (type 15) text_node (type 7)
line (type 3)  

示例:

!
! Change the color of lines, linestrings, and curves
! on level 1
!
if ((type in 3,4,11) and (level == 1)) then
	 color = 1
endif
注释: 要测试多线和关联尺寸标注元素,请使用 header_type 而不是 type。

weight

weight 关键字包含当前元素线宽的值。

数据类型:0 到 31 范围内的整数

示例:

!
! Set color of element based upon its weight
!
units = inches
if (weight == 0) then
	  color = 1
else if (weight == 1) then
	  color = 2
else if (weight == 2) then
	 color = 3
else if (weight == 3) then
	 color = 4
else if (weight == 4) then
	 color = 5
else if (weight == 5) then
	 color = 6
endif

width

width 关键字仅适用于二维线、线串、椭圆、弧和连接的字符串。所有其他元素和三维元素的线宽值为 0。线宽值从元素的 Z 低范围字段中提取,并以工作单位指定元素的线宽,而不是线宽值。

数据类型:工作单位

示例:

!
! Change the color of lines, linestrings, connected
! strings, arcs, and ellipses based on their width. 
!
units = inches
if (type .in. 3,4,12,15,16) then 
	if (width  == 0:0:050) then 
		 color = 1
	else if (width == 0:0:100) then 
		 color = 2
	else if (width == 0:0:150) then
		 color = (30,50,100)
	else if (width == 0:0:200) then
		 color = (100,0,0)
	else if (width > 0:0:300) then
		 color = (0,0,0)
 endif
endif