DCL和Lisp插入点a
这是我的挑战:我需要一个例程,该例程将提示用户在交点处插入一个点,然后将该点从edit_box值移动给定距离。当前有4个按钮可供选择以移动点,上、左、右和下,以及标准的“确定”、“取消”。
目前,我的代码将插入一个点,表单将显示以提示用户移动距离,但在此之后,我将绕圈尝试找出如何从edit_框中设置值。此外,该值需要以英寸为单位,不确定如何处理除a(val/12)以外的其他值。拼图的最后一块将是从原始插入点交点插入一个维度到点的新位置,然后返回到我们提示用户在交点插入点的开始处。谢谢大家的意见,我真的很感激。
目前为止的代码:
DCL:
//DCL CODING STARTS HERE
move_pt
: dialog
{
label = "Move Points";
: column {
: row {
: button {label = "UP"; key = "up";
width = 6;}
}
}
: column {
: row {
: button {label = "LEFT"; key = "left";
width = 6;}
: edit_box {key = mval; width = 7; value = "";
alignment = centered;}
: button {label = "RIGHT"; key = "right";
width = 6;}
}
}
: column {
: row {
: button {label = "DOWN"; key = "down";
width = 6;}
}
}
: column {
: row {
: button {label = "OK"; key = "accept"; mnemonic = "O";
width = 6; is_default = true;}
: button {label = "Cancel"; key = "cancel"; mnemonic = "c";
width = 6;}
}
}
}
Lisp程序:
(defun c:edgept ()
;define the function
(defun saveVars()
(setq mval( distof (get_tile "mval")))
)
(defun doButton(a)
(cond
((= a 1)(command "._move" (entlast) "" (list 0 (/ mval 12) 0) ""))
((= a 2)(command "._move" (entlast) "" (list ((* mval -1)/ 12) 0 0) ""))
((= a 3)(command "._move" (entlast) "" (list (/ mval 12) 0 0) ""))
((= a 4)(command "._move" (entlast) "" (list 0 ((* mval -1)/ 12) 0) ""))
)
)
;********************************************************
(setvar "CLAYER" "COVER")
(setq pt (getpoint "\Choose intersection you are measuring from: "))
(command "._point" pt)
(setq dcl_id (load_dialog "move_pt.dcl"))
(if (not (new_dialog "move_pt" dcl_id))
(exit)
);end if
(action_tile
"cancel"
"(done_dialog 1)")
(action_tile
"up" "(saveVars) (doButton 1)(done_dialog)")
(action_tile
"left" "(saveVars) (doButton 2)(done_dialog)")
(action_tile
"right" "(saveVars) (doButton 3)(done_dialog)")
(action_tile
"down" "(saveVars) (doButton 4)(done_dialog)")
(start_dialog) ;start dialog
(unload_dialog dcl_id)
(if(= done_diaglog 1)
(princ "\ncancelled!")
)
(princ)
)
(princ)
编辑:我已经更新了上面的代码,我被红色的“mval”的负值卡住了。
并且仍然需要从原点到新pt位置的尺寸。 你好
只需简单介绍一下这四个按钮。
例如,如果用户按下,点对象应移动到的新位置或新坐标在哪里?然后是其他按钮。 你可以为你的点做一个块,但一个点可以,用entlast在你的程序中选择它,将你的距离值存储在一个全局值或一个autocads用户变量中
USERI1–5存储和检索整数值
USERR1–5存储和检索实数
USERS1–5存储和检索文本字符串数据
然后,当用户向上按时,使用move(entlast)@您的距离
存储插入点和新的“极轴”点时,可以对其进行尺寸标注。
祝你好运
gr.Rlx
塔尔瓦特,
绝对如此。
假设用户在edit_框中键入15,则这四个按钮将用户从原始插入点插入的点移动到沿y轴的点“示例”+15(如果按下up),沿x轴的点移动到+15(如果按下right),沿y轴的点移动到-15(如果按下down),沿x轴的点移动到-15(如果按下left)。我编辑了上面的代码
(defun doButton(a)
(cond
((= a 1)(command "._move" (entlast) "" (list 0 (/ mval 12) 0) ""))
((= a 2)(command "._move" (entlast) "" (list (/ (* mval -1) 12) 0 0) ""))
((= a 3)(command "._move" (entlast) "" (list (/ mval 12) 0 0) ""))
((= a 4)(command "._move" (entlast) "" (list 0 (/ (* mval -1) 12) 0) ""))
所以实际上我所有的按钮现在都工作了,我只需要维度部分。
最后,我意识到这是在游戏后期添加的,但我想知道,然后连接一条线穿过所有的点有多难。
我很想看看这是如何应用的,我会努力用这个,谢谢。 很清楚,你不需要在每个动作块中都使用dobutton函数,尽管新坐标列表是错误的,无论如何,我明天早上会发布正确的代码,因为现在已经很晚了。
还有一件事是,需要删除许多额外的列和行函数,并且编辑框的关键字必须是字符串。
我同意它需要清理很多,这是第7-8关在它,我承认我不是最干净的哈哈。非常感谢您的帮助。 你能避免同时使用dcl吗?为什么不使用CHX CHY呢?只要简单的LISP,并提供移动量的正值或负值。如果需要,你还可以使用系数/12等。在循环中,只需不断拾取要移动的对象,很容易更改为先获取点。
(defun c:PTX ( / Pt mvamount))
(setq oldsnap (getvar "osmode'))
(setq pt (getpoint "pick point"))
(setvar "osmode" 0)
(command "point" pt)
(setq mvamount (getreal "Enter value"))
(Command "Move" "L" "" (list 0 0 0) (list mvamount 0 0))
(setvar "osmode" oldsnap)
)
我想使用dcl,因为这将由没有任何CAD培训的个人使用,基本上我需要编写所有的前端命令和变量,同时保持一个干净的界面。这只是过程中的一个组成部分。记住,他们不知道也无法访问所有命令。这就像定制产品的第一步,最后一步将由熟练的技术人员设计。 试试这个程序,让我知道它是如何与你合作的。
DCL代码:
move_pt : dialog { label = "Move Points";
: button {
label = "UP";
key = "up";
width = 6;}
: row {
: button {
label = "LEFT";
key = "left";
width = 6;}
: edit_box {
key = "mval";
width = 7;}
: button {
label = "RIGHT";
key = "right";
width = 6;}
}
: button {
label = "DOWN";
key = "down";
width = 6;}
: row {
: button {
label = "OK";
key = "accept";
mnemonic = "O";
width = 8;
is_default = true;}
: button {
label = "Cancel";
key = "cancel";
mnemonic = "c";
width = 8;
is_cancel = true;
}
}}
(defun c:test (/ pt obj id e p)
;; Tharwat 14.07.2015 ;;
(if (tblsearch "LAYER" "COVER")
(setvar "CLAYER" "COVER")
)
(if (zerop (getvar 'pdmode))
(setvar 'pdmode 3)
)
(if (setq
pt (getpoint "\nChoose intersection you are measuring from: ")
)
(setq obj (entmakex (list '(0 . "POINT") (cons 10 pt))))
)
(vla-regen (vla-get-activedocument (vlax-get-acad-object))
acallviewports
)
(if (and obj
(< 0 (setq id (load_dialog "move_pt.dcl")))
(new_dialog "move_pt" id)
)
(progn
(setq e (entget obj)
p (cdr (assoc 10 e))
)
(defun number-p ()
(or (eq (get_tile "mval") "")
(zerop (atoi (get_tile "mval")))
)
)
(action_tile
"up"
"(if (number-p)(progn
(mode_tile \"mval\" 2)
(alert \"Contents of Edit box is either not numbers or null !\"))
(progn
(entmod (append e (list (cons 10 (list (car p) (+ (cadr p) (read (get_tile \"mval\"))) (caddr p))))))
(done_dialog))) "
)
(action_tile
"left"
"(if (number-p)(progn
(mode_tile \"mval\" 2)
(alert \"Contents of Edit box is either not numbers or null !\"))
(progn
(entmod (append e (list (cons 10 (list (- (car p) (read (get_tile \"mval\"))) (cadr p) (caddr p))))))
(done_dialog)))"
)
(action_tile
"right"
"(if (number-p)(progn
(mode_tile \"mval\" 2)
(alert \"Contents of Edit box is either not numbers or null !\"))
(progn
(entmod (append e (list (cons 10 (list (+ (car p) (read (get_tile \"mval\"))) (cadr p) (caddr p))))))
(done_dialog)))"
)
(action_tile
"down"
"(if (number-p)(progn
(mode_tile \"mval\" 2)
(alert \"Contents of Edit box is either not numbers or null !\"))
(progn
(entmod (append e (list (cons 10 (list (car p) (- (cadr p) (read (get_tile \"mval\"))) (caddr p))))))
(done_dialog)))"
)
(action_tile "accept" "(done_dialog)")
(action_tile "cancel" "(done_dialog)")
(start_dialog)
(unload_dialog id)
)
(if (< 0 id)
(unload_dialog id)
)
)
(princ)
)(vl-load-com)
页:
[1]
2