明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 889|回复: 3

[基础] 如果几个控件的动作一样,那么怎样写代码简洁?

[复制链接]
发表于 2024-4-21 23:06:51 | 显示全部楼层 |阅读模式
  如果几个控件的动作一样,那么怎样写代码简洁?本人菜鸟求助,如下例


  •   (action_tile"HR_H" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_I" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_QI" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_[" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_Q[" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_EQANG" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_UEQANG" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"H" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_T" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_P" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))
  •   (action_tile"HR_TUB" (strcat "(setq $HRSType $key)" "(WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)" "(HRS_READ_DATA)" "(HRS_FILL_Size_LIST)" "(HRS_FILL_DES_LIST)"))


这11个按钮的动作一样.谢谢

发表于 2024-4-22 00:32:52 | 显示全部楼层
(foreach Key '("HR_H" "HR_I" "HR_[" "HR_Q[" "HR_EQANG" "HR_UEQANG" "HR_T" "HR_P" "HR_TUB")
  (action_tile Key "(setq $HRSType $key)
                    (WriteREGvalue \"HRSECTION\" \"SelectedTYPE\" $key)
                    (HRS_READ_DATA)" "(HRS_FILL_Size_LIST)
                    (HRS_FILL_DES_LIST)
                   "
  )
)
回复 支持 3 反对 0

使用道具 举报

发表于 2024-4-22 18:47:19 | 显示全部楼层
  1. (defun abc ()
  2.   (setq $HRSType $key)
  3.   (WriteREGvalue "HRSECTION" "SelectedTYPE" $key)
  4.   (HRS_READ_DATA)
  5.   (HRS_FILL_Size_LIST)
  6.   (HRS_FILL_DES_LIST)
  7. )
  8. (foreach a '("HR_H" "HR_I" "HR_QI" "HR_[" "HR_Q[" "HR_EQANG" "HR_UEQANG" "H" "HR_T" "HR_P" "HR_TUB")
  9.   (action_tile a (abc))
  10. )
 楼主| 发表于 2024-4-22 20:12:27 来自手机 | 显示全部楼层
多谢两位,学习了。回头看看我写的那个,惨不忍睹!啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 20:56 , Processed in 0.179031 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表