乐筑天下

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

[编程交流] Lisp with error-handling

[复制链接]

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 23:25:56 | 显示全部楼层 |阅读模式
Dear Lisp-Proffessionals
 
i have this following little Code with which i try to convert a text's entity style into "Simplex" (just an example). The text is on the layer "Test". Now, when there is a textfield on the layer "Test", the lisp works perfectly fine, but as soon as there is no textfield it doesn't. this wouldn't be a problem, but since there are some other conversion-codes after this particular one the whole code isn't working..
here is the code:
 
(defun c:Convert  (/ entities len count ent ent_data ent_name new_style_name )
 
(setq entities (ssget "X" '(
        (-4 . "")
        (-4 . "")))
      len      (sslength entities)
      count 0
)
   (while (
    (setq  ent      (ssname entities count)
           ent_data (entget ent)
           ent_name (cdr (assoc 7 ent_data))
     )
        (setq new_style_name (cons 7 "SIMPLEX"))      
    (setq ent_data (subst new_style_name (assoc 7 ent_data) ent_data))
    (entmod ent_data)
     (setq count (+ count 1))
    ) ; while
); defun
 
I guess what i need is some error-handling? So i thought to put in the two lines to stop the error:
; if
; progn entities
 
(defun c:Convert  (/ entities len count ent ent_data ent_name new_style_name )
 
(setq entities (ssget "X" '(
        (-4 . "")
        (-4 . "")))
      len      (sslength entities)
      count 0
)
(if entities               
  (progn               
   (while (
    (setq  ent      (ssname entities count)
           ent_data (entget ent)
           ent_name (cdr (assoc 7 ent_data))
     )
        (setq new_style_name (cons 7 "SIMPLEX"))      
    (setq ent_data (subst new_style_name (assoc 7 ent_data) ent_data))
    (entmod ent_data)
     (setq count (+ count 1))
    ) ;while               
   ) ;progn               
  ) ; if               
); defun
 
Even with that it wouldn't do the following conversions. I don't know much of errror-handling that is maybe why... Can please somebody tell me what i'm doing wrong?
 
Thank you!
回复

使用道具 举报

63

主题

6297

帖子

6283

银币

后起之秀

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

铜币
358
发表于 2022-7-5 23:54:56 | 显示全部楼层
Welcome to CADTutor .
 
Read this about code posting guidlines .
 
http://www.cadtutor.net/forum/showthread.php?9184-Code-posting-guidelines&p=51051&viewfull=1#post51051
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-5 23:56:29 | 显示全部楼层
Maybe:
 
  1. [b][color=BLACK]([/color][/b]defun c:convert [b][color=FUCHSIA]([/color][/b]/ ss i en ed[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"*TEXT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]8 . [color=#2f4f4f]"TEST"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]     [b][color=NAVY]([/color][/b]progn       [b][color=MAROON]([/color][/b]setq i 0[b][color=MAROON])[/color][/b]       [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]setq en [b][color=BLUE]([/color][/b]ssname ss i[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]              [b][color=GREEN]([/color][/b]setq ed [b][color=BLUE]([/color][/b]entget en[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]              [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 7 [color=#2f4f4f]"SIMPLEX"[/color][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 7 ed[b][color=RED])[/color][/b] ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b]              [b][color=GREEN]([/color][/b]setq i [b][color=BLUE]([/color][/b]1+ i[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
 
 
-David
回复

使用道具 举报

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 00:10:57 | 显示全部楼层
Thank you David for you quick advice  works perfect now!
...and sorry for not posting correctly, will do different next time...
Have a good day!
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 00:37:54 | 显示全部楼层
Glad it worked,
 
Welcome to CADTutor
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 00:24 , Processed in 0.966365 second(s), 62 queries .

© 2020-2025 乐筑天下

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