乐筑天下

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

[编程交流] 对UCS坐标使用Trans

[复制链接]

1

主题

1

帖子

0

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 09:39:18 | 显示全部楼层 |阅读模式
好啊所以我使用了一个以前设置的lisp例程。它不会显示任何当前UCS坐标。我想我已经解决了。但现在,我和领导们产生了一个问题。特别是应该在N下方但在东距上方的线。在WCS中效果很好,但在UCS中效果很好。通常是基于我离世界本源有多远。帮助下面是代码。(遗憾的是,我不知道问题出在哪里)
 
  1. Main Function---------------------------------------------------------------------------
  2. ;;;Function draws a leader with no text.
  3. (defun bmcdNE (wLeader wElev wa / ap np ep N E)
  4. (BMCDTextStyles) ;load standard text styles
  5. (BMCDDimStyles) ;load standard dim styles
  6. ;save variables
  7. (NEsave-vars)
  8. ; setup error handler here
  9. (setvar "cmdecho" 0)
  10. (setq *error* leader-error)
  11. ;check and set dscale
  12. (if (= dscale nil)
  13. (setq dscale (getvar "dimscale"))
  14. );end if
  15. (QlSave);saves current settings
  16. ;Now we need to set the current settings for the needed leader
  17. (setq NoText '(4 ;1. AnnoType 60 0Mtext<def> 1Copy 2Tolerance 3BlockReference 4None
  18. 0 ;2. ReuseAnno 61 0None<def> 1Next 2Current
  19. 1 ;3. LeftAttach 62 0TopOfTop 1MiddleOfTop<def> 2Middle 3MiddleOfBottom 4BottomOfBottom
  20. 3 ;4. RightAttach 63 0TopOfTop 1MiddleOfTop 2Middle 3MiddleOfBottom<def> 4BottomOfBottom
  21. 0 ;5. Underline 64 1On 0Off<def>
  22. 0 ;6. Splined 65 1On 0Off<def>
  23. 1 ;7. NoPointLimit 66 1On 0Off<def>
  24. 2 ;8. NumPoints 67 Integer (Must be greater than 2) 3<def>
  25. 0 ;9. Wordwrap 68 1On<def> 0Off
  26. 1 ;10. AlwaysLeftJust 69 1On 0Off<def>
  27. 0 ;11. Angle1 70 0Any<def> 1Horizontal 2?d 3Ed 40d 5 d
  28. 0 ;12. Angle2 71 0Any<def> 1Horizontal 2?d 3Ed 40d 5 d
  29. 0 ;13. Box 72 1On 0Off<def>
  30. 0.0 ;14. Textwidth 40 Real (Must be > 0.0) 0.0<def>
  31. "." ;15. Arrowname 3 String (or User defined arrow as block name) See definitions below
  32. ));end setq
  33. (command "osnap" "end,mid,intersection,center")
  34. (SetQleader NoText)
  35. (setvar "dimlwd" -1)
  36. (setvar "texteval" 1)
  37. (setvar "orthomode" 0)
  38. (setq style (cdr(assoc 40 (tblsearch "style" (getvar "textstyle"))))) ;gets the text height from style.
  39. (setq comp (cdr(assoc 41 (tblsearch "style" (getvar "textstyle"))))) ;stores the compression factor.
  40. (if (= 0 style) (setq ts (getvar "textsize"))) ;sets the text size to the active textsize.
  41. (if (/= 0 style) (setq ts style)) ;sets the text size to the style size.
  42. (command "layer" "set" "G-ANNO-TEXT" "")
  43. (setq pt1 (getpoint "\nEnter starting point:")) ;Gets the first point for the
  44. ;coordinate and line.
  45. (setvar "osmode" 0)
  46. (setvar "luprec" 2)
  47. (setq save-pt1 pt1)
  48. ;;; ;do we need to covert the point from pspace to mspace?
  49. (if (= (getvar "tilemode") 0)
  50. (setq cs_from 0) ;WCS
  51. (setq cs_to 1) ;UCS
  52. (setq pt1 (trans pt cs_from cs_to 0) ; disp = 0 indicateds that pt is a point
  53. )
  54. (setq x1 (car pt1)) ;Stores the x coord of the first point.
  55. (setq y1 (cadr pt1)) ;Stores the y coord of the first point.
  56. (setq z1 (caddr pt1)) ;stores the z coord of the first point. JAH
  57. (setq xabs (abs x1)) ;Gets the absolute value of the x point.
  58. (setq yabs (abs y1)) ;Gets the absolute value of the y point.
  59. (setq zabs (abs z1)) ;Gets the absolute value of the z point. AMS
  60. (setq x (rtos xabs (getvar "lunits") (+(getvar "luprec")0))) ;Converts the x coord from real to string.
  61. (setq y (rtos yabs (getvar "lunits") (+(getvar "luprec")0))) ;Converts the y coord form real to string.
  62. (setq z (rtos zabs (getvar "lunits") (+(getvar "luprec")0))) ;Converts the z coord form real to string. JAH
  63. ;if the number of decimal places is less than the precission add zeros
  64. (while (< (strlen (substr x (+(vl-string-search "." x) 2))) (getvar "luprec"))
  65. (setq x (strcat x "0"))
  66. )
  67. ;if the number of decimal places is less than the precission add zeros
  68. (while (< (strlen (substr y (+(vl-string-search "." y) 2))) (getvar "luprec"))
  69. (setq y (strcat y "0"))
  70. )
  71. ;if the number of decimal places is less than the precission add zeros
  72. (while (< (strlen (substr z (+(vl-string-search "." z) 2))) (getvar "luprec"))
  73. (setq z (strcat z "0"))
  74. )
  75. (setq IN x) ;Sets variable for subroutine.
  76. (COMMA) ;CALLS SUBROUTINE.
  77. (setq x OUT) ;Saves variable from subroutine.
  78. (setq IN y) ;Sets variable for subroutine.
  79. (COMMA) ;CALLS SUBROUTINE.
  80. (setq y OUT) ;Saves variable from subroutine.
  81. (setq IN z) ;Sets variable for subroutine.
  82. (COMMA) ;CALLS SUBROUTINE.
  83. (setq z OUT) ;Saves variable from subroutine.
  84. (setq pt1 save-pt1 )
  85. (if (> X1 0)
  86. (setq E (strcat "E " x )) ;Checks to see if X coordinate
  87. )
  88. (if(< X1 0)
  89. (setq E (strcat "W " x )) ;is positive or negitive
  90. )
  91. (if(= X1 0)
  92. (setq E (strcat "BASELINE " x )) ;and sets the proper label.
  93. )
  94. (if(> Y1 0)
  95. (setq N (strcat "N " y )) ;Checks to see if Y coordinate
  96. )
  97. (if(< Y1 0)
  98. (setq N (strcat "S " y )) ;is positive or negitive
  99. )
  100. (if(= Y1 0)
  101. (setq N (strcat "BASELINE " y )) ;and sets the proper label.
  102. )
  103. (setq ABC "ABC ")
  104. ;;;build the elevation label
  105. (setq Zelev (strcat "EL " z))
  106. (setq nl (strlen N)) ;Gets the string length of the N variable.
  107. (setq el (strlen E)) ;Gets the string length of the E variable.
  108. (cond
  109. ((> nl el) (setq ll nl)) ;Tests to see if the N var is longer than
  110. ;the E var.
  111. ((> el nl) (setq ll el)) ;Tests to see if the E var is longer than
  112. ;the N var.
  113. ((= nl el) (setq ll nl)) ;Tests to see if the N and E var are equil.
  114. ) ;end cond
  115. (setq pt2 (getpoint pt1 "\nEnter second point:")) ;The pt1 is used to create
  116. ;a rubberband line.
  117. (grdraw pt1 pt2 -1) ;Draws a tempory line to let you see
  118. ;where you are and what is going on.
  119. (setq x2 (car pt2)) ;Stores the Second X point
  120. (setq y2 (cadr pt2)) ;Stores the Second Y point
  121. (setq pt3 (getpoint pt2 "Enter side to offset:")) ;The pt2 is used to create
  122. ;a rubberband line.
  123. (setq x3 (car pt3)) ;Stores the Third X point
  124. (setq y3 (cadr pt3)) ;Stores the Third Y point
  125. (cond
  126. ((> x2 x3) (setq lx (- x2 (* 0.8 ts ll comp)))) ;Checks to see wich way
  127. ((> x3 x2) (setq lx (+ x2 (* 0.8 ts ll comp)))) ;you are drawing the line
  128. ) ;and sets the end of line
  129. ;to match the text length.
  130. (cond
  131. ((> x2 x3) (setq tx lx)) ;Based on the direction of the line
  132. ((> x3 x2) (setq tx (+ x2 ts))) ;the text X point is calculated.
  133. )
  134. (setq ta (+ y2 (* ts 3)))
  135. (setq ap (list tx ta))
  136. (setq tn (+ y2 ts)) ;Calculates the Y point for North or South text.
  137. (setq np (list tx tn)) ;Creates the point to place the text.
  138. (setq te (- y2 ts )) ;Calculates the Y point for East or West test.
  139. (setq ep (list tx te)) ;Creates the point to place the text.
  140. (setq tElev (- y2 (* ts 3))) ;Calculates the Y point for Elevation text.
  141. (setq elevP (list tx tElev)) ;Creates the point to place the text.
  142. (setq ly y2) ;Sets the last Y point EQ. to the second Y point.
  143. (setq pt4 (list lx ly)) ;Creates the point for the end of the line.
  144. (command "pline" pt2 pt4 "") ;Places the line.
  145. (setq theline (vlax-ename->vla-object (entlast))) ;get the line object
  146. (if (= style 0) (command "text" "J" "ML" np ts "0" N)) ;Places the top text.
  147. (if (/= style 0) (command "text" "J" "ML" np "0" N)) ;Places the top text.
  148. (setq toptext (vlax-ename->vla-object (entlast))) ;get the text object
  149. (if (= style 0) (command "text" "J" "ML" ep ts "0" E)) ;Places the bottom text.
  150. (if (/= style 0) (command "text" "J" "ML" ep "0" E)) ;Places the bottom text.
  151. (setq bottomtext (vlax-ename->vla-object (entlast))) ;get the text object
  152. (if wa
  153. (progn
  154. (if (= style 0) (command "text" "J" "ML" ap ts "0" ABC))
  155. (if (/= style 0) (command "text" "J" "ML" ap "0" ABC))
  156. (setq atext (vlax-ename->vla-object (entlast)))
  157. )
  158. )
  159. ;;;Create the text for the elevation text
  160. (if wElev
  161. (progn
  162. (if (= style 0) (command "text" "J" "ML" elevP ts "0" Zelev)) ;Places the bottom text.
  163. (if (/= style 0) (command "text" "J" "ML" elevP "0" Zelev)) ;Places the bottom text.
  164. (setq Elevtext (vlax-ename->vla-object (entlast))) ;get the text object
  165. );end progn
  166. );end if
  167. ;rotate the text and line to make it horizontal
  168. (setq viewrotation (getvar "viewtwist")) ;ucs twist
  169. (setq retval (vla-rotate theline (vlax-3d-point pt2) (* viewrotation -1)))
  170. (setq retval (vla-rotate toptext (vlax-3d-point pt2) (* viewrotation -1)))
  171. (setq retval (vla-rotate bottomtext (vlax-3d-point pt2) (* viewrotation -1)))
  172. (if wa
  173. (setq retval (vla-rotate atext (vlax-3d-point pt2) (* viewrotation -1)))
  174. )
  175. (if wElev
  176. (setq retval (vla-rotate Elevtext (vlax-3d-point pt2) (* viewrotation -1)))
  177. );end if
  178. ;;;get the end point of the now rotated line this will also be the endpoint for the qleader
  179. (setq theLineCoords (vlax-variant-value (vla-get-Coordinates theline)))
  180. (setq newXPt (vlax-safearray-get-element theLineCoords 0))
  181. (setq newYPt (vlax-safearray-get-element theLineCoords 0))
  182. (setq newEndPt (list newXPt newYPt))
  183. ;in order to avoid the the mtext dialog we set the default qleader settings above
  184. (setq ss (ssget "_X" (list (cons 0 "*MTEXT,TEXT")(cons 1 "Ex. TP*"))))
  185. (if wLeader
  186. (progn
  187. (vl-cmdf "qleader" pt1 pt2 newEndPt "")
  188. (vla-delete theline) ;delete our temp line
  189. );end progn
  190. );end if
  191. (Merge)
  192. (QlRestore)
  193. (setvar "cmdecho" 1) ;Turns on the command echo.
  194. (redraw)
  195. (NErestore-vars)
  196. (princ)
  197. );end defun
  198. (defun c:LNE ()
  199. (bmcdNE T nil nil)
  200. (princ)
  201. );end defun
  202. (defun c:LNEL ()
  203. (bmcdNE T nil T)
  204. (princ)
  205. );end defun
  206. (defun c:LNEEL ()
  207. (bmcdNE T T T)
  208. (princ)
  209. );end defun
  210. (defun c:LNEE ()
  211. (bmcdNE T T nil)
  212. (princ)
  213. );end defun
  214. (defun c:NEE ()
  215. (bmcdNE nil T nil)
  216. (princ)
  217. );end defun
  218. (defun c:NEEL ()
  219. (bmcdNE nil T T)
  220. (princ)
  221. );end defun
  222. (defun c:NEL ()
  223. (bmcdNE nil nil T)
  224. (princ)
  225. );end defun
  226. (defun c:NE ()
  227. (bmcdNE nil nil nil)
  228. (princ)
  229. );end defun

 
我使用“lneel”作为命令。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-7 00:28 , Processed in 0.481625 second(s), 54 queries .

© 2020-2025 乐筑天下

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