乐筑天下

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

[编程交流] 平移LISP例程

[复制链接]

17

主题

41

帖子

24

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 16:50:11 | 显示全部楼层 |阅读模式
我只是想分享一下我昨天创造的一个惯例——我希望其他人觉得它有用。
 
有时,我会遇到需要将模型的一部分移动很远的情况,每次更新视口时,我都需要花费几分钟的时间,以便我在图纸空间中的引线和标记与移动的模型对齐。我发现的唯一技术就是这个,当我把东西移到一千多英尺远的地方时,这个技术并不实用。
 
以下是LISP的工作原理。进入模型空间,在旧位置和新位置之间画一条线。然后进入paperspace,进入需要更新的视口。只需用“PANLINE”启动命令,然后单击该行。我还提供了一个选项,可以根据绘制线的方式反转平移方向,如果视口被锁定,还提供了一个警告。
 
代码如下:
  1. (defun c:PANLINE ( / lock flag alrt line p1 p2 option)
  2. ;Pans from one end of a line to another.
  3. ;Useful for updating a viewport when objects in modelspace have been moved.
  4. ;Created by Perry Lackowski on 12/22/2016
  5. (VL-LOAD-COM)
  6. (setq lock (VLA-GET-DISPLAYLOCKED (VLA-GET-ACTIVEPVIEWPORT (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))));
  7. (setq alrt (VL-SYMBOL-NAME lock))
  8. (IF (= alrt ":vlax-true")
  9.         (princ "\nCannot pan inside a locked viewport")
  10.         (progn
  11.         ;Prevents the rest of the code from running if an active viewport is locked.
  12.        
  13.                 (setq flag f)
  14.                 (while (not flag)
  15.                          (setq line (car (entsel "\nSelect Line : ")))
  16.                         (cond   (  (null line)                                        (princ "\nNothing selected, Please try again.")                  )
  17.                                 (  (= (cdr (assoc 0 (entget line))) "LINE")        (setq flag t)                                                  )
  18.                                 (  t                                                (princ "\nSelected object is not line, Please try again."))
  19.                         )
  20.                 )
  21.                 (setq p1 (cdr (assoc 10 (entget line))))
  22.                    (setq p2 (cdr (assoc 11 (entget line))))
  23.                 ;retrieves the contents of group codes 10 and 11 which contain the first and second point of the line.
  24.        
  25.                 (command ".-pan" p2 p1)
  26.                 (princ "Reverse direction [Yes/No] <No>:")
  27.                 (initget 6 "Yes or No")
  28.                 (setq option (getkword "\nReverse pan direction? (Yes/No) <No>: "))
  29.                 (if (= option "Yes")
  30.                         (progn
  31.                                 (command ".-pan" p1 p2)
  32.                                 (command ".-pan" p1 p2)
  33.                         )
  34.                 )
  35.         (princ "\nPan complete.")
  36. ));end progn/if
  37. (princ)
  38. );end defun
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 17:32:23 | 显示全部楼层
干得好
如果你不介意的话,请说几句:
-有一个讨论始终必须允许用户在不强制按ESC键的情况下退出(并错误退出),因此您可以使用此选项更改行提示循环(因此按enter键可以退出例程):
  1. (while (not flag)
  2. (setq line (car (entsel "\nSelect Line <exit> : ")))
  3. (cond   
  4.    ( (= 7 (getvar 'errno)) (princ "\nNothing selected, Please try again.") (setvar 'errno 0) )
  5.    ( (and line (/= (cdr (assoc 0 (entget line))) "LINE"))        (princ "\nSelected object is not line, Please try again.") )
  6.    (t (setq flag t) )
  7. )
  8. )

以下内容可能是:
 
  1. (if line
  2. (progn
  3.    (setq p1 (cdr (assoc 10 (entget line))))
  4.    (setq p2 (cdr (assoc 11 (entget line))))
  5.    ;retrieves the contents of group codes 10 and 11 which contain the first and second point of the line.
  6.    
  7.    (command "_.-pan" p2 p1)
  8.    
  9.    (initget 6 "Yes No")
  10.    (if (= (setq option (getkword "\nReverse pan direction? [Yes/No] <No>: ")) "Yes")
  11.      (command "_.-pan" p1 p2)
  12.    )
  13.    (princ "\nPan complete.")
  14. ); progn
  15. ); if

-------------------
  1. (setq flag f)

也许你会:
  1. (setq flag nil)

但无论如何,这一行是多余的,因为这个标志符号是局部的,并且没有设置为任何值。
-------
  1. (setq option (getkword "\nReverse pan direction? (Yes/No) <No>: "))

请注意,使用了括号的类型,因此这将改变提示行为(无论您在哪里按“N”或“Y”键)。
  1. (setq option (getkword "\nReverse pan direction? [Yes/No] <No>: "))

希望这有帮助。
回复

使用道具 举报

17

主题

41

帖子

24

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
85
发表于 2022-7-5 18:08:30 | 显示全部楼层
感谢您的宝贵意见!我执行了以下所有更改:
 
  1. (defun c:PANLINE ( / lock flag alrt line p1 p2 option)
  2. ;Pans from one end of a line to another.
  3. ;Useful for updating a viewport when objects in modelspace have been moved.
  4. ;Created by Perry Lackowski on 12/22/2016
  5. (VL-LOAD-COM)
  6. (setq lock (VLA-GET-DISPLAYLOCKED (VLA-GET-ACTIVEPVIEWPORT (VLA-GET-ACTIVEDOCUMENT (VLAX-GET-ACAD-OBJECT)))));
  7. (setq alrt (VL-SYMBOL-NAME lock))
  8. (IF (= alrt ":vlax-true")
  9.         (princ "\nCannot pan inside a locked viewport")
  10.         (progn
  11.         ;Prevents the rest of the code from running if an active viewport is locked.
  12.                 (while (not flag)
  13.                         (setq line (car (entsel "\nSelect Line <exit> : ")))
  14.                         (cond   
  15.                                 ( (= 7 (getvar 'errno)) (princ "\nNothing selected, Please try again.") (setvar 'errno 0) )
  16.                                 ( (and line (/= (cdr (assoc 0 (entget line))) "LINE"))        (princ "\nSelected object is not line, Please try again.") )
  17.                                 (t (setq flag t) )
  18.                         )
  19.                 )
  20.                 (if line
  21.                         (progn
  22.                                 (setq p1 (cdr (assoc 10 (entget line))))
  23.                                 (setq p2 (cdr (assoc 11 (entget line))))
  24.                                 ;retrieves the contents of group codes 10 and 11 which contain the first and second point of the line.
  25.                                 (command ".-pan" p2 p1)
  26.                                 (princ "Reverse direction (Yes/No) <No>:")
  27.                                 (initget 6 "Yes or No");initializes the next get function to only accept yes and no
  28.                                 (setq option (getkword "\nReverse pan direction? [Yes/No] <No>: "))
  29.                                 (if (= option "Yes")
  30.                                         (progn
  31.                                                 (command ".-pan" p1 p2)
  32.                                                 (command ".-pan" p1 p2)
  33.                                         )
  34.                                 )
  35.                                 (princ "\nPan complete.")
  36.                         )
  37.                 )
  38. ));end progn/if
  39. (princ)
  40. );end defun
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-8-23 13:20 , Processed in 1.587729 second(s), 58 queries .

© 2020-2025 乐筑天下

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