Qonfire 发表于 2022-7-6 08:30:57

关于ATOF的问题

(action_tile
   "accept"                                                ;if O.K. pressed
   (strcat                                                ;string 'em together
   "(progn
    (setq SIZ (atof (get_tile \"selections\")))"        ;get list selection
   " (done_dialog)(setq userclick T))"                ;close dialog, set flag
   );strcat
);action tile

(start_dialog)                                        ;start dialog

(unload_dialog dcl_id)                                ;unload

(if userclick                                        ;check O.K. was selected
   (progn

   (setq SIZ (fix SIZ))                                ;convert to integer;
    (setq SIZ (nth SIZ NAMES))                        ;get the size

   );progn

);if userclick

(princ)
 
你好,老虎
 
我被困在这里,这个教程是从下面的链接。平铺“选择”中的If值
是“M8”,为什么atof函数会处理它。http://www.afralisp.net/dialog-control-language/tutorials/dialog-boxes-and-autolisp-part-2.php

Lee Mac 发表于 2022-7-6 09:10:44

由于“selections”磁贴是列表磁贴,(适用于list\u box/popup\u list),get\u磁贴返回一个字符串,其中包含所选项目的从零开始的索引。作者使用atof函数将该字符串转换为实数,然后使用fix将其转换为整数。如果我在写它,我会去掉中间人,使用atoi直接转换成整数。
 

Qonfire 发表于 2022-7-6 09:28:34

谢谢你的回复。
,在教程中,列表中的一个元素是“M10”,(如果我在这个(setq-SIZ(fix-SIZ))中的两行之后插入“M10”,则atof(其中)返回“M10”)。
 
atof-此函数将字符串更改为实数。
 
      Syntax : (atof string)

         string - any valid string.

                (atof "345") returns 345.0

                (atof "345.9") returns 345.9

                (atof 345) returns "Error: Bad Argument Type"   

                (atof 345.9) returns "Error: Bad Argument Type"   

                (atof "-345") returns -345.0

                (atof "-345.9") returns -345.9

                (atof "345JEFF49") returns 345.0

                (atof "JEFF49") returns 0.0
我也看了这里。。。
如果它转换成实数,那么输出为什么是字符串。我相信李的回答完全涵盖了这个问题。。。但是它还没有点击

Lee Mac 发表于 2022-7-6 09:36:22

重读我的帖子-对于列表互动程序,get\u tile返回所选项目的索引。
 
因此,如果选择了第一个项目,get\u tile返回“0”,如果选择了第二个项目,则返回“1”等。
页: [1]
查看完整版本: 关于ATOF的问题