明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: yjwht

[源码] 电缆护套感应计算

[复制链接]
 楼主| 发表于 16 分钟前 | 显示全部楼层
再优化一下,合并DCL与LSP:
  1. (defun NP_DCL (/ Dcl_File file str)
  2.   (setq        file
  3.          (open
  4.            (setq tmp-dcl-file-name (vl-filename-mktemp nil nil ".DCL"))
  5.            "w"
  6.          )
  7.   )
  8.   (foreach str '("cable_calc : dialog {"
  9.                  "    label = \"电缆感应电动势计算\";"
  10.                  "    :boxed_column {"
  11.                  "        label = \"电气参数\";"
  12.                  "        alignment = centered;"
  13.                  "        :edit_box {"
  14.                  "            key = \"IA\";"
  15.                  "            label = \"正常工作电流(A):\";"
  16.                  "            value = \"100\";"
  17.                  "            width = 25;"
  18.                  "            fixed_width = true;"
  19.                  "            edit_limit = 10;"
  20.                  "        }"
  21.                  "        :edit_box {"
  22.                  "            key = \"L1\";"
  23.                  "            label = \"电缆分段长度(m):\";"
  24.                  "            value = \"100\";"
  25.                  "            width = 25;"
  26.                  "            fixed_width = true;"
  27.                  "            edit_limit = 10;"
  28.                  "        }"
  29.                  "        :edit_box {"
  30.                  "            key = \"GMRs\";"
  31.                  "            label = \"金属护套几何平均半径(mm):\";"
  32.                  "            value = \"50\";"
  33.                  "            width = 25;"
  34.                  "            fixed_width = true;"
  35.                  "            edit_limit = 10;"
  36.                  "        }"
  37.                  "    }"
  38.                  ""
  39.                  "    spacer_1;"
  40.                  "    ok_cancel;"
  41.                  "}"
  42.                  ""
  43.                  "  "
  44.                 )
  45.     (write-line str file)
  46.   )
  47.   (close file)
  48.   tmp-dcl-file-name
  49. )

  50. (defun c:tt (/ dcl_id dd p1 p2 p3 IA L1 GMRs m n S mS nS
  51.               Ea-x Ea-y Eb-x Eb-y Ec-x Ec-y)

  52.   ;; 在调用对话框前先指定三相电缆中心
  53.   (setq p1 (getpoint "\n指定A相电缆中心:"))
  54.   (setq p2 (getpoint p1 "\n指定B相电缆中心:"))
  55.   (setq p3 (getpoint p2 "\n指定C相电缆中心:"))

  56.   ;; 加载并显示对话框
  57.   (setq dcl_id (load_dialog (setq Dcl_File (NP_DCL))))
  58.   (vl-file-delete Dcl_File)
  59.   (if (not (new_dialog "cable_calc" dcl_id))
  60.     (progn
  61.       (alert "对话框加载失败!")
  62.       (unload_dialog dcl_id)
  63.       (exit)
  64.     )
  65.   )

  66.   ;;事件处理
  67.   (action_tile "accept" "(tt1)(done_dialog 1)")
  68.   (action_tile "cancel" "(done_dialog 0)")
  69.   
  70.   ;; 显示对话框并获取用户输入
  71.   (setq dd (start_dialog))
  72.   (unload_dialog dcl_id)

  73.   ;; 确定后计算并输出
  74.   (if (= dd 1)
  75.     (tt2)
  76.   )

  77.   (princ)
  78. )

  79. (defun tt1()
  80.     ;; 获取输入参数并转换为数值类型
  81.   (setq IA (atof (get_tile "IA"))
  82.         L1 (atof (get_tile "L1"))
  83.         GMRs (atof (get_tile "GMRs")))
  84. )

  85. (defun tt2()
  86.   ;; 绘制三相电缆中心线
  87.   (grdraw p1 p2 1 1)
  88.   (grdraw p2 p3 1 1)
  89.   (grdraw p1 p3 1 1)
  90.   
  91.   ;; 计算距离参数
  92.   (setq S (distance p1 p2)
  93.         mS (distance p2 p3)
  94.         nS (distance p1 p3)
  95.         m (/ mS S)
  96.         n (/ nS S))
  97.   
  98.   ;; 计算各相感应电动势分量
  99.   (setq Ea-x (* pi IA 0.00001 (log n) (sqrt 3) L1)
  100.         Ea-y (* pi IA 0.00001 (log (/ (* n S S) (* GMRs GMRs))) L1)
  101.         Eb-x (* pi IA 0.00001 (log (/ mS GMRs)) (sqrt 3) L1)
  102.         Eb-y (* pi IA -0.00001 (log (/ S (* m GMRs))) L1)
  103.         Ec-x (* pi IA -0.00001 (log (/ mS GMRs)) (sqrt 3) L1)
  104.         Ec-y (* pi IA -0.00001 (log (/ (* n nS) (* m GMRs))) L1))

  105.   ;; 格式化输出结果
  106.   (princ "\n===== 电缆感应电动势计算结果 =====")
  107.   (princ (strcat "\nEa = " (rtos Ea-x 2 2) "+" (rtos Ea-y 2 2) "i(V)"))
  108.   (princ (strcat "\nEb = " (rtos Eb-x 2 2) (rtos Eb-y 2 2) "i(V)"))
  109.   (princ (strcat "\nEc = " (rtos Ec-x 2 2) (rtos Ec-y 2 2) "i(V)"))
  110.   (princ "\n====================================\n")

  111.   (princ)
  112. )
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-13 20:23 , Processed in 0.148735 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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