明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1785|回复: 4

[已解答] 大侠帮忙看看这个dcl触发按钮动作哪里错了?

[复制链接]
发表于 2014-8-15 16:47:21 | 显示全部楼层 |阅读模式
  1. (defun c:dt()
  2.   (Form1_load)
  3. )

  4. (defun Form1_load( / dcl_id Dialog_Return key keys Dcl_File)
  5.   (vl-load-com)
  6.   (setq dcl_id (load_dialog (setq Dcl_File

  7. (Write_Dcl_Form1))));对话框加载
  8.   (vl-file-delete Dcl_File);加载后删除DCL文件
  9.   (setq Dialog_Return 2)
  10.   (while (> Dialog_Return 1) ;循环控制对话框是否结束
  11.     (new_dialog "Form1" dcl_id);建立窗体
  12. ;-->-->-对话框初始化->-->--
  13.     (setq keys '("Command1" "accept" "cancel"));列表全

  14. 部控件名称
  15.     (foreach key keys;全部控件的初始化
  16.       (if (eval (read (strcat key "_bak")))

  17. (set_tile key (eval (read (strcat key "_bak")))));控件内容
  18.       (action_tile key "(Action_Form1_Keys $key

  19. $value)");点击动作
  20.     )
  21. ;--<--<-对话框初始化完成-<--<--
  22.     (setq Dialog_Return (start_dialog));开启对话框(用

  23. 户可见)
  24.   )
  25.   (unload_dialog dcl_id);退出时卸载对话框
  26.   (princ);防止函数回显
  27. )

  28. (defun Action_Form1_Keys (key value) ;全部控件的点击动作触发
  29.   (cond
  30.     ((= key "accept") ;{确认按钮}
  31.       
  32.       (Get_Form1_Data)
  33.       (done_dialog 1);对话框退出返回主函数 传递

  34. 给Dialog_Return值为1
  35.     )
  36.     ((= key "cancel") ;{取消按钮}
  37.       
  38.       (done_dialog 0);对话框退出返回主函数 传递

  39. 给Dialog_Return值为0
  40.     )
  41.     ((= key "Command1") ; {"Command1"} (按钮)
  42.       (c:eww)
  43.     )
  44.   )
  45. )
  46. (defun Get_Form1_Data( / key);临时生成Dcl文件 返回文件名
  47.   (foreach key keys
  48.     (set (read (strcat key "_bak")) (get_tile key));每

  49. 个控件都赋给一个变量 用于下次开启初始化
  50.   )
  51. )
  52. (defun Write_Dcl_Form1( / Dcl_File file str)
  53.   (setq Dcl_File (vl-filename-mktemp nil nil ".Dcl"))
  54.   (setq file (open Dcl_File "w"))
  55.   (foreach str '(
  56.     "Form1:dialog"
  57.     "{"
  58.     " label = \"Form1\";"
  59.     "    :row"
  60.     "    {"
  61.     "        :button"
  62.     "        {"
  63.     "            key = \"Command1\" ;"
  64.     "            label = \"Command1\" ;"
  65.     "            width = 26.55 ;"
  66.     "            height = 5.475 ;"
  67.     "        }"
  68.     "        :text"
  69.     "        {"
  70.     "            key = \"Label1\" ;"
  71.     "            width = 48.15 ;"
  72.     "            height = 6.075 ;"
  73.     "        }"
  74.     "    }"
  75.     "ok_cancel ;"
  76.     "}"
  77.     )
  78.     (write-line str file)
  79.   )
  80.   (close file)
  81.   Dcl_File
  82. )
  83. ;|
  84. /*   自动备份FRM文件内容
  85. VERSION 5.00
  86. Begin VB.Form Form1
  87.    Caption         =   "Form1"
  88.    ClientHeight    =   6450
  89.    ClientLeft      =   120
  90.    ClientTop       =   450
  91.    ClientWidth     =   9675
  92.    LinkTopic       =   "Form1"
  93.    ScaleHeight     =   6450
  94.    ScaleWidth      =   9675
  95.    StartUpPosition =   3  '窗口缺省
  96.    Begin VB.CommandButton Command1
  97.       Caption         =   "Command1"
  98.       Height          =   1095
  99.       Left            =   1080
  100.       TabIndex        =   0
  101.       Top             =   960
  102.       Width           =   2655
  103.    End
  104.    Begin VB.Label Label1
  105.       Caption         =   "Label1"
  106.       Height          =   1215
  107.       Left            =   4200
  108.       TabIndex        =   1
  109.       Top             =   1200
  110.       Width           =   4815
  111.    End
  112. End
  113. Attribute VB_Name = "Form1"
  114. Attribute VB_GlobalNameSpace = False
  115. Attribute VB_Creatable = False
  116. Attribute VB_PredeclaredId = True
  117. Attribute VB_Exposed = False
  118. */
  119. |;



  120. (defun c:eww(/ x0 y0 x1 y1)
  121. (gxl-error-init1 (list ‘blipmode 0 ‘cmdecho 0 ‘osmode 0) ‘tt1

  122. 2) ;_ 出错只编组
  123.   (defun tt1 ()  ;_ 出错后*error*要执行的动作
  124.     (alert "出错啦!")
  125.     )
  126. (setvar "cmdecho" 0 )
  127.   
  128. (SetQ        p0 (GetPoint "\n 第一角点:") x0(car p0) y0(cadr p0)
  129.         p1 (getcorner p0 "\n 另一角点:") x1(car p1) y1(cadr p1)
  130.         dx (abs (- x0 x1))
  131.         dy (abs (- y0 y1))
  132. )
  133. (Command "rectang" p0 p1)

  134. (if(<= dx dy)
  135. (SetQ al (/ dx 8))
  136. (SetQ al (/ dy 8)))
  137. (Command "revcloud" "a" al al "s" "c" "o" "l" "")
  138.   
  139. (setvar "cmdecho" 1)
  140. (gxl-error-end)
  141. (prinC)
  142. )

 楼主| 发表于 2014-8-15 16:48:10 | 显示全部楼层
为什么加载以后点command1按钮调不出我自己写的eww这个命令呢 Cad卡死了直接
 楼主| 发表于 2014-8-15 16:51:20 | 显示全部楼层
或者说怎样调用我写的eww命令呢
发表于 2014-8-15 19:26:08 | 显示全部楼层
  1. (defun c:tt (/ ddr)
  2.   (vl-load-com)
  3.   (setq        dcl_file (write_dcl_form1)
  4.         dcl_id         (load_dialog dcl_file)
  5.         dr         2
  6.   )                                        ;对话框加载
  7.   (vl-file-delete dcl_file)                ;加载后删除dcl文件
  8.   (while (> dr 1)                        ;循环控制对话框是否结束
  9.     (new_dialog "form1" dcl_id)                ;建立窗体
  10.     (setq keys '("command1" "accept" "cancel")) ;列表全部控件名称
  11.     (foreach key keys                        ;全部控件的初始化
  12.       (if (eval (read (strcat key "_bak")))
  13.         (set_tile key (eval (read (strcat key "_bak"))))
  14.       )
  15.       (action_tile key "(action_form1_keys $key $value)") ;点击动作
  16.     )
  17.     (setq dr (start_dialog))
  18.   )
  19.   (unload_dialog dcl_id)
  20.   (if ddr
  21.     (c:eww)
  22.   )
  23.   (princ)
  24. )

  25. (defun action_form1_keys (key value)        ;全部控件的点击动作触发
  26.   (cond        ((= key "accept")                ;{确认按钮}
  27.          (get_form1_data)
  28.          (done_dialog 1)                ;对话框退出返回主函数 传递给dr值为1
  29.         )
  30.         ((= key "cancel")                ;{取消按钮}
  31.          (done_dialog 0)                ;对话框退出返回主函数 传递给dr值为0
  32.         )
  33.         ((= key "command1")
  34.          (setq ddr (done_dialog 1))
  35.         )
  36.   )
  37. )
  38. (defun get_form1_data (/ key)                ;临时生成dcl文件 返回文件名
  39.   (foreach key keys
  40.     (set (read (strcat key "_bak")) (get_tile key)) ;每个控件都赋给一个变量 用于下次开启初始化
  41.   )
  42. )
  43. (defun write_dcl_form1 (/ dcl_file file str)
  44.   (setq        dcl_file (vl-filename-mktemp nil nil ".dcl")
  45.         file         (open dcl_file "w")
  46.   )
  47.   (foreach str '("form1:dialog{label="form1";:row"
  48.                  "{:button{key="command1";label="command1";width=26.55;height=5.475;}:text{key="label1";width=48.15;height=6.075;}}"
  49.                  "ok_cancel;"
  50.                  "}"
  51.                 )
  52.     (write-line str file)
  53.   )
  54.   (close file)
  55.   dcl_file
  56. )

  57. (defun c:eww ()
  58.   (if (and (setq p0 (getpoint "\n第一角点: "))
  59.            (setq p1 (getcorner p0 "\n另一角点: "))
  60.       )
  61.     (progn
  62.       (setq dx (abs (- (car p0) (car p1)))
  63.             dy (abs (- (cadr p0) (cadr p1)))
  64.             al (if (<= dx dy)
  65.                  (/ dx df 1.)
  66.                  (/ dy df 1.)
  67.                )
  68.       )
  69.       (command "rectang" "non" p0 "non" p1)
  70.       (command "revcloud" "a" al al "o" "l" "")
  71.     )
  72.   )
  73.   (princ)
  74. )

点评

多谢版主 周一回公司了我自己测试一下 多谢  发表于 2014-8-15 20:13

评分

参与人数 1明经币 +1 收起 理由
鲑鱼扬帆 + 1 多谢版主指教!感激万分。

查看全部评分

发表于 2014-8-15 19:26:49 | 显示全部楼层
简化模式:
  1. ;; 需要e派工具箱(XCAD)的支持
  2. (defun c:tt (/ ilst)
  3.   (xyp-cmdla0)
  4.   (defun main-pro () (c:eww))
  5.   (xyp-initSet '(df) '(8))
  6.   (setq ilst '(("df" "等分" "int" "8")))
  7.   (if (= (xyp-Dcl-Init Ilst "【DCL测试】" t) 1)
  8.     (main-pro)
  9.   )
  10.   (xyp-cmdla1)
  11. )
  12. (defun c:eww ()
  13.   (if (and (setq p0 (getpoint "\n第一角点: "))
  14.            (setq p1 (getcorner p0 "\n另一角点: "))
  15.       )
  16.     (progn
  17.       (setq dx (abs (- (car p0) (car p1)))
  18.             dy (abs (- (cadr p0) (cadr p1)))
  19.             al (if (<= dx dy)
  20.                  (/ dx df 1.)
  21.                  (/ dy df 1.)
  22.                )
  23.       )
  24.       (command "rectang" "non" p0 "non" p1)
  25.       (command "revcloud" "a" al al "o" "l" "")
  26.     )
  27.   )
  28.   (princ)
  29. )
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-24 06:13 , Processed in 0.224180 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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