BLOACH85 发表于 2022-7-6 15:03:59

帮助DCL?

嘿伙计们,
好的,这是我的新项目,我对dcl不太熟悉,但无论如何我都在尝试。我有一个lisp例程,它只是一个信息,但这是我的东西,我想在对话框中发布的信息,但以英尺英寸而不是十进制形式。有什么想法吗?我写了一个dcl,我将发布lisp和dcl。如果对我的问题有任何想法,请帮助我。如果它不起作用,请随时联系创建者!!严格来说,这是为了让我和其他人在工作时的生活更轻松(如果你是一个其他结构的细节设计师)。。
 
这是尖桩Lisp程序。
 
(defun c:picket (/ aa ab ac ad ae af ag dst1 pip1 bar1 dst2 num1 d num2 spa1 y y1 y2 y3 y4 spa2 dst3 endb endr1 endr2)
((setq dst1 (getdist "\nEnter Post to Post spacing : <>"))       ;DIMENSION FROM POST TO POST
(setq pip1 (getdist "\nEnter Pipe Size in inches : <1.66>"))   ;DIAMETER OF POST (DEFAULT 1.66)
(setq bar1 (getdist "\nEnter thickness of pickets : <0.5>"))   ;PICKET SIZE (DEFAULT 0.5)
(setq dst2 (+ (- dst1 pip1) bar1));dst2 is the spacing of pickets less the pipe post
(setq num1 (/ dst2 4))   ;num1 is the number of picket spaces @ exactly 4"
(setq d (fix (+ num1 0.99)))      ;d is the number of spaces needed to round up
(setq num2 (- d 2))    ;num2 is the number of spacing for the middle of the rail
(setq spa1 (/ dst2 d))
(setq y (+ spa1 0.03125))
(setq y1 (* y 32))
(setq y2 (- y1 (rem y1 1)))
(setq y3 (/ y2 2))
(setq y4 (- y3 (rem y3 1)))
(setq spa2 (/ y4 16))    ;spa2 is the picket space in the middle in 16ths.
(setq dst3 (* spa2 num2))   ;dst3 is the middle dimension.
                                       ;This is the number of spaces times the picket
   ;spacing for the middle section.
(setq endb (- dst1 dst3))
(setq endr1 (/ (* endb 16) 2))
(setq endr2 (- endr1 (rem endr1 1)))
(setq endr (/ endr2 16))
(setq endl (- endb endr))   ;endl is the left end dimension minus
   ;the right end dimension.
);    INPUT
    ; Post to Post spacing=dst1
    ; Pipe size = pip1
    ; Picket size = bar1
    ;
    ;   OUTPUT
    ;Left space = endl
    ;Right space = endr
    ;Number of middle spaces = d
    ;Dimension of middle space spaces = spa2
    ;Dimension of middle space total = dst3
   
(princ)
)



 
好的,这是我的dcl(如果你这么说的话)
 
PICKETS : dialog {
label = "The Picket Spacing Machine!" ;
: row {
:boxed_column {
label = "ENTER DIMENSIONS EXACTLY";
:edit_box {
key="X";
label="What is your Dimension from Center to Center of Post?" ;
value=dst1;
edit_width=14;
alignment=centered;
}
:edit_box {
key="y" ;
label = "What is your Post Diameter";
value=pip1;
edit_width=14;
}                  
:edit_box {
key="z" ;
label = "What is your Picket size";
value=bar1;
edit_width=14;
}
:row {
:column {
width=10;
alignment=centered;
label="End Space 1";
:edit_box {
edit_width=6;
key="end1" ;
value=endr1;
}
}

:column {
width=3;}
:column {
width=10;
label="# of Spaces";
:edit_box {
edit_width=6;
key="sp";
value=num2;
}
}
:row {
:column{
width=15;
:text {key="tt" ; value="SPACES @";
alignment=centered;}}
}
:column {
width=10;
label="Space Size";
:edit_box {
edit_width=6;
key="sp2";
value=spa2;
}
}

:column {
width=3;}

:column {
width=10;
alignment=centered;
label="End Space 2";
:edit_box {
key="end2" ;
edit_width=6;
value=endr1
}
}
}
:row {
:boxed_column {
label="Written by Joe Barrett and Brandon DeLoach   <2009>" ;}
}
}
}
ok_cancel ;
}
 
如有任何帮助或指导,我们将不胜感激:?

JohnM 发表于 2022-7-6 15:09:48

如果我错了,请纠正我。
你想启动程序
显示对话框
让用户填写3个问题
并在对话框底部的4个框中显示结果。

BLOACH85 发表于 2022-7-6 15:15:25

是的,没错。它只会提供信息,就这样!

JohnM 发表于 2022-7-6 15:19:19

首先,第74行的dcl文件中有一个错误:value=endr1
这需要在末尾有一个分号:value=endr1;
编写需要对话框的程序时,应编写一个输入/输出文件,作为lisp文件和dcl文件之间的连接。
输入/输出文件可以在dcl中设置分片的值,然后将结果返回lisp进行处理。
这是我认为你应该做的。
不要让用户在命令行上回答问题,而是让对话框出现,用户在那里填写问题。然后使用2个按钮代替ok\u cancel,1个用于计算,另一个用于取消。
当用户填写这3个问题时,他们点击“计算”按钮,这3个答案被发送到lisp文件进行处理,然后返回到对话框进行显示。这将使用输入/输出文件中的循环来完成
这将需要您编辑原始lisp文件、dcl文件并创建输入/输出文件
但结果会很酷。
如果你有兴趣学习如何做到这一点,我很乐意一步一步地指导你。我会自己写,但你什么也学不到。

BLOACH85 发表于 2022-7-6 15:21:13

我真的很感激你帮我做这件事。因此,输入/输出文件只是作为两者之间的传输。。。。好的,那么它是如何格式化的?
我们从哪里开始lsp、dcl、in/out

JohnM 发表于 2022-7-6 15:25:13

首先,让我们从清理和设置lsp和dcl文件开始。
在您的dcl文件中,第74行有一个错误。在我之前的帖子中,我指出了这一点
纠正它
在dcl文件中,在单词value之前用2个斜杠//注释掉所有值行。稍后,我们将使用输入/输出文件来设置这些值。
 
如果你有ok\u cancel,你需要创建两个按钮,代码如下
:行{//定义确定/取消按钮行
:间隔{width=20;}
:按钮{//定义“确定”或“计算”按钮
label=“计算”;
is_default=true;
key=“接受”;
宽度=8;
固定宽度=true;
}
:按钮{//定义取消按钮
label=“取消”;
is_cancel=true;
key=“取消”;
宽度=8;
固定宽度=true;}
 
:间隔{width=20;}
}
 
完成此操作后,请检查对话框,确保所有内容都在它应该位于的位置。
您知道如何使用visp环境查看对话框吗?
如果不让我知道,我会告诉你。
 
现在,我们清理您的Lisp程序:
 
你知道如何将参数传递给另一个defun吗?
您知道如何从defun返回变量吗?
 
编写lisp文件时,从(defun c:XXX(/var1 var2……)开始
C:用于告诉autocad这是从命令行调用的,因此如果在命令行上键入XXX,程序将启动。
 
在c:xxx之后是声明括号(/var1 var2……)。这是您接受要在程序中使用的参数的地方,也是您声明在程序中使用的所有变量的地方,以便在程序完成时将其设置为零。
正斜杠/左边的任何内容都是传递给程序的参数,/右边的所有内容都是程序中的变量。
典型的情况是,如果程序使用传递给它的参数,则省略C:如下所示:
(defun XXX(aug1 aug2/var1 var2….)
 
假设您有一个程序C:YYY,要求用户获得2分
 
使用变量pt1和pt2,使用getpoint函数获取点
 
然后你有另一个程序(defun XXX(aug1 aug2/var1 var2….)这将接受两个参数,并对其进行处理以获得点到点的距离。
 
在c:yy程序内,在收集点后,您将调用XXX程序,将2个点传递给它,并让它返回处理后的值,如下所示:
 
(setq ret(XXX pt1 pt2)调用XXX程序,将pt1和pt2的2个值传递给它,并由aug1和aug2参数保存在XXX程序中。
所以xxx程序会这样处理
(setq dist(距离aug1 aug2)
 
只是一个传递变量的速成班。它可能会变得复杂得多,但现在让我们坚持基本原则。
 
好的,现在开始清理您的lisp文件。
在您的lisp文件中,我们需要使用;在问题之前
稍后,我们将通过输入/输出文件将这些值传递回lisp文件
如果第一个问题的第一个开括号
((setq dst1(getdist“\n输入柱间距:”))
去掉表示输入的右括号。
 
接下来,通过去掉C:并添加3个参数,将defun设置为接受参数。不使用aug1 aug2 aug3,而是将参数命名为dist1 pip1 bar1
(defun pickens(dist1 pip1 bar1/您的变量在此处保持不变)
其中,变量位于/delete dist1 pip1 bar1之后,因为这些现在是参数,在程序完成后,wan将为nill。
 
是时候让你提问了,然后我们将进入“输入/输出”文件,并将所有内容整合在一起。
 
 
 
 
 
 

BLOACH85 发表于 2022-7-6 15:29:23

好了,现在dcl和lisp被清理了,现在我们分配一个条件?Lisp程序?这将允许输入/输出切换到dcl,并允许用户输入输入并切换回lisp,以根据用户输入执行计算?

CAB 发表于 2022-7-6 15:33:54

我把它放在一起&没有检查准确性,但它确实向您展示了如何启动DCL。
 
也许约翰会带你度过难关。希望我没有踩到你的脚,约翰。
 
另存为纠察队。dcl&必须位于ACAD搜索路径中。
PICKETS : dialog { label = "The Picket Spacing Machine!"; initial_focus = "c2c";
:boxed_column { label = "ENTER DIMENSIONS EXACTLY";
:edit_box { key = "c2c"; edit_width = 14 ;
   label="What is your Dimension from Center to Center of Post?" ;}
:edit_box { key = "pdia"; edit_width = 14;
   label = "What is your Post Diameter"; }                  
:edit_box { key = "psize"; edit_width = 14;
   label = "What is your Picket size"; }
}   
:row {
:column { width=8; alignment=centered; label="End Space 1";
    :text {key="end1"; width=6; value="XXXXXX"; alignment=centered;}
   }
:column { width=8; label="# of Spaces";
    :text {key="sp"; width=6; value="XXXXXX"; alignment=centered;}
}
:column { width=8; label="Space Size";
    :text { key="sp2"; width=6; value="XXXXXX"; alignment=centered;}
}
:column {width=8; label="End Space 2";
    :text { key="end2"; width=6; value="XXXXXX"; alignment=centered;}
}
}
:boxed_row { label="STATUS";
:text {key= "msg"; value="Status message";}
}
:text{key="xxx";label="Written by Joe Barrett and Brandon DeLoach   <2009>& CAB :)" ;}
: ok_button { is_cancel = true; }
}
 
Lisp文件,warts&all。目前没有尝试本地化VAR。
(defun c:pickets (/ aa ab ac ad ae af ag cen2cen PostDia PickSize dst2 num1 d num2 spa1 y y1 y2 y3 y4
                spa2 dst3 endb endr1 endr2
               )


;; convert to a number & return (number & type)
(defun GetNum (numstr / num typ)
   ;;Returns a list of (<type of number> <number>) or nil
   ;;must be tested in this order (4 2 1 5 3)
   ;;if you use (1 2 3 4 5) you will not get any 2 4 or 5 results
   ;;further test result in inconsistancies with 3&4 and 5 types
   ;;Note that if the system units are set to Arch then Arch entries will return
   ;;as type 2 numbers, else they will be type 4 numbers
   ;;so I put type 4 ahead of type 2
   (cond ((setq num (distof numstr 2)) (setq typ 2))
         ((setq num (distof numstr 4)) (setq typ 4))
         ((setq num (distof numstr 1)) (setq typ 1))
         ((setq num (distof numstr 5)) (setq typ 5))
         ((setq num (distof numstr 3)) (setq typ 3))
   )
   (list typ num)
)

(defun GetTiles ()
   (and
   (setq cen2cen (cadr (GetNum (get_tile "c2c")))) ; DIMENSION FROM POST TO POST
   (setq PostDia (cadr (GetNum (get_tile "pdia")))) ; DIAMETER OF POST
   (setq PickSize (cadr (GetNum (get_tile "psize")))) ; PICKET SIZE
   )
)


;;calc & update
(defun calc ()
   (if (and (GetTiles) cen2cen PostDia PickSize)
   (progn

       ;;(setq cen2cen (getdist "\nEnter Post to Post spacing : <>")) ;DIMENSION FROM POST TO POST
       ;;(setq PostDia (getdist "\nEnter Pipe Size in inches : <1.66>")) ;DIAMETER OF POST (DEFAULT 1.66)
       ;;(setq PickSize (getdist "\nEnter thickness of pickets : <0.5>")) ;PICKET SIZE (DEFAULT 0.5)
       (setq dst2 (+ (- cen2cen PostDia) PickSize))
         ;dst2 is the spacing of pickets less the pipe post
       (setq num1 (/ dst2 4)) ;num1 is the number of picket spaces @ exactly 4"
       (setq d (fix (+ num1 0.99))) ;d is the number of spaces needed to round up
       (setq num2 (- d 2)) ;num2 is the number of spacing for the middle of the rail
       (setq spa1 (/ dst2 d))
       (setq y (+ spa1 0.03125))
       (setq y1 (* y 32))
       (setq y2 (- y1 (rem y1 1)))
       (setq y3 (/ y2 2))
       (setq y4 (- y3 (rem y3 1)))
       (setq spa2 (/ y4 16)) ;spa2 is the picket space in the middle in 16ths.
       (setq dst3 (* spa2 num2)) ;dst3 is the middle dimension.
       ;;This is the number of spaces times the picket
       ;;spacing for the middle section.
       (setq endb (- cen2cen dst3))
       (setq endr1 (/ (* endb 16) 2))
       (setq endr2 (- endr1 (rem endr1 1)))
       (setq endr (/ endr2 16))
       (setq endl (- endb endr)) ;endl is the left end dimension minus
       ;;the right end dimension.
       ;;    INPUT
       ;; Post to Post spacing=cen2cen
       ;; Pipe size = PostDia
       ;; Picket size = PickSize
       ;;
       ;;   OUTPUT
       ;;Left space = endl
       ;;Right space = endr
       ;;Number of middle spaces = d
       ;;Dimension of middle space spaces = spa2
       ;;Dimension of middle space total = dst3

       ;;Update the dialog box
       (set_tile "msg" "Data evaluation complete.")
       (set_tile "end1" (rtos endl 4 )
       (set_tile "end2" (rtos endr 4 )
       (set_tile "sp" (rtos d 2 0)) ; # of Spaces
       (set_tile "sp2" (rtos spa2 4 ) ; Space Size
   )
   (set_tile "msg" "Incomplete input or bad number.")
   )
)

(defun doit (dn)
   ;;set actions to do when exiting these tiles
   (action_tile "c2c" "(calc)")
   (action_tile "pdia" "(calc)")
   (action_tile "psize" "(calc)")
   ;;default values for these tiles
   (set_tile "pdia" "1.66")
   (set_tile "psize" "0.5")

   (start_dialog)
   (unload_dialog dn)
)



;;--------------------------
;;S T A R T   H E R E   
;;--------------------------

(setq dclfile "Pickets.dcl"
       dclName "PICKETS"
)
(cond
   ;;((not (tm_create_dcl dclName)) (prompt (strcat "\nCannot create " dclfile ".")))
   ((< (setq dcl# (load_dialog dclfile)) 0)
    (prompt (strcat "\nCannot load " dclfile "."))
   )
   ((not (new_dialog dclName dcl#)) (prompt (strcat "\nProblem with " dclfile ".")))
   ((doit dcl#)) ; No DCL problems: fire it up
)       ; end cond

(princ)
)

JohnM 发表于 2022-7-6 15:39:57

接下来,让我们确定需要从lisp文件传递回in/out文件的内容
当用户单击“计算”按钮时,我们将3个值传递到lisp文件,并让它返回答案。
输入/输出文件中有一个循环,因此当用户单击“计算”按钮时,它将循环。这也意味着我们需要重新填充dcl文件中的所有磁贴。
因此,lisp需要返回问题的3个原始值加上4个计算出的答案。
lisp文件中的4个变量是什么?
在原始dcl文件中,您分配了值,并分配了变量endr1 num2 spa end1。这是正确的吗?第一个和最后一个值都有endr1。
在lisp文件的末尾写一行
(setq ret(list dist1 pip1 bar1 endr1 num2 spa end1))这将把列表传递回输入/输出文件,然后我们将解析列表并相应地分配值
同时去掉lisp文件末尾的(princ)。
如果希望程序返回值或列表,则它必须是文件中的最后一项。
这可以通过以下两种方式之一实现:
要么将文件的最后一行设置为(setq ret(list dist1 pip1 bar1 endr1 num2 spa end1)),然后将使用defun的右括号)
或者在代码中使用上面的setq ret,在文件的末尾只写变量
Ret公司
);_德芬
好的,当你在消化这个的时候,我会准备一个输入/输出文件,在我的下一篇文章中解释

JohnM 发表于 2022-7-6 15:43:14

哦,是的,也可以在defun之后将变量ret添加到declarations部分的变量列表中,这样在程序完成后它将为nill
页: [1] 2
查看完整版本: 帮助DCL?