乐筑天下

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

[编程交流] Lisp更改全部的Z值

[复制链接]

3

主题

11

帖子

8

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 08:25:08 | 显示全部楼层
目前,我选择的是简单的路线——使用Change/Elev。下面是代码,有几个变体(在我的系统上,代码都在一个文件中:SetZ.lsp):
 
SZ-将选定图元设置为指定高程
SZC-将选定图元设置为指定高程,将修改后的图元更改为当前图层
 
SZ100-将选定图元设置为标高100'
SZ150-将选定图元设置为标高150’
SZ200-将选定图元设置为标高200'
 
SZc100-将选定图元设置为标高100’,将修改的图元更改为当前图层
SZc150-将选定图元设置为标高150’,将修改的图元更改为当前图层
SZc200-将选定图元设置为标高200’,将修改的图元更改为当前图层
 
LSZ-重新加载SetZ。lsp if在其中一个支持文件路径中
 
汤姆
 
  1. ;;==================
  2. ;;
  3. ;; SZ - Set Z to user input value
  4. ;;
  5. ;; Changes Elevations of selected entities
  6. ;;   (not "Z" values per se)
  7. ;; If the Z values are not all the same, no action.
  8. ;;
  9. ;; Written by Tom Deering
  10. ;;
  11. ; Rev0 2012-08-08 Initial Code
  12. ;
  13. ;
  14. ;;==================
  15. ;
  16. (defun c:SZ (/ current_layer ss1 s)
  17. ; Set Z
  18. (princ "\nSet Z for selected entities...\n")
  19. (setvar "cmdecho" 0)
  20. (setq ss1 (ssget))
  21. (if ss1
  22. (progn
  23. (setq s (getstring "New Elevation? >"))
  24. ; Set selected to new elevation
  25. (command ".change" ss1 "" "P" "E" s "")
  26. (princ (strcat "\nEntities changed to elevation: " s ))
  27. )
  28. )
  29. ;
  30. (princ)
  31. )
  32. ;
  33. ;
  34. (defun c:SZc (/ current_layer ss1 s)
  35. ;Set Z with Change to Current Layer
  36. (setq current_layer (getvar "clayer"))
  37. (princ "\nSet Z for selected entities, w/ Change to curr layer...\n")
  38. (setvar "cmdecho" 0)
  39. (setq ss1 (ssget))
  40. (if ss1
  41. (progn
  42. (setq s (getstring "New Elevation? >"))
  43. ; Set selected to new elevation
  44. (command ".change" ss1 "" "P" "E" s "")
  45. ;Change to current layer
  46. (command ".change" ss1 "" "P" "LA" current_layer "")
  47. (princ (strcat "\nEntities changed to elevation: " s "\nEntities changed to current layer: " current_layer))
  48. )
  49. )
  50. ;
  51. (princ)
  52. )
  53. ;
  54. ;
  55. (defun _SZCx ( elev / current_layer ss1 s)
  56. ;To Be Called from Driver Function: (defun c:SZC100 () (_SZCx "100'") (princ) )
  57. (setq current_layer (getvar "clayer"))
  58. (princ (strcat "\nSetting Z to: " elev "(w/change to curr layer)") )
  59. (setvar "cmdecho" 0)
  60. (setq ss1 (ssget))
  61. (if ss1
  62. (progn
  63. (setq s elev)
  64. ; Set selected to new elevation
  65. (command ".change" ss1 "" "P" "E" s "")
  66. ;Change to current layer
  67. (command ".change" ss1 "" "P" "LA" current_layer "")
  68. (princ (strcat "\nEntities changed to elevation: " s "\nEntities changed to current layer: " current_layer))
  69. )
  70. )
  71. ;
  72. (princ)
  73. )
  74. ;
  75. ;
  76. (defun _SZx ( elev / current_layer ss1 s)
  77. ;To Be Called from Driver Function: (defun c:SZC100 () (_SZx "100'") (princ) )
  78. (princ (strcat "\nSetting Z to: " elev "(w/change to curr layer)") )
  79. (setvar "cmdecho" 0)
  80. (setq ss1 (ssget))
  81. (if ss1
  82. (progn
  83. (setq s elev)
  84. ; Set selected to new elevation
  85. (command ".change" ss1 "" "P" "E" s "")
  86. (princ (strcat "\nEntities changed to elevation: " s ))
  87. )
  88. )
  89. ;
  90. (princ)
  91. )
  92. ;
  93. ;
  94. ;
  95. ;Functions to set to specific elevations
  96. ;
  97. ;Set Z - no layer change
  98. (defun c:SZ100 () (_SZx "100'") (princ) )
  99. (defun c:SZ150 () (_SZx "150'") (princ) )
  100. (defun c:SZ200 () (_SZx "200'") (princ) )
  101. ;
  102. ;Set Z - Change modified to cuttent layer
  103. (defun c:SZC100 () (_SZCx "100'") (princ) )
  104. (defun c:SZC150 () (_SZCx "150'") (princ) )
  105. (defun c:SZC200 () (_SZCx "200'") (princ) )
  106. ;
  107. ;
  108. ; Command to reload this file
  109. (defun c:LSZ ( / s)
  110. (setvar "cmdecho" 0)
  111. (setq s "SetZ.lsp")
  112. (if (findfile s)
  113. (progn
  114.   (load s)
  115.   (princ (strcat "\n" s " reloaded...\n"))
  116. )
  117. (princ (strcat "\n" s " NOT reloaded...\n"))
  118. )
  119. ;
  120. (princ)
  121. )
  122. ;
  123. ;
  124. (princ)
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 08:27:58 | 显示全部楼层
注意s=nil,如果用户取消,或者在提示输入s时右键单击,则可以考虑使用错误处理程序来恢复CMDECHO。
 
回复

使用道具 举报

3

主题

11

帖子

8

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 08:33:27 | 显示全部楼层
谢谢,我知道我略过了错误检测,我会留意它是如何被使用的(分发将非常小)。汤姆
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 08:38:21 | 显示全部楼层
Re s=零
 
  1. (setq s (getstring "New Elevation? >"))
  2. (if (= s nil)(setq s 0.0)) ; if user presses the enter key
回复

使用道具 举报

44

主题

3166

帖子

2803

银币

中流砥柱

Rank: 25

铜币
557
发表于 2022-7-6 08:41:09 | 显示全部楼层
 
这里有一个有趣的小例子。。。无需操作CMDECHO系统变量,因为此代码使用Visual LISP的Move方法代替Move或Change命令。
 
  1. (vl-load-com)
  2. (defun c:SELEV () (c:SetElevation))
  3. (defun c:SetElevation (/ *error*)
  4. (princ "\rSETELEVATION ")
  5. (defun *error* (msg)
  6.    (if acDoc
  7.      (vla-endundomark acDoc)
  8.    )
  9.    (cond ((not msg))                                                   ; Normal exit
  10.          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
  11.          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
  12.    )
  13.    (princ)
  14. )
  15. ((lambda (acDoc / ss el startPoint endPoint)
  16.     (vla-startundomark acDoc)
  17.     (if
  18.       (and (setq ss (ssget "_:L"))
  19.            (setq el (getreal "\nAmount to add to all elevations: "))
  20.            (setq startPoint (vlax-3d-point '(0. 0. 0.)))
  21.            (setq endPoint (vlax-3d-point (list 0. 0. el)))
  22.       )
  23.        (progn
  24.          (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
  25.            (vla-move x startPoint endPoint)
  26.          )
  27.          (vla-delete ss)
  28.          (*error* nil)
  29.        )
  30.        (cond (ss (*error* "No amount specified"))
  31.              ((*error* "Nothing selected"))
  32.        )
  33.     )
  34.   )
  35.    (vla-get-activedocument (vlax-get-acad-object))
  36. )
  37. )
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 04:41 , Processed in 1.197427 second(s), 60 queries .

© 2020-2025 乐筑天下

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