现在,我们已设定了构造模型和计算零件代号必需的所有参数值。我们要撰写的最后一个规则会将与此文件关联的零件代号以及其他参数值传递到 Excel 电子表单。其中的某些零件代号包含在 iPart 中,而螺钉零件代号则是由此规则生成的。
update_excel_spreadsheet_rule 可利用“编辑规则”对话框“代码段”区域中“Excel 数据链接”类别中所提供的一组函数。
此规则可根据模型状态填充必要的单元格。在电子表单中,要向其中传递数据的所有单元格已经命名,从而与要撰写的信息相对应。
GoExcel.CellValue("part_number.xls", "Sheet1", "Block_Type") = component_type GoExcel.CurrentCellValue("Block_Style") = block GoExcel.CurrentCellValue("Block_Part_Number") = iProperties.Value("manifold_block:1", "Project", "Part Number")
在此部分中,我们将参考此教程项目附带的 part_number.xls 电子表单文件。然后设定 Block_Type、Block_Style 和 Block_Part_Number 单元的值。前两个值是根据部件参数设定的,最后一个值是根据块的“零件代号”iProperty 设定的。
GoExcel.CurrentCellValue("port_a_size") = port_a_size If block = "tee" Then GoExcel.CurrentCellValue("port_b_size") = port_b_size Else GoExcel.CurrentCellValue("port_b_size") = "N/A" End If GoExcel.CurrentCellValue("port_c_size") = port_c_size
请注意我们是如何对弯头样式集成块使用 N/A 占位符值的。
GoExcel.CurrentCellValue("block_depth") = Parameter("manifold_block:1", "block_depth") GoExcel.CurrentCellValue("block_width") = Parameter("manifold_block:1", "block_width") GoExcel.CurrentCellValue("block_height") = Parameter("manifold_block:1", "block_height")
请注意此部分中对 manifold_block:1 零部件的参考。
GoExcel.CurrentCellValue("port_a_union_cap") = port_a_union_part_number GoExcel.CurrentCellValue("port_a_screw_kit") = port_a_screw_part_number If block = "tee" Then GoExcel.CurrentCellValue("port_b_union_cap") = port_b_union_part_number GoExcel.CurrentCellValue("port_b_screw_kit") = port_b_screw_part_number Else GoExcel.CurrentCellValue("port_b_union_cap") = "N/A" GoExcel.CurrentCellValue("port_b_screw_kit") = "N/A" End If GoExcel.CurrentCellValue("port_c_union_cap") = port_c_union_part_number GoExcel.CurrentCellValue("port_c_screw_kit") = port_c_screw_part_number
就像规则的前一部分中的 port_b_size 一样,注意对 Port B 相关值的条件控制。
GoExcel.Save