乐筑天下

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

[编程交流] Error message in routine - bad

[复制链接]

33

主题

117

帖子

85

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2022-7-5 16:13:22 | 显示全部楼层 |阅读模式
I have a lisp routine which worked well in earlier editions of AutoCAD but now with AutoCAD Map 2014 it doesn't work giving me the following error message:
 
; error: bad argument type: numberp: nil
 
The routine draws a circle around a number located at an x,y co-ordinate.
 
Here's the code:
 
  1. (defun c:ImportPts (/ txtht file line ptno x y xy b4y) (setq txtht (getreal "\nText height?")           file (open (getfiled "Select the input file: " "" "txt"  "r") ;;;the smiley with shades is 8 with a bracket next to it) (while (setq line (read-line file))   (setq ptno (substr line 1 (setq xy (vl-string-search "," line)))x (vl-string-left-trim " " (substr line (+ 2 xy) (- (setq b4y (vl-string-search "," line (+ 2 xy))) 2)))y (vl-string-left-trim " " (substr line (+ 2 b4y)))) (command "circle" (list (atof x) (atof y)) txtht) (command "text" "j" "mc" (list (atof x) (atof y)) txtht 0 ptno) ) )
 
 
I would appreciate any help, thanks in advance.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 16:20:26 | 显示全部楼层
Modify your codes by adding CODE TAGS to avoid any appearance of smileys .
 
Can you upload a sample txt file ?
回复

使用道具 举报

33

主题

117

帖子

85

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2022-7-5 16:21:47 | 显示全部楼层
Please find attached as requested Tharwat.
Aberdeen Road.txt
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 16:25:29 | 显示全部楼层
Things like this ?
 
  1. (defun c:ImportPts  (/ h f p w st x y xy b4y) (if   (and (setq h (getreal "\nText height :"))        (setq          f (getfiled "Select the input txt file: " "" "txt" 16))        (setq f (open f "r"))        )    (progn      (while (setq w (read-line f))        (setq st                 (substr w 1 (setq xy (vl-string-search " " w)))              x                 (vl-string-left-trim                   " "                   (substr w  (+ 2 xy) (- (setq b4y (vl-string-search "," w (+ 2 xy))) 3)))              y                 (vl-string-left-trim " " (substr w (+ 2 b4y)))              )        (entmake          (list '(0 . "CIRCLE")                (cons 10                      (setq p (trans (list (atof x) (atof y)) 1 0)))                (cons 40 h)))        (entmake          (list '(0 . "TEXT")                (cons 1 st)                (cons 7 (getvar 'TEXTSTYLE))                (cons 10 p)                (cons 11 p)                (cons 40 h)                '(50 . 0.)                '(71 . 0)                '(72 . 1)                '(73 . 2)                )          )        )      (close f)      )) (princ) )
回复

使用道具 举报

33

主题

117

帖子

85

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2022-7-5 16:29:36 | 显示全部楼层
Thanks for your assist, Tharwat ... works beautifully.
 
Please can you let me know what was wrong in the first instance.
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 16:33:15 | 显示全部楼层
 
You are welcome .
 
 
The first function that search for comma (,) is supposed to be empty space " " and the variable b4y should be increased in location to reach the correct destination and I changed it to 3 .
 
Compare between the two routine to learn and see the differences ( if you'd like ) .
 
Tharwat
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 16:39:11 | 显示全部楼层
FWIW, here's another way to parse the text file contents:
  1. (defun c:test ( / des hgt lst txt )   (initget 6)   (if (and (setq hgt (getdist "\nSpecify text height: "))            (setq txt (getfiled "" "" "txt" 16))            (setq des (open txt "r"))       )       (progn           (while (setq str (read-line des))               (if (and (setq lst (read (strcat "(" (vl-string-translate "," " " str) ")")))                        (= 3 (length lst))                        (apply 'and (mapcar 'numberp lst))                   )                   (progn                       (entmake                           (list                               '(0 . "CIRCLE")                                (cons 10 (cdr lst))                               (cons 40 hgt)                           )                       )                       (entmake                            (list                               '(0 . "TEXT")                               (cons 10 (cdr lst))                               (cons 11 (cdr lst))                               (cons 01 (itoa (car lst)))                               (cons 40 hgt)                               '(72 . 1)                               '(73 . 2)                           )                       )                   )               )           )           (close des)       )   )   (princ))
(Untested & typed in post box!)
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
358
发表于 2022-7-5 16:42:41 | 显示全部楼层
 
Nice way of parsing the string
回复

使用道具 举报

33

主题

117

帖子

85

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2022-7-5 16:46:28 | 显示全部楼层
Hi Tharwat,
 
Apologies for this but with the modified routine the coordinates for the first set of points (1-9) are drawn out of synch, possibly because of the number of digits. the coordinates are fine for points number 10 onwards. When I have got the coordinate say for point number 1 it reads as 53250,166730 rather than 532050, 166730. I have attached the sample text file I am using.
Chesnut Primary.txt
回复

使用道具 举报

33

主题

117

帖子

85

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
170
发表于 2022-7-5 16:50:27 | 显示全部楼层
No worries Tharwat the routine from Lee Mac resolves the issue.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-7 09:43 , Processed in 1.599769 second(s), 73 queries .

© 2020-2025 乐筑天下

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