乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 55|回复: 5

[编程交流] Number Array Difficulties - Pr

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 17:15:34 | 显示全部楼层 |阅读模式
Hi Guys,
 
I have just been creating a LISP to produce a number array, but can't get it to work.
 
I would appreciate it if someone could point out the mistake in my program
 

[code](defun c:numarray (/ snum enum incr txpt cnt ldir lspc)   (while       (and           (setq snum (getreal "\nSpecify Starting Number: "))           (setq enum (getreal "\nSpecify Ending Number: "))           (setq incr (getreal "\nSpecify Increment Size [> 0.01]: "))           (setq txpt (getpoint "\nSelect First Text Base Point: "))       ) ; end and       (setq cnt snum)       (initget 1 "Up" "Down" "Left" "Right")       (setq ldir (getkword "\nSpecify List Direction (Up/Down/Left/Right): "))       (setq lspc (getreal (strcat "Specify List Spacing [>"                       (rtos (* 2.5 (getvar "DIMSCALE")) 2 2)                       "]: "                   ) ; end strcat              ) ; end getreal       ) ; end setq           (while           (
回复

使用道具 举报

4

主题

940

帖子

961

银币

初来乍到

Rank: 1

铜币
12
发表于 2022-7-6 17:38:13 | 显示全部楼层
Right off the bat I noticed that your initget has too many arguments
should be
  1. (initget 1 "Up Down Left Right")
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 17:44:34 | 显示全部楼层
Excellent, thanks for that lpseifert - I knew it would be something as simple as that...
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 18:01:47 | 显示全部楼层
Hi Guys,
 
Once again, thanks for your help with my LISP program
Now that I have finished it, I thought I might upload it so that if it is of any use to anyone to help speed up their work, they are free to use it or modify it to better suit their needs.
 
So here it is:
 

[code](defun c:numarray (/ pref ptxt snum enum incr txpt cnt ldir lspc)   (initget "Yes No")   (setq pref (getkword "\nPrefix Text? [Yes/No]: "))   (if (= pref "Yes")       (setq ptxt (getstring t "\nSpecify Prefix: "))   ) ; end if   (while       (and           (setq snum (getreal "\nSpecify Starting Number: "))           (setq enum (getreal "\nSpecify Ending Number: "))           (setq incr (getreal "\nSpecify Increment Size [> 0.01]: "))           (setq txpt (getpoint "\nSelect First Text Base Point: "))       ) ; end and       (setq cnt snum)       (initget 1 "Up Down Left Right")       (setq ldir (getkword "\nSpecify List Direction (Up/Down/Left/Right): "))       (setq lspc (getreal (strcat "\nSpecify List Spacing [> "                       (rtos (getvar "TEXTSIZE") 2 2)                       "]: "                   ) ; end strcat              ) ; end getreal       ) ; end setq       (cond           ((/= pref "Yes")           (while               (
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 18:10:46 | 显示全部楼层
Lee Mac you're learning fast.
 
Food for thought.

[code](defun c:numarray (/ pref ptxt snum enum incr txpt cnt ldir lspc) (initget "Yes No") (setq pref (getkword "\nPrefix Text? [Yes/No]: ")) (if (= pref "Yes")   (setq ptxt (getstring t "\nSpecify Prefix: "))   (setq ptxt "") )       ; end if (while   (and     (setq snum (getdist "\nSpecify Starting Number: "))     (setq enum (getdist "\nSpecify Ending Number: "))     (setq incr (getdist "\nSpecify Increment Size [> 0.01]: "))     (setq txtpt (getpoint "\nSelect First Text Base Point: "))   )     ; end and    (setq cnt snum)    (initget 1 "Up Down Left Right")    (setq ldir (getkword "\nSpecify List Direction (Up/Down/Left/Right): "))    (setq lspc (getdist (strcat "\nSpecify List Spacing [> "                                (rtos (getvar "TEXTSIZE") 2 2)                                "]: "                        ) ; end strcat               ) ; end getdist    )    ; end setq    (if (member ldir '("Right" "Left"))      (setq ang 0.)      (setq ang (/ pi 2.))    )    (if (member ldir '("Down" "Left"))      (setq lspc (- lspc))    )       (while         (
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 18:23:37 | 显示全部楼层
Thanks Charles,
 
That make the LISP a lot more concise, whilst still achieveing the same result.
 
I couldn't figure out how to incorporate the prefix within the entmake function and still enable the user to decide not to use a prefix, without duplicating the entmake  with use of a cond function - but just setting the prefix to "" in the alternative result of the if function accomplishes it nicely.
 
Thanks
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 16:48 , Processed in 0.856002 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表