iLogic 提供了一些规则函数,用于设定或获取 Inventor 零件、部件和工程图文档的 iProperty。当使用规则将设计更改或修改为新配置后,保持设计文档的 iProperty 最新。iProperty 必须是最新的,以便 BOM 表是正确的。还可以使用规则读取文档的 iProperty 值并对这些值响应。例如,您可以使用规则在材料特性被更改后更改零件的厚度。如果零件的质量超过了最大值或最小值,规则可能会引发更改。使用规则可以设定或读取任何可以手动设定的 iProperty。
若要访问 iProperty 函数,请展开“代码段”区域中的“系统”选项卡下的“iProperty”节点。
语法
iProperties.Value("property tab name", "property name")
读取或设定包含规则的文档中的特性值。
iProperties.Value("filename.ipt", "property tab name", "property name")
在部件级规则中使用该函数,可以访问零件或子部件的 iProperty。
如果零件或子部件的文件名称进行了更改,规则文本也必须进行更改。
最好使用零部件名称(在自定义零部件名称之后),而不是文件名。
iProperties.Value("custom component name", "property tab name", "property name")
设定或读取零部件中的特性值。该函数使用零部件名称而不是文件名。自定义零部件名称(更改初始默认名称),以便该名称在文件参考发生更改时不发生更改。
示例
设定 iProperty 值:
iProperties.Value("Project", "Stock Number") = "302A"
读取 iProperty 值:
MyStringParam = iProperties.Value("Project", "Stock Number")
设定自定义 iProperty 值:
iProperties.Value("Custom", "Age") = 41 'number type iProperties.Value("Custom", "Company") = "Autodesk, Inc" 'text type iProperties.Value("Custom", "Date") = CDate("11/1/2008") ' date type iProperties.Value("Custom", "Insured") = true 'yes or no type
读取自定义 iProperty 值:
age = iProperties.Value("Custom", "Age") company = iProperties.Value("Custom", "Company") thedate = CStr(iProperties.Value("Custom", "Date")) insured = iProperties.Value("Custom", "Insured")
注意事项
Work_In_Progress = 1 Pending = 2 Released = 3 iProperties.Value("Status", "Design State") = Pending
过时的函数
以前的 iLogic 版本使用以下函数从部件中的零件获取 iProperty:
iProperties.ValueInDoc("filename.ipt", "property tab name", "property name")
参考文件名。
iProperties.ValueInComponent("custom component name", "property tab name", "property name")
参考零部件名称。
尽管“编辑规则”对话框的“代码段”区域中已不再包含这些函数,但是仍可以在规则中使用它们。但是,建议优先使用 iProperties.Value 函数而不是那些过时的函数。
该函数支持在不同语言版本的 Autodesk Inventor 中使用相同的文档。当您对规则中的材料和颜色使用英文名称时,模型的可移植性更强。如果您将该函数设置为 True,则用于返回任何材料或颜色名称的任何函数都返回英文名称。您可以使用以 Autodesk Inventor 安装语言表示的名称来设定材料或颜色名称。但是建议您使用英文名称以保持一致。当您将 iProperties.StylesInEnglish 值设置为 True 时,以下函数将返回英文名称。
设定或读取文档的材料。
设定材料时,请使用与激活的标准物理材质列表中所显示的名称完全一样的材料名称(区分大小写)。材料值始终为文本字符串,且包含在引号中。
示例
若要设定材料:
iProperties.Material = "Gold"
若要读取材料:
MyStringParam = iProperties.Material
通过指定文件名设定或读取部件中的零件材料。
在部件级规则中使用该函数,可以通过指定零部件名称访问部件中的零件材料。
设定或读取零件的当前颜色。零件颜色值是文本字符串,并包含在引号中。更改颜色不会影响当前的材料值。
该函数仅适用于零件。
示例
若要设定颜色:
iProperties.PartColor = "Green" iProperties.PartColor = "As Material"
若要读取颜色:
MyStringParam = iProperties.PartColor
读取或写入包含该规则的零件或部件文档的质量。
如果写入质量,写入值会替代计算的质量。若要恢复计算的值,请将质量设定为 -1。
iProperties.Mass(“filename.ipt”)
通过指定文件名,读取或写入部件中的零件或子部件的质量。
iProperties.Mass(“component name:1”)
通过指定零部件名称,读取或写入部件中的零部件的质量。还可以使用该函数读取或写入虚拟零部件的质量。
示例
若要读取质量:
MyMassParam = iProperties.Mass MyMassParam = iProperties.Mass("component:1") MyMassParam = iProperties.Mass("mypart.ipt")
若要设定质量(替代自动计算值):
iProperties.Mass = 3 kg iProperties.Mass("virtual_component") = 233 g iProperties.Mass("mypart.ipt") = 4.2 lb massiProperties.Mass = -1 'set the mass back to automatic calculation
读取或设定包含该规则的文档的体积。
iProperties.Volume(“filename.ipt”)
通过指定文件名,读取或写入包含该规则的零件或子部件的体积。
iProperties.Volume(“component:1”)
通过指定零部件名称,读取或写入部件中的零部件的体积。还可以使用该函数读取或写入虚拟零部件的体积。
示例
若要读取体积:
MyVolumeParam = iProperties.Volume MyVolumeParam = iProperties.Volume("component:1") MyVolumeParam = iProperties.Volume("mypart.ipt")
若要设定体积(替代自动计算值):
iProperties.Volume = 12.4 in^3 iProperties.Volume("virtual_component") = 542 cm^3 iProperties.Volume("mypart.ipt") = 12.8 in^3 iProperties.Volume = -1 'set it back to automatic calculation
读取包含该规则的文档中的模型重心。
语法
pt = iProperties.CenterOfGravity
pt 表示 Inventor.Point 类型,Inventor API 的帮助中对此进行了描述。您可以读取该点的 X、Y 和 Z 值(用规则文档的单位表示)。
cx = pt.X cy = pt.Y cz = pt.Z
pt = iProperties.CenterOfGravity("component")
通过指定零部件名称,读取部件中的零部件重心。
读取包含该规则的文档中的模型曲面面积。
语法
surfaceArea = iProperties.Area
surfaceArea = iProperties.Area(“component:1”)
通过指定零部件名称,读取部件中的零部件的曲面面积。