乐筑天下

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

[编程交流] LISP won't reset to Origi

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 17:08:03 | 显示全部楼层 |阅读模式
Hi Guys,
 
This is probably a really silly mistake on my part - but my LISP will not reset back to the original current layer settings after the user has completed the function.
 
The LISP is created to tag orientation labels on tanks, after the user has specified input data such as drawing scale, label length and angle increment.
 
Here is the LISP:
 
  1. ;|   Tank Orientation Label by Lee McDonnell          (November 2008)          SYNTAX:  "TOL"|;(defun dtr (a)   (* pi (/ a 180.0))) ; end dtr(defun rtd (b)   (* 180.0 (/ b pi))) ; end rtd(defun CreateLayer (Name)     (if       (not (tblsearch "LAYER" Name))            (command "_.-layer" "_m" Name "_c" Name Name "")     ); end if); end of  CreateLayer(defun *error*(msg)   (if oldVars       (mapcar 'setvar varLst  oldVars)   ); end if   (princ "\nError or Esc pressed... ")   (princ)); end of *error*(defun c:TOL (/ oldlay oldsnap dwgscale tkcirc tkent        tkcent line1 l1ent llen inc ang1 txtpt ang2)       (setq varLst    (list "CMDECHO" "OSMODE" "CLAYER" "DIMSCALE")         oldVars    (mapcar 'getvar varLst)   ); end setq    (setq oldlay (getvar "clayer"))   (setq oldsnap (getvar "osmode"))   (setq oldortho (getvar "orthomode"))   (setvar "cmdecho" 0)   (mapcar 'CreateLayer '("1" "2" "3" "4" "5"))   (if       (/= (setq dwgscale (getreal "\nSpecify Drawing Scale: 1:")) nil)       (progn           (while               (/= (setq tkcirc (car (entsel "\nSelect Tank Outer Shell: "))) nil)               (setq tkent (entget tkcirc))               (if                   (= (cdr (assoc 0 tkent)) "CIRCLE")                   (progn                       (setq tkcent (cdr (assoc 10 tkent)))                       (setvar "orthomode" 1)                       (princ "\nSpecify Length of Primary Label: ")                       (command "_line"                           tkcent                           pause                           ""                       ) ; end line                       (setq line1 (entlast))                       (setq l1ent (entget line1))                       (setq llen                            (distance                                (cdr (assoc 10 l1ent))                                (cdr (assoc 11 l1ent))                           ) ; end distance                       ) ; end setq                       (entdel line1)                       (setvar "orthomode" 0)                       (if                           (and                               (> (setq inc (getreal "\nSpecify Angle Increment: ")) 0)                               (< inc 360)                           ) ; end and                           (progn                               (setvar "osmode" 0)                               (setq inc (dtr inc))                               (setq ang1 0)                               (while                                   (< ang1 (* 2 pi))                                   (setvar "clayer" "5")                                   (command "_line"                                       tkcent                                       (polar                                           tkcent                                           ang1                                           llen                                       ) ; end polar                                       ""                                   ) ; end line                                   (setq txtpt                                       (polar                                           tkcent                                           ang1                                           (* llen 1.12)                                       ) ; end polar                                   ) ; end setq                                   (setq ang2                                       (strcat                                           (rtos (rtd ang1))                                           "%%D"                                       ) ; end strcat                                   ) ; end setq                                   (entmake                                   (list    '(0 . "TEXT")                                       '(8 . "TEXT")                                       (cons 10 txtpt)                                       (cons 40 (* dwgscale 2.5))                                       (cons 1 ang2)                                       '(50 . 0.0)                                       '(7 . "STANDARD")                                       '(71 . 0)                                       '(72 . 1)                                       '(73 . 2)                                       (cons 11 txtpt)                                   ) ; end list                                   ) ; end entmake                                   (setvar "clayer" oldlay)                                   (setq ang1 (+ inc ang1))                               ) ; end while                           ) ; end progn                           (alert "\nAngle Increment must be Positive and Non-zero. ")                       ) ; end if                   ) ; end progn                   (alert "\nEntity Selected is not a Circle.")               ) ; end if           ) ; end while       ) ; end progn       (alert "\nDrawing Scale must be Positive and Non-zero. ")   ) ; end if   (setvar "cmdecho" 1)   (setvar "osmode" oldsnap)   (setvar "orthomode" oldortho)   (princ "\nFunction Complete. ")   (princ)) ; end function                             
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 17:36:38 | 显示全部楼层
try this (not tested)
  1. ;|   Tank Orientation Label by Lee McDonnell          (November 2008)          SYNTAX:  "TOL"|;(defun dtr (a)   (* pi (/ a 180.0))) ; end dtr(defun rtd (b)   (* 180.0 (/ b pi))) ; end rtd(defun CreateLayer (Name)     (if       (not (tblsearch "LAYER" Name))            (command "_.-layer" "_m" Name "_c" Name Name "")     ); end if); end of  CreateLayer(defun *error*(msg)   (if oldVars       (mapcar 'setvar varLst  oldVars)   ); end if   (princ "\nError or Esc pressed... ")   (princ)); end of *error*(defun c:TOL (/  dwgscale tkcirc tkent        tkcent line1 l1ent llen inc ang1 txtpt ang2 [color=red]*error*[/color])       (setq varLst    (list "CMDECHO" "OSMODE" "CLAYER" "DIMSCALE" [color=red]"ORTHOMODE"[/color])         oldVars    (mapcar 'getvar varLst)   ); end setq    [color=red];;[/color](setq oldlay (getvar "clayer"))    [color=red];;[/color](setq oldsnap (getvar "osmode"))    [color=red];;[/color](setq oldortho (getvar "orthomode"))       (setvar "cmdecho" 0)   (mapcar 'CreateLayer '("1" "2" "3" "4" "5"))   (if       (/= (setq dwgscale (getreal "\nSpecify Drawing Scale: 1:")) nil)       (progn           (while               (/= (setq tkcirc (car (entsel "\nSelect Tank Outer Shell: "))) nil)               (setq tkent (entget tkcirc))               (if                   (= (cdr (assoc 0 tkent)) "CIRCLE")                   (progn                       (setq tkcent (cdr (assoc 10 tkent)))                       (setvar "orthomode" 1)                       (princ "\nSpecify Length of Primary Label: ")                       (command "_line"                           tkcent                           pause                           ""                       ) ; end line                       (setq line1 (entlast))                       (setq l1ent (entget line1))                       (setq llen                            (distance                                (cdr (assoc 10 l1ent))                                (cdr (assoc 11 l1ent))                           ) ; end distance                       ) ; end setq                       (entdel line1)                       (setvar "orthomode" 0)                       (if                           (and                               (> (setq inc (getreal "\nSpecify Angle Increment: ")) 0)                               (< inc 360)                           ) ; end and                           (progn                               (setvar "osmode" 0)                               (setq inc (dtr inc))                               (setq ang1 0)                               (while                                   (< ang1 (* 2 pi))                                   (setvar "clayer" "5")                                   (command "_line"                                       tkcent                                       (polar                                           tkcent                                           ang1                                           llen                                       ) ; end polar                                       ""                                   ) ; end line                                   (setq txtpt                                       (polar                                           tkcent                                           ang1                                           (* llen 1.12)                                       ) ; end polar                                   ) ; end setq                                   (setq ang2                                       (strcat                                           (rtos (rtd ang1))                                           "%%D"                                       ) ; end strcat                                   ) ; end setq                                   (entmake                                   (list    '(0 . "TEXT")                                       '(8 . "TEXT")                                       (cons 10 txtpt)                                       (cons 40 (* dwgscale 2.5))                                       (cons 1 ang2)                                       '(50 . 0.0)                                       '(7 . "STANDARD")                                       '(71 . 0)                                       '(72 . 1)                                       '(73 . 2)                                       (cons 11 txtpt)                                   ) ; end list                                   ) ; end entmake                                   [color=red];;[/color](setvar "clayer" oldlay)                                   (setq ang1 (+ inc ang1))                               ) ; end while                           ) ; end progn                           (alert "\nAngle Increment must be Positive and Non-zero. ")                       ) ; end if                   ) ; end progn                   (alert "\nEntity Selected is not a Circle.")               ) ; end if           ) ; end while       ) ; end progn       (alert "\nDrawing Scale must be Positive and Non-zero. ")   ) ; end if  [color=red];;[/color](setvar "cmdecho" 1)   [color=red];;[/color](setvar "osmode" oldsnap)   [color=red];;[/color](setvar "orthomode" oldortho)[color=red]  (*error* nil) ;_force error function at end to restore variables[/color]      (princ "\nFunction Complete. ")   (princ)) ; end function                             
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 17:53:03 | 显示全部楼层
Hi Wizman,
 
Just tried your LISP, and it returns "NO FUNCTION DEFINITION.... *ERROR* ".
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 18:16:07 | 显示全部楼层
 
 
your subroutines dtr, rtd, createlayer and *error* were outside the main function c:tol, include them inside and it should work.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 16:14 , Processed in 0.416707 second(s), 60 queries .

© 2020-2025 乐筑天下

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