乐筑天下

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

[编程交流] 关于线型/旋转的问题

[复制链接]

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 10:58:26 | 显示全部楼层
 
 
这似乎不是个坏主意,但在某些情况下,我可能希望在程序中的某个地方使用旧设置。我将程序设置为在需要时使用用户自己的对象捕捉。如果我把所有设置都放在一个变量下,那对我来说不够灵活。
 
见下文:
 
  1. ;//////////////////////////////////////////////////////////////////////////
  2. ; Start-Up Function
  3. (defun C:GL ()                                                             ;Define function
  4. (GL_MF)                                                                  ;Go to GL_MF ~ Main Function
  5. (princ)                                                                  ;Exit quietly
  6. )                                                                          ;End defun
  7. (princ "\nGL.lsp Loaded....")                                              ;print message to command line
  8. (princ "\nType GL to start program.")                                      ;print message to command line
  9. ;;;//////////////////////////////////////////////////////////////////////////
  10. ; Main Function
  11. (defun GL_MF (/ SUCE SUOM SUSM SUAB SUAD MIDPT PLEN  PT01 PT02)            ;Define function, Declare local variables
  12. (setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo
  13. (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode
  14. (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode
  15. (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base
  16. (setq SUAD (getvar "angdir"))                                            ;Save User Angle Direction
  17. (setq SUCL (getvar "clayer"))                                            ;Save User Current Layer
  18. (setq temperr *error*)                                                   ;Save Temporary Error
  19. [color=red](setq *error* GL_ET)                                                     ;Go to GL_ET ~ Error Trap Function[/color]
  20. (GL_LC "GAS LINE" "3" "GAS_LINE" "")                                     ;Go to GL_LC Layer Function, Layer Name, Color, Linetype & Lineweight
  21. (setvar "cmdecho" 0)                                                     ;Set Command Echo to 0
  22. (setvar "angbase" 0.0000)                                                ;Set Angle Base to 0
  23. (setvar "angdir"  0)                                                     ;Set Angle Direction to 0
  24. (setvar "orthomode" 1)                                                   ;Turn on Orthomode
  25. (setvar "osmode"    SUSM)                                                ;Turn on User Object Snaps
  26. (setq PT01 (getpoint "\nEnter the line start point:"))                   ;Get the first point of line
  27. (while                                                                   ;Evaluate expression till nill
  28.    (/= nil                                                                ;If not =
  29.      (setq PT02 (getpoint PT01 "\nEnter the line end point:"))            ;Set point 2
  30.    )                                                                      ;End if not
  31.    (setvar "osmode" 0)                                                    ;Turn off all Object Snaps
  32.    (progn                                                                 ;Then do the following
  33.      (command "._pline" PT01 PT02 "")                                     ;Pline command
  34.      (setq RADIANS (angle PT01 PT02))                                     ;Get line angle in radians
  35.      (setq DEGREES (GL_RTD RADIANS))                                      ;Convert radians to degrees
  36.      (setq PLEN (distance PT01 PT02))                                     ;Get the line distance
  37.      (setq MIDPT (polar PT01 (GL_DTR DEGREES)(/ PLEN 2.0)))               ;Set the midpoint of the line
  38.      (setq PT01 PT02)                                                     ;Set point 1 from point 2
  39.      (setvar "osmode" SUSM)                                               ;Turn on User Object Snaps
  40.      (if                                                                  ;If the following returns true
  41.        (and                                                               ;Return the logical AND of the supplied arguments
  42.          (>  DEGREES 90.0)                                                ;Degrees is greater than 90
  43.          (<= DEGREES 270.0)                                               ;And less than or equal to 270
  44.        )                                                                  ;End and
  45.        (command "._rotate" "_last" "" MIDPT "180.0")                      ;Rotate the line on it mid-point 180 degrees
  46.      )                                                                    ;End if
  47.    )                                                                      ;Otherwise...
  48. )                                                                        ;End while
  49. (setq *error* temperr)                                                   ;Restore error
  50. (setvar "cmdecho"   SUCE)                                                ;Restore Saved User Command Echo
  51. (setvar "orthomode" SUOM)                                                ;Restore Saved User Orthomode
  52. (setvar "osmode"    SUSM)                                                ;Restore Saved User Object Snapmode
  53. (setvar "angbase"   SUAB)                                                ;Restore Saved User Angle Base
  54. (setvar "angdir"    SUAD)                                                ;Restore Saved User Angle Direction
  55. (setvar "clayer"    SUCL)                                                ;Restore Saved User Current Layer
  56. (princ)                                                                  ;Exit quietly
  57. )                                                                          ;End defun
  58. ;//////////////////////////////////////////////////////////////////////////
  59. ; Degrees to Radians Function
  60. (defun GL_DTR (DEGREES)                                                    ;Define function, DEGREES is the argument
  61. (* pi (/ DEGREES 180.0))                                                  ;Calculate Degress to radians
  62. )                                                                          ;End defun
  63. ;//////////////////////////////////////////////////////////////////////////
  64. ; Radians to Degrees Function
  65. (defun GL_RTD (RADIANS)                                                    ;Define function, RADIANS is the argument
  66. (* 180.0 (/ RADIANS pi))                                                 ;Calculate Radians to degress
  67. )                                                                          ;End defun
  68. ;//////////////////////////////////////////////////////////////////////////
  69. ; Layer Create Function
  70. (defun GL_LC (NLAY LCLR LTYP LWGT / LAY FRZ)                               ;Define function, Declare local variables and arguments
  71. (setq CLAY (getvar "clayer"))                                            ;Get the current layer
  72. (setq LAY (tblsearch "layer" NLAY))                                      ;Search drawing to find layer, Note: (NOT USED)
  73. (if                                                                      ;If the following returns true
  74.    (not LAY)                                                              ;Layer not in drawing
  75.    (command "._layer" "_m" NLAY "_c" LCLR "" "_lt" LTYP "" "_lw" LWGT "") ;Layer command
  76.    (progn                                                                 ;Then do the following
  77.      (setq FRZ (cdr (assoc 70 LAY)))                                      ;Variable FRZ is frozen layer
  78.      (if                                                                  ;If the following returns true
  79.        (= FRZ 65)                                                         ;Layer frozen from last edit
  80.        (progn                                                             ;Then do the following
  81.          (command "._layer" "_t" NLAY "")                                 ;Thaw layer
  82.          (command "._layer" "_s" NLAY "")                                 ;Set layer
  83.        )                                                                  ;Otherwise...
  84.        (command "._layer" "_s" NLAY "")                                   ;Set layer
  85.      )                                                                    ;End if
  86.    )                                                                      ;Otherwise...
  87. )                                                                        ;End if
  88. (princ)                                                                  ;Exit quietly
  89. )                                                                          ;End defun
  90. ;//////////////////////////////////////////////////////////////////////////
  91. ; Error Trap Function
  92. (defun GL_ET (errmsg)                                                      ;Define function, errmsg is the argument
  93. (command nil nil nil)                                                    ;When escape selected
  94. (if                                                                      ;If the following returns true
  95.    (not                                                                   ;Verify that an item evaluates to nil
  96.      (member errmsg '("console break" "Function Cancelled"))              ;Search list for an occurence of an expression
  97.    )                                                                      ;End not
  98.    (princ (strcat "\nError:" errmsg))                                     ;Print message to command line
  99. )                                                                        ;End if
  100. (setvar "cmdecho"   SUCE)                                                ;Restore Saved User Command Echo
  101. (setvar "orthomode" SUOM)                                                ;Restore Saved User Orthomode
  102. (setvar "osmode"    SUSM)                                                ;Restore Saved User Object Snapmode
  103. (setvar "angbase"   SUAB)                                                ;Restore Saved User Angle Base
  104. (setvar "angdir"    SUAD)                                                ;Restore Saved User Angle Direction
  105. (setvar "clayer"    SUCL)                                                ;Restore Saved User Current Layer
  106. (princ "\nError, Restoring Variables.")                                  ;Print message to command line
  107. (terpri)                                                                 ;Terminate print
  108. (setq *error* temperr)                                                   ;Restore error
  109. (princ)                                                                  ;Exit quietly
  110. )                                                                          ;End defun
  111. ;//////////////////////////////////////////////////////////////////////////

 
然后重新打开捕捉:
 
  1. ; Layer Create Function
  2. (defun GL_LC (NLAY LCLR LTYP LWGT / LAY FRZ)                               ;Define function, Declare local variables and arguments
  3. (setq CLAY (getvar "clayer"))                                            ;Get the current layer
  4. (setq LAY (tblsearch "layer" NLAY))                                      ;Search drawing to find layer, Note: (NOT USED)
  5. (if                                                                      ;If the following returns true
  6.    (not LAY)                                                              ;Layer not in drawing
  7.    [color=red](command "._layer" "_m" NLAY "_c" LCLR "" "_lt" LTYP "" "_lw" LWGT "") ;Layer command[/color]
  8.    (progn                                                                 ;Then do the following
  9.      (setq FRZ (cdr (assoc 70 LAY)))                                      ;Variable FRZ is frozen layer
  10.      (if                                                                  ;If the following returns true
  11.        (= FRZ 65)                                                         ;Layer frozen from last edit
  12.        (progn                                                             ;Then do the following
  13.          (command "._layer" "_t" NLAY "")                                 ;Thaw layer
  14.          (command "._layer" "_s" NLAY "")                                 ;Set layer
  15.        )                                                                  ;Otherwise...
  16.        (command "._layer" "_s" NLAY "")                                   ;Set layer
  17.      )                                                                    ;End if
  18.    )                                                                      ;Otherwise...
  19. )                                                                        ;End if
  20. (princ)                                                                  ;Exit quietly
  21. )                                                                          ;End defun

 
或者,如果它在列表中靠后,只需使用nth
112452kqqhb1qihuahtz3h.jpg
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:01:16 | 显示全部楼层
 
 
我从没想过那么多,李很好。
我将在下一个代码中尽量记住这一点。
 
谢谢
秃鹰
回复

使用道具 举报

59

主题

327

帖子

268

银币

后起之秀

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

铜币
295
发表于 2022-7-6 11:03:07 | 显示全部楼层
不客气,设置多个系统变量时更方便。
 
例如,相当多的程序只会改变CMDECHO OSMODE和CLAYER。
 
所以代码可以是这样的:
 
  1. (setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo
  2. (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode
  3. (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode
  4. (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base
  5. (setq SUAD (getvar "angdir"))
然后在关闭CMDECHO时,OSMODE:
 
在错误处理程序中:
 
希望这有帮助,
 
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:08:45 | 显示全部楼层
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:09:46 | 显示全部楼层
Marcow,
 
I had to correct the line indicated in RED for the error trap. See below. I must have been in a hurry.
 
Sorry about that.
The Buzzard

[code];//////////////////////////////////////////////////////////////////////////; Start-Up Function(defun C:GL ()                                                             ;Define function (GL_MF)                                                                  ;Go to GL_MF ~ Main Function (princ)                                                                  ;Exit quietly)                                                                          ;End defun(princ "\nGL.lsp Loaded....")                                              ;print message to command line(princ "\nType GL to start program.")                                      ;print message to command line;;;//////////////////////////////////////////////////////////////////////////; Main Function(defun GL_MF (/ SUCE SUOM SUSM SUAB SUAD MIDPT PLEN  PT01 PT02)            ;Define function, Declare local variables (setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base (setq SUAD (getvar "angdir"))                                            ;Save User Angle Direction (setq SUCL (getvar "clayer"))                                            ;Save User Current Layer (setq temperr *error*)                                                   ;Save Temporary Error (setq *error* GL_ET)                                                     ;Go to GL_ET ~ Error Trap Function (GL_LC "GAS LINE" "3" "GAS_LINE" "")                                     ;Go to GL_LC Layer Function, Layer Name, Color, Linetype & Lineweight (setvar "cmdecho" 0)                                                     ;Set Command Echo to 0 (setvar "angbase" 0.0000)                                                ;Set Angle Base to 0 (setvar "angdir"  0)                                                     ;Set Angle Direction to 0 (setvar "orthomode" 1)                                                   ;Turn on Orthomode (setvar "osmode"    SUSM)                                                ;Turn on User Object Snaps (setq PT01 (getpoint "\nEnter the line start point:"))                   ;Get the first point of line (while                                                                   ;Evaluate expression till nill   (/= nil                                                                ;If not =     (setq PT02 (getpoint PT01 "\nEnter the line end point:"))            ;Set point 2   )                                                                      ;End if not   (setvar "osmode" 0)                                                    ;Turn off all Object Snaps   (progn                                                                 ;Then do the following     (command "._pline" PT01 PT02 "")                                     ;Pline command     (setq RADIANS (angle PT01 PT02))                                     ;Get line angle in radians     (setq DEGREES (GL_RTD RADIANS))                                      ;Convert radians to degrees     (setq PLEN (distance PT01 PT02))                                     ;Get the line distance     (setq MIDPT (polar PT01 (GL_DTR DEGREES)(/ PLEN 2.0)))               ;Set the midpoint of the line     (setq PT01 PT02)                                                     ;Set point 1 from point 2     (setvar "osmode" SUSM)                                               ;Turn on User Object Snaps     (if                                                                  ;If the following returns true       (and                                                               ;Return the logical AND of the supplied arguments          (>  DEGREES 90.0)                                                ;Degrees is greater than 90         (
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:15:03 | 显示全部楼层
Buzzard,
 
I notice that you use a lot of variables to store and reset your sys Vars:
 
  1. (setq SUCE (getvar "cmdecho"))                                           ;Save User Command Echo (setq SUOM (getvar "orthomode"))                                         ;Save User Orthomode (setq SUSM (getvar "osmode"))                                            ;Save User Object Snapmode (setq SUAB (getvar "angbase"))                                           ;Save User Angle Base (setq SUAD (getvar "angdir"))
 
Why not just store them all at once:
 
  1. (setq OldVars (mapcar 'getvar '("CMDECHO" "ORTHOMODE" "OSMODE" "ANGBASE" "ANGDIR")))
 
Lee
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:17:02 | 显示全部楼层
 
 
That does not seem like a bad idea, But in some instance I may want to use the old settings somewhere within the program. I set the program up to use the Users own object snaps when called for. Thats not flexible enough for me if I place all settings under one variable.
 
See below:
 

[code]  (while                                                                   ;Evaluate expression till nill   (/= nil                                                                ;If not =     (setq PT02 (getpoint PT01 "\nEnter the line end point:"))            ;Set point 2   )                                                                      ;End if not   (setvar "osmode" 0)                                                    ;Turn off all Object Snaps   (progn                                                                 ;Then do the following     (command "_.pline" PT01 PT02 "")                                     ;Pline command     (setq RADIANS (angle PT01 PT02))                                     ;Get line angle in radians     (setq DEGREES (GL_RTD RADIANS))                                      ;Convert radians to degrees     (setq PLEN (distance PT01 PT02))                                     ;Get the line distance     (setq MIDPT (polar PT01 (GL_DTR DEGREES)(/ PLEN 2.0)))               ;Set the midpoint of the line     (setq PT01 PT02)                                                     ;Set point 1 from point 2     (setvar "osmode" SUSM)                                               ;Turn on User Object Snaps     (if                                                                  ;If the following returns true       (and                                                               ;Return the logical AND of the supplied arguments          (>  DEGREES 90.0)                                                ;Degrees is greater than 90         (
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:21:38 | 显示全部楼层
No, its not too much more - you just need to plan things a little
 
For example, structure the list like something like this:
 
  1. (setq OldVars (mapcar 'getvar '("OSMODE" "CMDECHO"...
 
Then to switch snaps back on:
 
  1. (setvar "OSMODE" (car OldVars))
 
Or, if it is further down in the list, just use nth
回复

使用道具 举报

32

主题

1166

帖子

1146

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
159
发表于 2022-7-6 11:22:33 | 显示全部楼层
 
 
I never gave that much thought, Very nice Lee.
I will try to keep that in mind on my next code.
 
Thanks,
The Buzzard
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 11:26:41 | 显示全部楼层
You're welcome, its much more convenient when setting multiple Sys vars.
 
For instance, quite a few programs will only alter CMDECHO OSMODE and CLAYER, for example.
 
So the code can be something like:
 
  1. (setq VarList '("CLAYER" "CMDECHO" "OSMODE"))(setq OldVars (mapar 'getvar VarList))
Then when switching off CMDECHO, OSMODE:
 
  1. (mapcar 'setvar (cdr VarList) '(0 0))
And in the Error Handler:
 
  1. (defun *error* (msg) (if OldVars (mapcar 'setvar VarList OldVars)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")     (princ (strcat "\n** Error: " msg " **"))) (princ))
Hope this helps,
 
Lee
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 21:31 , Processed in 0.339387 second(s), 73 queries .

© 2020-2025 乐筑天下

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